Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
138 lines
4.4 KiB
JavaScript
138 lines
4.4 KiB
JavaScript
const path = require('path')
|
|
const minimatch = require('minimatch')
|
|
|
|
function getManifest() {
|
|
const nextExternalTestFilters = process.env.NEXT_EXTERNAL_TESTS_FILTERS
|
|
if (!nextExternalTestFilters) {
|
|
return null
|
|
}
|
|
|
|
return nextExternalTestFilters
|
|
.split(',')
|
|
.reduce((mergedManifest, manifestPath) => {
|
|
const manifest = require(path.resolve(manifestPath))
|
|
if (!mergedManifest) {
|
|
return manifest
|
|
}
|
|
|
|
if (manifest.version === 2) {
|
|
for (const suite in manifest.suites) {
|
|
if (mergedManifest.suites[suite]) {
|
|
const mergedSuite = mergedManifest.suites[suite]
|
|
const currentSuite = manifest.suites[suite]
|
|
mergedSuite.failed = [
|
|
...(mergedSuite.failed || []),
|
|
...(currentSuite.failed || []),
|
|
]
|
|
mergedSuite.flakey = [
|
|
...(mergedSuite.flakey || []),
|
|
...(currentSuite.flakey || []),
|
|
]
|
|
} else {
|
|
mergedManifest.suites[suite] = manifest.suites[suite]
|
|
}
|
|
}
|
|
mergedManifest.rules.include.push(...(manifest.rules.include || []))
|
|
mergedManifest.rules.exclude.push(...(manifest.rules.exclude || []))
|
|
return mergedManifest
|
|
}
|
|
|
|
throw new Error(
|
|
`Merging manifests is only supported for version 2: ${manifestPath}`
|
|
)
|
|
}, null)
|
|
}
|
|
|
|
function getTestFilter() {
|
|
const manifest = getManifest()
|
|
if (!manifest) return null
|
|
|
|
console.log(
|
|
'Filtering tests using manifest:',
|
|
process.env.NEXT_EXTERNAL_TESTS_FILTERS
|
|
)
|
|
|
|
// For the legacy manifest without a version, we assume it's a complete list
|
|
// of all the tests.
|
|
if (!manifest.version || typeof manifest.version !== 'number') {
|
|
return (tests) =>
|
|
tests
|
|
.filter((test) => {
|
|
const info = manifest[test.file]
|
|
// Include tests that are not in the manifest
|
|
return !info || !info.runtimeError
|
|
})
|
|
.map((test) => {
|
|
const info = manifest[test.file]
|
|
// Exclude failing and flakey tests, newly added tests are automatically included
|
|
if (info && (info.failed.length > 0 || info.flakey.length > 0)) {
|
|
test.excludedCases = info.failed.concat(info.flakey)
|
|
}
|
|
return test
|
|
})
|
|
}
|
|
|
|
// The new manifest version 2 only contains the list of tests that should
|
|
// be run, with exclusions added based on rules. Any new tests that are added
|
|
// will be automatically included if they match the include rules.
|
|
if (manifest.version === 2) {
|
|
return (tests) =>
|
|
tests
|
|
.filter((test) => {
|
|
// Check to see if this was included as-is in the manifest.
|
|
if (test.file in manifest.suites) {
|
|
// When merging multiple manifests, a test file may be included in
|
|
// the suites by one manifest, but excluded in the rules by another.
|
|
// If it's excluded by filename (and not by pattern), the exclusion
|
|
// takes precedence over the inclusion.
|
|
return !manifest.rules.exclude?.includes(test.file)
|
|
}
|
|
|
|
// If this file doesn't match any of the include patterns, then it
|
|
// should be excluded.
|
|
if (
|
|
manifest.rules.include.every(
|
|
(pattern) => !minimatch(test.file, pattern)
|
|
)
|
|
) {
|
|
return false
|
|
}
|
|
|
|
// If the file matches any of the exclude patterns, then it should be
|
|
// excluded.
|
|
if (
|
|
manifest.rules.exclude?.some((pattern) =>
|
|
minimatch(test.file, pattern)
|
|
)
|
|
) {
|
|
return false
|
|
}
|
|
|
|
// Otherwise, it should be included.
|
|
return true
|
|
})
|
|
.map((test) => {
|
|
const info = manifest.suites[test.file]
|
|
|
|
// If there's no info for this test, then it's a test that has no
|
|
// failures or flakey tests, so we can just include it as-is.
|
|
if (!info) {
|
|
return test
|
|
}
|
|
|
|
// Exclude failing and flakey tests, newly added tests are
|
|
// automatically included.
|
|
const { failed = [], flakey = [] } = info
|
|
if (failed.length > 0 || flakey.length > 0) {
|
|
test.excludedCases = failed.concat(flakey)
|
|
}
|
|
|
|
return test
|
|
})
|
|
}
|
|
|
|
throw new Error(`Unknown manifest version: ${manifest.version}`)
|
|
}
|
|
|
|
module.exports = { getTestFilter }
|