Skip to content

Commit

Permalink
test(turbopack): script to sync latest test lists (vercel#50008)
Browse files Browse the repository at this point in the history
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

This PR adjusts manifests for the next.js test with Turbopack, as I
found upstream test keep changing and need to sync its latests state
into the manifest.

Manifest is now .js file contains 2 arrays, one for the enabled, and
others for the disabled. Disabled doesn't mean it's always failing
though.
  • Loading branch information
kwonoj authored and hydRAnger committed Jun 12, 2023
1 parent 662939a commit bcc2bb8
Show file tree
Hide file tree
Showing 5 changed files with 795 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ jobs:
NEXT_BINDINGS_BIN: /work/packages/next-swc/native/next-swc.linux-x64-gnu.node
# Glob pattern to run specific tests with --turbo.
NEXT_DEV_TEST_GLOB: '*'
NEXT_EXTERNAL_TESTS_FILTERS: /work/packages/next-swc/crates/next-dev-tests/tests-manifest.json
NEXT_EXTERNAL_TESTS_FILTERS: /work/packages/next-swc/crates/next-dev-tests/tests-manifest.js

strategy:
fail-fast: false
Expand Down
64 changes: 64 additions & 0 deletions packages/next-swc/crates/next-dev-tests/sync-tests-manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// A script to remove / add next.js tests into the lists if there are any changes.

const fs = require('fs')
const _glob = require('glob')
const { promisify } = require('util')
const glob = promisify(_glob)
const path = require('path')

const generateManifest = (enabledTests, disabledTests) => `
// Tests that are currently enabled with Turbopack in CI.
// Add new test when Turbopack updates to fix / implement a feature.
const enabledTests = ${enabledTests}
// Tests that are currently disabled with Turbopack in CI.
const disabledTests = ${disabledTests}
module.exports = {
enabledTests,
disabledTests,
}`

const main = async () => {
// Read existing manifests
let enabledTests = []
let disabledTests = []

const manifestPath = path.resolve(__dirname, 'tests-manifest.js')
if (fs.existsSync(manifestPath)) {
const manifest = require(manifestPath)
enabledTests = manifest.enabledTests
disabledTests = manifest.disabledTests
} else {
throw new Error('a')
}

// Collect all test files
const testFiles = (
await glob('**/*.test.{js,ts,tsx}', {
nodir: true,
cwd: path.resolve(__dirname, '../../../../test'),
})
).map((file) => `test/${file}`)

// Naively update enabled / disabled tests to the latest.
// This is not the most efficient way to do this, but it's good enough for now.

// First, remove enabled tests that are no longer in the test directory.
enabledTests = enabledTests.filter((testFile) => testFiles.includes(testFile))
// Anything else are disabled.
disabledTests = testFiles.filter(
(testFile) => !enabledTests.includes(testFile)
)

fs.writeFileSync(
manifestPath,
generateManifest(
JSON.stringify(enabledTests, null, 2),
JSON.stringify(disabledTests, null, 2)
),
'utf-8'
)
}

main().catch((e) => console.error(e))

0 comments on commit bcc2bb8

Please sign in to comment.