Skip to content

Commit

Permalink
fix(testing): fix windows e2e storage ENOENT
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Jun 9, 2023
1 parent 20359e7 commit 5f2ab7e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ jobs:
executor: macos
environment:
NX_E2E_CI_CACHE_KEY: e2e-circleci-macos
NX_VERBOSE_LOGGING: 'false'
NX_DAEMON: 'true'
NX_PERF_LOGGING: 'false'
SELECTED_PM: 'npm' # explicitly define npm for macOS tests
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ 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
30 changes: 21 additions & 9 deletions e2e/utils/global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import { join } from 'path';
import { ChildProcess, execSync, spawn } from 'child_process';
import { tmpdir } from 'tmp';
import { existsSync } from 'fs-extra';
import { Config } from '@jest/types';

export default async function () {
export default async function (globalConfig: Config.ConfigGlobals) {
const isVerbose =
process.env.NX_VERBOSE_LOGGING === 'true' || globalConfig.verbose;
const storageLocation = join(
process.cwd(),
'tmp/local-registry/storage',
tmpdir,
'local-registry/storage',
process.env.NX_TASK_TARGET_PROJECT ?? ''
);
global.nxLocalRegistryProcess = await new Promise<ChildProcess>(
(resolve, reject) => {
const childProcess = spawn(
`nx`,
`local-registry @nx/nx-source --location none --storage ${storageLocation} --clear ${
`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(' ')
}`.split(' '),
{ shell: process.platform === 'win32' }
);

childProcess.stdout.on('data', (data) => {
childProcess?.stdout?.on('data', (data) => {
if (isVerbose) {
process.stdout.write(data);
}
if (data.toString().includes('http://localhost:')) {
const port = parseInt(
data.toString().match(/localhost:(?<port>\d+)/)?.groups?.port
Expand All @@ -31,7 +40,7 @@ export default async function () {
resolve(childProcess);
}
});
childProcess.stderr.on('data', (data) => {
childProcess?.stderr?.on('data', (data) => {
process.stderr.write(data);
reject(data);
});
Expand All @@ -46,10 +55,13 @@ export default async function () {
}
);

if (process.env.NX_E2E_SKIP_BUILD_CLEANUP !== 'true') {
if (
process.env.NX_E2E_SKIP_BUILD_CLEANUP !== 'true' ||
!existsSync('./build')
) {
console.log('Publishing packages to local registry');
execSync('pnpm nx-release --local major', {
stdio: process.env.CI === 'true' ? 'ignore' : 'inherit',
stdio: isVerbose ? 'inherit' : 'ignore',
});
}
}
2 changes: 1 addition & 1 deletion packages/js/src/executors/verdaccio/verdaccio.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function verdaccioExecutor(

try {
const port = await detectPort(options.port);
if (port === options.port) {
if (port !== options.port) {
logger.info(`Port ${options.port} was occupied. Using port ${port}.`);
options.port = port;
}
Expand Down
31 changes: 31 additions & 0 deletions scripts/local-registry/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# path to a directory with all packages
storage: ../../tmp/local-registry/storage

listen: localhost:4872

# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/
max_fails: 100
maxage: 30m
fail_timeout: 10m
timeout: 600s
cache: false

packages:
'@nrwl/*':
access: $all
publish: $all

'**':
access: $all
publish: $all
unpublish: $all
proxy: npmjs

# log settings
logs:
type: stdout
format: pretty
level: warn

0 comments on commit 5f2ab7e

Please sign in to comment.