Skip to content

Commit 7412111

Browse files
committed
Add monorepo packageDir param to startApp e2e util
1 parent ffe0478 commit 7412111

File tree

3 files changed

+18
-74
lines changed

3 files changed

+18
-74
lines changed

e2e/monorepo.spec.ts

+12-70
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,23 @@
1-
import { debugChildProcess, getFreePort, terminate, test } from './utils.js';
2-
import { fileURLToPath } from 'node:url';
3-
import { cp, mkdtemp } from 'node:fs/promises';
4-
import { exec, execSync } from 'node:child_process';
51
import { expect } from '@playwright/test';
6-
import waitPort from 'wait-port';
7-
import { join } from 'node:path';
8-
import { tmpdir } from 'node:os';
9-
import { createRequire } from 'node:module';
102

11-
let standaloneDir: string;
12-
let standaloneAppDir: string;
13-
const appRelativePath = '/packages/waku-project';
14-
const exampleDir = fileURLToPath(
15-
new URL('./fixtures/monorepo', import.meta.url),
16-
);
17-
const wakuDir = fileURLToPath(new URL('../packages/waku', import.meta.url));
18-
const { version } = createRequire(import.meta.url)(
19-
join(wakuDir, 'package.json'),
20-
);
3+
import { test, prepareStandaloneSetup } from './utils.js';
214

22-
async function start() {
23-
const port = await getFreePort();
24-
const cp = exec(
25-
`node ${join(standaloneDir, './node_modules/waku/dist/cli.js')} start --port ${port}`,
26-
{ cwd: standaloneDir },
27-
);
28-
debugChildProcess(cp, fileURLToPath(import.meta.url), [
29-
/ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time/,
30-
]);
5+
const startApp = prepareStandaloneSetup('monorepo');
316

32-
await waitPort({ port });
33-
return [port, cp.pid] as const;
34-
}
35-
36-
test.describe('monorepo', async () => {
37-
test.beforeEach(async () => {
38-
// GitHub Action on Windows doesn't support mkdtemp on global temp dir,
39-
// Which will cause files in `src` folder to be empty.
40-
// I don't know why
41-
const tmpDir = process.env.TEMP_DIR ? process.env.TEMP_DIR : tmpdir();
42-
standaloneDir = await mkdtemp(join(tmpDir, 'waku-monorepo-'));
43-
standaloneAppDir = join(standaloneDir, appRelativePath);
44-
await cp(exampleDir, standaloneDir, {
45-
filter: (src) => {
46-
return !src.includes('node_modules') && !src.includes('dist');
47-
},
48-
recursive: true,
49-
});
50-
51-
// FIXME we need to `npm install` in the monorepo but
52-
// how do we copy in the local version of waku or link
53-
// it in a way that will accurately match what happens
54-
// with the npm published version.
55-
execSync(`pnpm pack --pack-destination ${standaloneDir}`, {
56-
cwd: wakuDir,
57-
stdio: 'inherit',
7+
for (const mode of ['DEV', 'PRD'] as const) {
8+
test.describe(`monorepo: ${mode}`, () => {
9+
let port: number;
10+
let stopApp: () => Promise<void>;
11+
test.beforeAll(async () => {
12+
({ port, stopApp } = await startApp(mode, "packages/waku-project"));
5813
});
59-
const name = `waku-${version}.tgz`;
60-
execSync(`npm install ${join(standaloneDir, name)}`, {
61-
cwd: standaloneDir,
62-
stdio: 'inherit',
14+
test.afterAll(async () => {
15+
await stopApp();
6316
});
64-
execSync(
65-
`node ${join(standaloneDir, './node_modules/waku/dist/cli.js')} build`,
66-
{
67-
cwd: standaloneAppDir,
68-
stdio: 'inherit',
69-
},
70-
);
71-
});
7217

73-
test.describe('renders', () => {
74-
test(`the home page`, async ({ page }) => {
75-
const [port, pid] = await start();
18+
test('renders the home page', async ({ page }) => {
7619
await page.goto(`http://localhost:${port}`);
7720
await expect(page.getByTestId('header')).toHaveText('Waku');
78-
await terminate(pid!);
7921
});
8022
});
81-
});
23+
}

e2e/utils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export const prepareStandaloneSetup = (fixtureName: string) => {
151151
const tmpDir = process.env.TEMP_DIR || tmpdir();
152152
let standaloneDir: string | undefined;
153153
let built = false;
154-
const startApp = async (mode: 'DEV' | 'PRD' | 'STATIC') => {
154+
const startApp = async (mode: 'DEV' | 'PRD' | 'STATIC', packageDir = '') => {
155155
if (!standaloneDir) {
156156
standaloneDir = mkdtempSync(join(tmpDir, fixtureName));
157157
cpSync(fixtureDir, standaloneDir, {
@@ -170,10 +170,10 @@ export const prepareStandaloneSetup = (fixtureName: string) => {
170170
);
171171
}
172172
if (mode !== 'DEV' && !built) {
173-
rmSync(`${standaloneDir}/dist`, { recursive: true, force: true });
173+
rmSync(`${standaloneDir}${packageDir}/dist`, { recursive: true, force: true });
174174
execSync(
175175
`node ${join(standaloneDir, './node_modules/waku/dist/cli.js')} build`,
176-
{ cwd: standaloneDir },
176+
{ cwd: join(standaloneDir, packageDir) },
177177
);
178178
built = true;
179179
}
@@ -190,7 +190,7 @@ export const prepareStandaloneSetup = (fixtureName: string) => {
190190
cmd = `node ${join(standaloneDir, './node_modules/serve/build/main.js')} dist/public -p ${port}`;
191191
break;
192192
}
193-
const cp = exec(cmd, { cwd: standaloneDir });
193+
const cp = exec(cmd, { cwd: join(standaloneDir, packageDir) });
194194
debugChildProcess(cp, fileURLToPath(import.meta.url), [
195195
/ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time/,
196196
]);

pnpm-lock.yaml

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)