Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f13a454

Browse files
authored
test: fix test setup (#2749)
* test: fail prepare fixtures script if fixtures fail to install deps or build a fixture * test: intentionally break deps installation / fixture build to test prepare script changes * Revert "test: intentionally break deps installation / fixture build to test prepare script changes" This reverts commit 0d9c1f4. * ci: upgrade corepack * test: don't prepare e2e-only fixtures ahead of time
1 parent 4bcb34f commit f13a454

File tree

3 files changed

+63
-49
lines changed

3 files changed

+63
-49
lines changed

.github/workflows/run-tests.yml

+14-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ jobs:
6060
cache-dependency-path: '**/package-lock.json'
6161
- uses: oven-sh/setup-bun@v1
6262
- name: setup pnpm/yarn
63-
run: corepack enable
63+
run: |
64+
npm install -g corepack
65+
corepack enable
6466
shell: bash
6567
- name: Install Deno
6668
uses: denoland/setup-deno@v1
@@ -127,8 +129,18 @@ jobs:
127129
node-version: '18.x'
128130
cache: 'npm'
129131
cache-dependency-path: '**/package-lock.json'
132+
- name: Prefer npm global on windows
133+
if: runner.os == 'Windows'
134+
# On Windows by default PATH prefers corepack bundled with Node.js
135+
# This prepends npm global to PATH to ensure that npm installed global corepack is used instead
136+
run: |
137+
echo "$(npm config get prefix)" >> "$GITHUB_PATH"
138+
shell: bash
130139
- name: setup pnpm/yarn
131-
run: corepack enable
140+
run: |
141+
# global corepack installation requires --force on Windows, otherwise EEXIST errors occur
142+
npm install -g corepack --force
143+
corepack enable
132144
shell: bash
133145
- name: Install Deno
134146
uses: denoland/setup-deno@v1

tests/integration/turborepo.test.ts

-46
This file was deleted.

tests/prepare.mjs

+49-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,30 @@ const NEXT_VERSION = process.env.NEXT_VERSION ?? 'latest'
1818
const fixturesDir = fileURLToPath(new URL(`./fixtures`, import.meta.url))
1919
const fixtureFilter = argv[2] ?? ''
2020

21+
// E2E tests run next builds, so we don't need to prepare those ahead of time for integration tests
22+
const e2eOnlyFixtures = new Set([
23+
'after',
24+
'cli-before-regional-blobs-support',
25+
'dist-dir',
26+
// There is also a bug on Windows on Node.js 18.20.6, that cause build failures on this fixture
27+
// see https://github.com/opennextjs/opennextjs-netlify/actions/runs/13268839161/job/37043172448?pr=2749#step:12:78
28+
'middleware-og',
29+
'middleware-single-matcher',
30+
'nx-integrated',
31+
'turborepo',
32+
'turborepo-npm',
33+
'unstable-cache',
34+
])
35+
2136
const limit = pLimit(Math.max(2, cpus().length / 2))
2237
const fixtures = readdirSync(fixturesDir)
2338
// Ignoring things like `.DS_Store`.
2439
.filter((fixture) => !fixture.startsWith('.'))
2540
// Applying the filter, if one is set.
2641
.filter((fixture) => !fixtureFilter || fixture.startsWith(fixtureFilter))
42+
// Filter out fixtures that are only needed for E2E tests
43+
.filter((fixture) => !e2eOnlyFixtures.has(fixture))
44+
2745
console.log(`🧪 Preparing fixtures: ${fixtures.join(', ')}`)
2846
const fixtureList = new Set(fixtures)
2947
const fixtureCount = fixtures.length
@@ -62,7 +80,15 @@ const promises = fixtures.map((fixture) =>
6280
this.push(chunk.toString().replace(/\n/gm, `\n[${fixture}] `))
6381
callback()
6482
},
83+
flush(callback) {
84+
// final transform might create non-terminated line with a prefix
85+
// so this is just to make sure we end with a newline so further writes
86+
// to same destination stream start on a new line for better readability
87+
this.push('\n')
88+
callback()
89+
},
6590
})
91+
6692
console.log(`[${fixture}] Running \`${cmd}\`...`)
6793
const output = execaCommand(cmd, {
6894
cwd,
@@ -80,6 +106,11 @@ const promises = fixtures.map((fixture) =>
80106
operation: 'revert',
81107
})
82108
}
109+
if (output.exitCode !== 0) {
110+
const errorMessage = `[${fixture}] 🚨 Failed to install dependencies or build a fixture`
111+
console.error(errorMessage)
112+
throw new Error(errorMessage)
113+
}
83114
fixtureList.delete(fixture)
84115
})
85116
}).finally(() => {
@@ -91,5 +122,22 @@ const promises = fixtures.map((fixture) =>
91122
}
92123
}),
93124
)
94-
await Promise.allSettled(promises)
125+
const prepareFixturesResults = await Promise.allSettled(promises)
126+
const failedFixturesErrors = prepareFixturesResults
127+
.map((promise) => {
128+
if (promise.status === 'rejected') {
129+
return promise.reason
130+
}
131+
return null
132+
})
133+
.filter(Boolean)
134+
135+
if (failedFixturesErrors.length > 0) {
136+
console.error('Some fixtures failed to prepare:')
137+
for (const error of failedFixturesErrors) {
138+
console.error(error.message)
139+
}
140+
process.exit(1)
141+
}
142+
95143
console.log('🎉 All fixtures prepared')

0 commit comments

Comments
 (0)