Skip to content

Commit

Permalink
test(turbopack): script to sync latest test lists
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed May 18, 2023
1 parent eaea208 commit e53e076
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
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))

0 comments on commit e53e076

Please sign in to comment.