diff --git a/packages/next-pwa/__tests__/package.json b/packages/next-pwa/__tests__/package.json index 36a2b2f6..e90de913 100644 --- a/packages/next-pwa/__tests__/package.json +++ b/packages/next-pwa/__tests__/package.json @@ -2,6 +2,7 @@ "name": "next-pwa-tests", "version": "1.0.0", "private": true, + "type": "module", "devDependencies": { "@types/jest": "29.5.5", "@types/react": "18.2.22", diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index 7f441b70..e419b3ba 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -2,6 +2,7 @@ "name": "tests-utils", "version": "1.0.0", "private": true, + "type": "module", "exports": { ".": "./src/index.ts", "./dist/*": "./src/*" diff --git a/packages/test-utils/src/next-instance-dev.ts b/packages/test-utils/src/next-instance-dev.ts index 6b5e1d1f..a8e09c8e 100644 --- a/packages/test-utils/src/next-instance-dev.ts +++ b/packages/test-utils/src/next-instance-dev.ts @@ -2,6 +2,7 @@ import type { SpawnOptionsWithoutStdio } from "node:child_process"; import { spawn } from "node:child_process"; import { NextInstance } from "./next-instance-base"; +import { getURLFromLog } from "./utils"; export class NextInstanceDev extends NextInstance { public async setup(sourceDir: string) { @@ -26,14 +27,12 @@ export class NextInstanceDev extends NextInstance { this._process.stdout.on("data", (chunk: Buffer) => { const msg = chunk.toString(); this._cliOutput += msg; - if (msg.includes("- Local:")) { - this._url = - msg - .split(/\s*- Local:/) - .pop() - ?.trim() ?? ""; + const potentialUrl = getURLFromLog(msg); + if (potentialUrl !== undefined) { + this._url = potentialUrl; resolve(); } + console.log(msg); }); this._process.stderr.on("data", (chunk: Buffer) => { const msg = chunk.toString(); diff --git a/packages/test-utils/src/next-instance-start.ts b/packages/test-utils/src/next-instance-start.ts index 66312a2b..4cf71ce4 100644 --- a/packages/test-utils/src/next-instance-start.ts +++ b/packages/test-utils/src/next-instance-start.ts @@ -2,6 +2,7 @@ import type { SpawnOptionsWithoutStdio } from "node:child_process"; import { spawn } from "node:child_process"; import { NextInstance } from "./next-instance-base"; +import { getURLFromLog } from "./utils"; export class NextInstanceStart extends NextInstance { public async setup(sourceDir: string) { @@ -64,12 +65,9 @@ export class NextInstanceStart extends NextInstance { this._process.stdout.on("data", (chunk: Buffer) => { const msg = chunk.toString(); this._cliOutput += msg; - if (msg.includes("- Local:")) { - this._url = - msg - .split(/\s*- Local:/) - .pop() - ?.trim() ?? ""; + const potentialUrl = getURLFromLog(msg); + if (potentialUrl !== undefined) { + this._url = potentialUrl; resolve(); } console.log(msg); diff --git a/packages/test-utils/src/utils.ts b/packages/test-utils/src/utils.ts new file mode 100644 index 00000000..a786206b --- /dev/null +++ b/packages/test-utils/src/utils.ts @@ -0,0 +1,6 @@ +export const getURLFromLog = (message: string) => { + if (message.includes("- Local:")) { + return message.match(/\s*- Local:\s*(.+)\n/)?.[1]; + } + return undefined; +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f6f5b298..00b21e95 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8958,7 +8958,7 @@ packages: ansi-escapes: 5.0.0 cli-cursor: 4.0.0 slice-ansi: 5.0.0 - strip-ansi: 7.0.1 + strip-ansi: 7.1.0 wrap-ansi: 8.1.0 dev: true @@ -12216,7 +12216,7 @@ packages: dependencies: eastasianwidth: 0.2.0 emoji-regex: 9.2.2 - strip-ansi: 7.0.1 + strip-ansi: 7.1.0 dev: true /string.prototype.matchall@4.0.8: @@ -12286,13 +12286,6 @@ packages: dependencies: ansi-regex: 5.0.1 - /strip-ansi@7.0.1: - resolution: {integrity: sha512-cXNxvT8dFNRVfhVME3JAe98mkXDYN2O1l7jmcwMnOslDeESg1rF/OZMtK0nRAhiari1unG5cD4jG3rapUAkLbw==} - engines: {node: '>=12'} - dependencies: - ansi-regex: 6.0.1 - dev: true - /strip-ansi@7.1.0: resolution: {integrity: sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==} engines: {node: '>=12'} @@ -13700,7 +13693,7 @@ packages: dependencies: ansi-styles: 6.2.1 string-width: 5.1.2 - strip-ansi: 7.0.1 + strip-ansi: 7.1.0 dev: true /wrappy@1.0.2: