Skip to content

Commit

Permalink
chore(testing): change e2e setup to use @nx/js (nrwl#17679)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi authored Jun 21, 2023
1 parent 19ec1de commit c3e08b3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 82 deletions.
5 changes: 4 additions & 1 deletion .verdaccio/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ packages:
logs:
type: stdout
format: pretty
level: http
level: warn

publish:
allow_offline: true # set offline to true to allow publish offline
1 change: 0 additions & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ pnpm-lock.yaml @nrwl/nx-pipelines-reviewers
# Scripts
/scripts/depcheck @FrozenPandaz @vsavkin @jaysoo
/scripts/documentation @nrwl/nx-docs-reviewers
/scripts/local-registry @FrozenPandaz @vsavkin
/scripts/angular-support-upgrades @nrwl/nx-angular-reviewers

# CI
Expand Down
56 changes: 12 additions & 44 deletions e2e/utils/global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,33 @@
import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry';
import { join } from 'path';
import { ChildProcess, exec, fork } from 'child_process';
import { exec } from 'child_process';
import { tmpdir } from 'tmp';
import { existsSync } from 'fs-extra';
import { Config } from '@jest/types';

export default async function (globalConfig: Config.ConfigGlobals) {
const isVerbose =
process.env.NX_VERBOSE_LOGGING === 'true' || globalConfig.verbose;
const isVerbose: boolean =
process.env.NX_VERBOSE_LOGGING === 'true' || !!globalConfig.verbose;
const storageLocation = join(
tmpdir,
'local-registry/storage',
process.env.NX_TASK_TARGET_PROJECT ?? ''
);
global.nxLocalRegistryProcess = await new Promise<ChildProcess>(
(resolve, reject) => {
const childProcess = fork(
require.resolve(`nx`),
`local-registry @nx/nx-source --config scripts/local-registry/config.yml --location none --storage ${storageLocation} --clear ${
process.env.NX_E2E_SKIP_BUILD_CLEANUP !== 'true'
}`.split(' '),
{ stdio: 'pipe' }
);

const listener = (data) => {
if (data.toString().includes('http://localhost:')) {
const port = parseInt(
data.toString().match(/localhost:(?<port>\d+)/)?.groups?.port
);
console.log('Local registry started on port ' + port);

const registry = `http://localhost:${port}`;
process.env.npm_config_registry = registry;
process.env.YARN_REGISTRY = registry;
console.log('Set npm and yarn config registry to ' + registry);

resolve(childProcess);
childProcess.stdout?.off('data', listener);
}
};
childProcess?.stdout?.on('data', listener);
childProcess?.stderr?.on('data', (data) => {
process.stderr.write(data);
});
childProcess.on('error', (err) => {
console.log('local registry error', err);
reject(err);
});
childProcess.on('exit', (code) => {
console.log('local registry exit', code);
reject(code);
});
}
);
global.e2eTeardown = await startLocalRegistry({
localRegistryTarget: '@nx/nx-source:local-registry',
verbose: isVerbose,
storage: storageLocation,
});

if (
process.env.NX_E2E_SKIP_BUILD_CLEANUP !== 'true' ||
!existsSync('./build')
) {
console.log('Publishing packages to local registry');
await new Promise<void>((res, rej) => {
const publishProcess = exec('pnpm nx-release --local major');
const publishProcess = exec('pnpm nx-release --local major', {
env: process.env,
});
let logs = Buffer.from('');
if (isVerbose) {
publishProcess?.stdout?.pipe(process.stdout);
Expand Down
4 changes: 2 additions & 2 deletions e2e/utils/global-teardown.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function () {
if (global.nxLocalRegistryProcess) {
global.nxLocalRegistryProcess.kill();
if (global.e2eTeardown) {
global.e2eTeardown();
console.log('Killed local registry process');
}
}
34 changes: 0 additions & 34 deletions scripts/local-registry/config.yml

This file was deleted.

0 comments on commit c3e08b3

Please sign in to comment.