|
| 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 | +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 | + |
| 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 | +); |
| 21 | + |
| 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 | + ]); |
| 31 | + |
| 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', |
| 58 | + }); |
| 59 | + const name = `waku-${version}.tgz`; |
| 60 | + execSync(`npm install ${join(standaloneDir, name)}`, { |
| 61 | + cwd: standaloneDir, |
| 62 | + stdio: 'inherit', |
| 63 | + }); |
| 64 | + execSync( |
| 65 | + `node ${join(standaloneDir, './node_modules/waku/dist/cli.js')} build`, |
| 66 | + { |
| 67 | + cwd: standaloneAppDir, |
| 68 | + stdio: 'inherit', |
| 69 | + }, |
| 70 | + ); |
| 71 | + }); |
| 72 | + |
| 73 | + test.describe('renders', () => { |
| 74 | + test(`the home page`, async ({ page }) => { |
| 75 | + const [port, pid] = await start(); |
| 76 | + await page.goto(`http://localhost:${port}`); |
| 77 | + await expect(page.getByTestId('header')).toHaveText('Waku'); |
| 78 | + await terminate(pid!); |
| 79 | + }); |
| 80 | + }); |
| 81 | +}); |
0 commit comments