-
Notifications
You must be signed in to change notification settings - Fork 14
/
global-setup.e2e.ts
71 lines (63 loc) · 2.15 KB
/
global-setup.e2e.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { rm, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { setup as globalSetup } from './global-setup';
import { setupTestFolder, teardownTestFolder } from './testing/test-setup/src';
import {
nxRunManyNpmInstall,
nxRunManyNpmUninstall,
} from './tools/src/npm/utils';
import { findLatestVersion, nxRunManyPublish } from './tools/src/publish/utils';
import { START_VERDACCIO_SERVER_TARGET_NAME } from './tools/src/verdaccio/constants';
import startLocalRegistry, {
RegistryResult,
} from './tools/src/verdaccio/start-local-registry';
import stopLocalRegistry from './tools/src/verdaccio/stop-local-registry';
import { uniquePort } from './tools/src/verdaccio/utils';
const e2eDir = join('tmp', 'e2e', 'react-todos-app');
const uniqueDir = join(e2eDir, `registry-${uniquePort()}`);
let activeRegistry: RegistryResult;
export async function setup() {
await globalSetup();
await setupTestFolder(e2eDir);
try {
activeRegistry = await startLocalRegistry({
localRegistryTarget: `@code-pushup/cli-source:${START_VERDACCIO_SERVER_TARGET_NAME}`,
storage: join(uniqueDir, 'storage'),
port: uniquePort(),
});
} catch (error) {
console.error('Error starting local verdaccio registry:\n' + error.message);
throw error;
}
// package publish
const { registry } = activeRegistry.registryData;
await writeFile('.npmrc', `@code-pushup:registry=${registry}`);
try {
console.info('Publish packages');
nxRunManyPublish({
registry,
nextVersion: findLatestVersion(),
parallel: 1,
});
} catch (error) {
console.error('Error publishing packages:\n' + error.message);
throw error;
}
// package install
try {
console.info('Installing packages');
nxRunManyNpmInstall({ registry, parallel: 1 });
} catch (error) {
console.error('Error installing packages:\n' + error.message);
throw error;
}
}
export async function teardown() {
if (activeRegistry && 'registryData' in activeRegistry) {
const { stop } = activeRegistry;
stopLocalRegistry(stop);
nxRunManyNpmUninstall({ parallel: 1 });
}
await rm('.npmrc');
await teardownTestFolder(e2eDir);
}