|
| 1 | +// @ts-check |
1 | 2 | // this installs and builds all the fixtures
|
2 | 3 | // Needed to run before executing the integration tests
|
3 | 4 | import { execaCommand } from 'execa'
|
4 | 5 | import { existsSync, readdirSync } from 'node:fs'
|
5 | 6 | import { rm } from 'node:fs/promises'
|
6 | 7 | import { join } from 'node:path'
|
7 | 8 | import { fileURLToPath } from 'node:url'
|
| 9 | +import { cpus } from 'node:os' |
| 10 | +import pLimit from 'p-limit' |
| 11 | +import { Transform } from 'node:stream' |
8 | 12 |
|
9 | 13 | const fixturesDir = fileURLToPath(new URL(`./fixtures`, import.meta.url))
|
10 | 14 |
|
11 |
| -console.log('Preparing test fixtures:') |
| 15 | +const limit = pLimit(Math.max(2, cpus().length)) |
12 | 16 | await Promise.all(
|
13 |
| - readdirSync(fixturesDir).map(async (fixture) => { |
14 |
| - console.log(`◆ Preparing fixture: ${fixture}`) |
15 |
| - await rm(join(fixturesDir, fixture, '.next'), { recursive: true, force: true }) |
16 |
| - const cwd = join(fixturesDir, fixture) |
| 17 | + readdirSync(fixturesDir).map((fixture) => |
| 18 | + limit(async () => { |
| 19 | + console.log(`[${fixture}] Preparing fixture`) |
| 20 | + await rm(join(fixturesDir, fixture, '.next'), { recursive: true, force: true }) |
| 21 | + const cwd = join(fixturesDir, fixture) |
17 | 22 |
|
18 |
| - // npm is the default |
19 |
| - let cmd = `npm install --no-audit --progress=false --prefer-offline` |
| 23 | + // npm is the default |
| 24 | + let cmd = `npm install --no-audit --progress=false --prefer-offline` |
20 | 25 |
|
21 |
| - if (existsSync(join(cwd, 'pnpm-lock.yaml'))) { |
22 |
| - cmd = `pnpm install --reporter=silent` |
23 |
| - } |
| 26 | + if (existsSync(join(cwd, 'pnpm-lock.yaml'))) { |
| 27 | + cmd = `pnpm install --reporter=silent` |
| 28 | + } |
24 | 29 |
|
25 |
| - return execaCommand(cmd, { cwd }) |
26 |
| - }), |
| 30 | + const addPrefix = new Transform({ |
| 31 | + transform(chunk, encoding, callback) { |
| 32 | + this.push(chunk.toString().replace(/\n/gm, `\n[${fixture}] `)) |
| 33 | + callback() |
| 34 | + }, |
| 35 | + }) |
| 36 | + |
| 37 | + const output = execaCommand(cmd, { |
| 38 | + cwd, |
| 39 | + stdio: 'pipe', |
| 40 | + env: { ...process.env, FORCE_COLOR: '1' }, |
| 41 | + }) |
| 42 | + if (process.env.DEBUG) { |
| 43 | + output.stdout?.pipe(addPrefix).pipe(process.stdout) |
| 44 | + } |
| 45 | + output.stderr?.pipe(addPrefix).pipe(process.stderr) |
| 46 | + |
| 47 | + return output |
| 48 | + }), |
| 49 | + ), |
27 | 50 | )
|
0 commit comments