Skip to content

Commit d53739f

Browse files
authored
chore: make test setup log errors (#99)
1 parent b77512e commit d53739f

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

tests/fixtures/simple-next-app-pnpm/next.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3+
swcMinify: true,
34
output: 'standalone',
45
eslint: {
56
ignoreDuringBuilds: true,

tests/prepare.mjs

+35-12
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,50 @@
1+
// @ts-check
12
// this installs and builds all the fixtures
23
// Needed to run before executing the integration tests
34
import { execaCommand } from 'execa'
45
import { existsSync, readdirSync } from 'node:fs'
56
import { rm } from 'node:fs/promises'
67
import { join } from 'node:path'
78
import { fileURLToPath } from 'node:url'
9+
import { cpus } from 'node:os'
10+
import pLimit from 'p-limit'
11+
import { Transform } from 'node:stream'
812

913
const fixturesDir = fileURLToPath(new URL(`./fixtures`, import.meta.url))
1014

11-
console.log('Preparing test fixtures:')
15+
const limit = pLimit(Math.max(2, cpus().length))
1216
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)
1722

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`
2025

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+
}
2429

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+
),
2750
)

0 commit comments

Comments
 (0)