Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(turbopack): script to sync latest test lists #50008

Merged
merged 2 commits into from May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_test_deploy.yml
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
@@ -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))