| 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 |
|
|
| console.log( |
| 'Filtering tests using manifest:', |
| process.env.NEXT_EXTERNAL_TESTS_FILTERS |
| ) |
|
|
| |
| |
| if (!manifest.version || typeof manifest.version !== 'number') { |
| return (tests) => |
| tests |
| .filter((test) => { |
| const info = manifest[test.file] |
| |
| return !info || !info.runtimeError |
| }) |
| .map((test) => { |
| const info = manifest[test.file] |
| |
| if (info && (info.failed.length > 0 || info.flakey.length > 0)) { |
| test.excludedCases = info.failed.concat(info.flakey) |
| } |
| return test |
| }) |
| } |
|
|
| |
| |
| |
| if (manifest.version === 2) { |
| return (tests) => |
| tests |
| .filter((test) => { |
| |
| if (test.file in manifest.suites) return true |
|
|
| |
| |
| if ( |
| manifest.rules.include.every( |
| (pattern) => !minimatch(test.file, pattern) |
| ) |
| ) { |
| return false |
| } |
|
|
| |
| |
| if ( |
| manifest.rules.exclude?.some((pattern) => |
| minimatch(test.file, pattern) |
| ) |
| ) { |
| return false |
| } |
|
|
| |
| return true |
| }) |
| .map((test) => { |
| const info = manifest.suites[test.file] |
|
|
| |
| |
| if (!info) { |
| return test |
| } |
|
|
| |
| |
| 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 } |
|
|