|
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'; |
5 | 1 | 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'; |
10 | 2 |
|
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'; |
21 | 4 |
|
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'); |
31 | 6 |
|
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")); |
58 | 13 | });
|
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(); |
63 | 16 | });
|
64 |
| - execSync( |
65 |
| - `node ${join(standaloneDir, './node_modules/waku/dist/cli.js')} build`, |
66 |
| - { |
67 |
| - cwd: standaloneAppDir, |
68 |
| - stdio: 'inherit', |
69 |
| - }, |
70 |
| - ); |
71 |
| - }); |
72 | 17 |
|
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 }) => { |
76 | 19 | await page.goto(`http://localhost:${port}`);
|
77 | 20 | await expect(page.getByTestId('header')).toHaveText('Waku');
|
78 |
| - await terminate(pid!); |
79 | 21 | });
|
80 | 22 | });
|
81 |
| -}); |
| 23 | +} |
0 commit comments