Skip to content

Commit

Permalink
fix(testing): make local registry to match any port
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Dec 13, 2024
1 parent 5bdda1d commit 0972b4d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
21 changes: 11 additions & 10 deletions e2e/release/src/circular-dependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ expect.addSnapshotSerializer({
// Normalize package manager specific logs
.replaceAll(/p?npm workspaces/g, '{PACKAGE_MANAGER_WORKSPACES}')
// We trim each line to reduce the chances of snapshot flakiness
.replaceAll(/http:\/\/localhost:\d+/g, '{registry}')
.split('\n')
.map((r) => r.trim())
.join('\n')
Expand Down Expand Up @@ -244,7 +245,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to {registry} with tag "latest", but [dry-run] was set
> nx run {project-name}:nx-release-publish
Expand All @@ -266,7 +267,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to {registry} with tag "latest", but [dry-run] was set
Expand Down Expand Up @@ -429,7 +430,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to {registry} with tag "latest", but [dry-run] was set
> nx run {project-name}:nx-release-publish
Expand All @@ -451,7 +452,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to {registry} with tag "latest", but [dry-run] was set
Expand Down Expand Up @@ -613,7 +614,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to {registry} with tag "latest", but [dry-run] was set
> nx run {project-name}:nx-release-publish
Expand All @@ -635,7 +636,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to {registry} with tag "latest", but [dry-run] was set
Expand Down Expand Up @@ -772,7 +773,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to {registry} with tag "latest", but [dry-run] was set
Expand Down Expand Up @@ -934,7 +935,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to {registry} with tag "latest", but [dry-run] was set
> nx run {project-name}:nx-release-publish
Expand All @@ -956,7 +957,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to {registry} with tag "latest", but [dry-run] was set
Expand Down Expand Up @@ -1121,7 +1122,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to {registry} with tag "latest", but [dry-run] was set
Expand Down
5 changes: 5 additions & 0 deletions e2e/utils/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { existsSync, removeSync } from 'fs-extra';
import * as isCI from 'is-ci';
import { exec } from 'node:child_process';
import { join } from 'node:path';
import * as detectPort from 'detect-port';
import { registerTsConfigPaths } from '../../packages/nx/src/plugins/js/utils/register';
import { runLocalRelease } from '../../scripts/local-registry/populate-storage';

Expand All @@ -19,6 +20,8 @@ export default async function (globalConfig: Config.ConfigGlobals) {
const requiresLocalRelease =
!process.env.NX_TASK_TARGET_TARGET?.startsWith('e2e-ci');

console.log('detectPort', await detectPort(4873));

global.e2eTeardown = await startLocalRegistry({
localRegistryTarget: '@nx/nx-source:local-registry',
verbose: isVerbose,
Expand Down Expand Up @@ -52,7 +55,9 @@ export default async function (globalConfig: Config.ConfigGlobals) {
} catch (err) {
// Clean up registry if possible after setup related errors
if (typeof global.e2eTeardown === 'function') {
console.log('detectPort', await detectPort(4873));
global.e2eTeardown();
console.log('detectPort', await detectPort(4873));
console.log('Killed local registry process due to an error during setup');
}
throw err;
Expand Down
4 changes: 3 additions & 1 deletion packages/js/src/plugins/jest/start-local-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function startLocalRegistry({
clearStorage?: boolean;
listenAddress?: string;
}) {
listenAddress ??= 'localhost';
if (!localRegistryTarget) {
throw new Error(`localRegistryTarget is required`);
}
Expand All @@ -33,10 +32,13 @@ export function startLocalRegistry({
clearStorage ?? true
}`.split(' '),
...(storage ? [`--storage`, storage] : []),
...(verbose ? ['--verbose'] : []),
...(listenAddress ? ['--listenAddress', listenAddress] : []),
],
{ stdio: 'pipe' }
);

listenAddress ??= 'localhost';
const listener = (data) => {
if (verbose) {
process.stdout.write(data);
Expand Down

0 comments on commit 0972b4d

Please sign in to comment.