Skip to content

Commit

Permalink
test: fix test setup (#2749)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pieh authored Feb 12, 2025
1 parent 4bcb34f commit f13a454
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 49 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ jobs:
cache-dependency-path: '**/package-lock.json'
- uses: oven-sh/setup-bun@v1
- name: setup pnpm/yarn
run: corepack enable
run: |
npm install -g corepack
corepack enable
shell: bash
- name: Install Deno
uses: denoland/setup-deno@v1
Expand Down Expand Up @@ -127,8 +129,18 @@ jobs:
node-version: '18.x'
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Prefer npm global on windows
if: runner.os == 'Windows'
# On Windows by default PATH prefers corepack bundled with Node.js
# This prepends npm global to PATH to ensure that npm installed global corepack is used instead
run: |
echo "$(npm config get prefix)" >> "$GITHUB_PATH"
shell: bash
- name: setup pnpm/yarn
run: corepack enable
run: |
# global corepack installation requires --force on Windows, otherwise EEXIST errors occur
npm install -g corepack --force
corepack enable
shell: bash
- name: Install Deno
uses: denoland/setup-deno@v1
Expand Down
46 changes: 0 additions & 46 deletions tests/integration/turborepo.test.ts

This file was deleted.

50 changes: 49 additions & 1 deletion tests/prepare.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,30 @@ const NEXT_VERSION = process.env.NEXT_VERSION ?? 'latest'
const fixturesDir = fileURLToPath(new URL(`./fixtures`, import.meta.url))
const fixtureFilter = argv[2] ?? ''

// E2E tests run next builds, so we don't need to prepare those ahead of time for integration tests
const e2eOnlyFixtures = new Set([
'after',
'cli-before-regional-blobs-support',
'dist-dir',
// There is also a bug on Windows on Node.js 18.20.6, that cause build failures on this fixture
// see https://github.com/opennextjs/opennextjs-netlify/actions/runs/13268839161/job/37043172448?pr=2749#step:12:78
'middleware-og',
'middleware-single-matcher',
'nx-integrated',
'turborepo',
'turborepo-npm',
'unstable-cache',
])

const limit = pLimit(Math.max(2, cpus().length / 2))
const fixtures = readdirSync(fixturesDir)
// Ignoring things like `.DS_Store`.
.filter((fixture) => !fixture.startsWith('.'))
// Applying the filter, if one is set.
.filter((fixture) => !fixtureFilter || fixture.startsWith(fixtureFilter))
// Filter out fixtures that are only needed for E2E tests
.filter((fixture) => !e2eOnlyFixtures.has(fixture))

console.log(`🧪 Preparing fixtures: ${fixtures.join(', ')}`)
const fixtureList = new Set(fixtures)
const fixtureCount = fixtures.length
Expand Down Expand Up @@ -62,7 +80,15 @@ const promises = fixtures.map((fixture) =>
this.push(chunk.toString().replace(/\n/gm, `\n[${fixture}] `))
callback()
},
flush(callback) {
// final transform might create non-terminated line with a prefix
// so this is just to make sure we end with a newline so further writes
// to same destination stream start on a new line for better readability
this.push('\n')
callback()
},
})

console.log(`[${fixture}] Running \`${cmd}\`...`)
const output = execaCommand(cmd, {
cwd,
Expand All @@ -80,6 +106,11 @@ const promises = fixtures.map((fixture) =>
operation: 'revert',
})
}
if (output.exitCode !== 0) {
const errorMessage = `[${fixture}] 🚨 Failed to install dependencies or build a fixture`
console.error(errorMessage)
throw new Error(errorMessage)
}
fixtureList.delete(fixture)
})
}).finally(() => {
Expand All @@ -91,5 +122,22 @@ const promises = fixtures.map((fixture) =>
}
}),
)
await Promise.allSettled(promises)
const prepareFixturesResults = await Promise.allSettled(promises)
const failedFixturesErrors = prepareFixturesResults
.map((promise) => {
if (promise.status === 'rejected') {
return promise.reason
}
return null
})
.filter(Boolean)

if (failedFixturesErrors.length > 0) {
console.error('Some fixtures failed to prepare:')
for (const error of failedFixturesErrors) {
console.error(error.message)
}
process.exit(1)
}

console.log('🎉 All fixtures prepared')

0 comments on commit f13a454

Please sign in to comment.