rsnext/test/get-test-filter.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
2.8 KiB
JavaScript
Raw Normal View History

const path = require('path')
const minimatch = require('minimatch')
function getTestFilter() {
const manifest = process.env.NEXT_EXTERNAL_TESTS_FILTERS
? require(path.resolve(process.env.NEXT_EXTERNAL_TESTS_FILTERS))
: null
if (!manifest) return null
fix e2e deployment test action (#66721) [Test Run](https://github.com/vercel/next.js/actions/runs/9471783416/job/26095882422) Changes: - Add a setup step that clears the project so it doesn't happen in each runner - Run when a release is published rather than on cron - Notify via Slack when a failure occurs - Leverage build_reusable for the test runner to match the build_and_test workflow - Fixes to `next-deploy` script: not properly logging/catching errors - Adds manifest to ignore known issues - Split into 6 runners with 2 concurrency (12 deploys at a time) - Adds some logging so we know what's happening - Disable Playwright trace mode (it kept failing to find a trace file and cluttering the output. Don't think we need it here anyway) <details> - <summary>Removed noisy output</summary> ![CleanShot 2024-06-10 at 14 08 05@2x](https://github.com/vercel/next.js/assets/1939140/f227e71c-95b4-4859-90de-a23c88c55ea8) </details> <!-- 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 - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating 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 # -->
2024-06-11 22:59:43 +02:00
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) return true
// 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 }