Unverified Commit 3b1ccbf9 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

additional test runner refactoring (#53406)

This relocates the regex patterns that were being used for `test-dev`, `test-prod`, and `test-integration` actions to be part of `run-tests`. Also fixes e2e tests since they were expected to be found in `e2e` rather than `test/e2e`, and updated it exit with a failure code in case of no tests being found 
Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent fc52e027
......@@ -131,7 +131,7 @@ jobs:
uses: ./.github/workflows/build_reusable.yml
with:
skipForDocsOnly: 'yes'
afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/packages/next-swc/crates/next-dev-tests/tests-manifest.js" TURBOPACK=1 __INTERNAL_CUSTOM_TURBOPACK_BINDINGS="$(pwd)/packages/next-swc/native/next-swc.linux-x64-gnu.node" NEXT_E2E_TEST_TIMEOUT=240000 NEXT_TEST_MODE=dev node run-tests.js --type development --timings -c ${TEST_CONCURRENCY}
afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/packages/next-swc/crates/next-dev-tests/tests-manifest.js" TURBOPACK=1 __INTERNAL_CUSTOM_TURBOPACK_BINDINGS="$(pwd)/packages/next-swc/native/next-swc.linux-x64-gnu.node" NEXT_E2E_TEST_TIMEOUT=240000 NEXT_TEST_MODE=dev node run-tests.js --test-pattern '^(test\/development)/.*\.test\.(js|jsx|ts|tsx)$' --timings -c ${TEST_CONCURRENCY}
secrets: inherit
test-turbopack-integration:
......@@ -146,7 +146,7 @@ jobs:
with:
nodeVersion: 16
skipForDocsOnly: 'yes'
afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/packages/next-swc/crates/next-dev-tests/tests-manifest.js" TURBOPACK=1 __INTERNAL_CUSTOM_TURBOPACK_BINDINGS="$(pwd)/packages/next-swc/native/next-swc.linux-x64-gnu.node" node run-tests.js --timings -g ${{ matrix.group }}/5 -c ${TEST_CONCURRENCY} --test-pattern '^(test\/integration)/.*\.test\.(js|jsx|ts|tsx)$'
afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/packages/next-swc/crates/next-dev-tests/tests-manifest.js" TURBOPACK=1 __INTERNAL_CUSTOM_TURBOPACK_BINDINGS="$(pwd)/packages/next-swc/native/next-swc.linux-x64-gnu.node" node run-tests.js --timings -g ${{ matrix.group }}/5 -c ${TEST_CONCURRENCY} --type integration
secrets: inherit
test-next-swc-wasm:
......@@ -169,7 +169,7 @@ jobs:
uses: ./.github/workflows/build_reusable.yml
with:
skipForDocsOnly: 'yes'
afterBuild: NEXT_TEST_MODE=dev node run-tests.js --timings -g ${{ matrix.group }}/3 -c ${TEST_CONCURRENCY} --test-pattern '^(test\/(development|e2e|unit)|packages\/.*\/src\/.*)/.*\.test\.(js|jsx|ts|tsx)$'
afterBuild: NEXT_TEST_MODE=dev node run-tests.js --timings -g ${{ matrix.group }}/3 -c ${TEST_CONCURRENCY} --type development
secrets: inherit
......@@ -184,7 +184,7 @@ jobs:
uses: ./.github/workflows/build_reusable.yml
with:
skipForDocsOnly: 'yes'
afterBuild: NEXT_TEST_MODE=start node run-tests.js --timings -g ${{ matrix.group }}/5 -c ${TEST_CONCURRENCY} --test-pattern '^(test\/(production|e2e))/.*\.test\.(js|jsx|ts|tsx)$'
afterBuild: NEXT_TEST_MODE=start node run-tests.js --timings -g ${{ matrix.group }}/5 -c ${TEST_CONCURRENCY} --type production
secrets: inherit
test-integration:
......@@ -199,7 +199,7 @@ jobs:
with:
nodeVersion: 16
skipForDocsOnly: 'yes'
afterBuild: node run-tests.js --timings -g ${{ matrix.group }}/12 -c ${TEST_CONCURRENCY} --test-pattern '^(test\/integration)/.*\.test\.(js|jsx|ts|tsx)$'
afterBuild: node run-tests.js --timings -g ${{ matrix.group }}/12 -c ${TEST_CONCURRENCY} --type integration
secrets: inherit
test-firefox-safari:
......
......@@ -41,11 +41,18 @@ const TIMINGS_API_HEADERS = {
}
const testFilters = {
unit: 'unit/',
e2e: 'e2e/',
production: 'production/',
development: 'development/',
development: new RegExp(
'^(test/(development|e2e|unit)|packages/.*/src/.*)/.*\\.test\\.(js|jsx|ts|tsx)$'
),
production: new RegExp(
'^(test/(production|e2e))/.*\\.test\\.(js|jsx|ts|tsx)$'
),
unit: new RegExp(
'^test/unit|packages/.*/src/.*/.*\\.test\\.(js|jsx|ts|tsx)$'
),
examples: 'examples/',
integration: 'test/integration/',
e2e: 'test/e2e/',
}
const mockTrace = () => ({
......@@ -70,6 +77,14 @@ const cleanUpAndExit = async (code) => {
}, 1)
}
const isMatchingPattern = (pattern, test) => {
if (pattern instanceof RegExp) {
return pattern.test(test)
} else {
return test.startsWith(pattern)
}
}
async function getTestTimings() {
let timingsRes
......@@ -119,27 +134,14 @@ async function main() {
filterTestsBy = testFilters.unit
break
}
case 'development': {
filterTestsBy = testFilters.development
break
}
case 'production': {
filterTestsBy = testFilters.production
break
}
case 'e2e': {
filterTestsBy = testFilters.e2e
case 'all': {
filterTestsBy = 'none'
break
}
case 'examples': {
filterTestsBy = testFilters.examples
default: {
filterTestsBy = testFilters[testType]
break
}
case 'all':
filterTestsBy = 'none'
break
default:
break
}
console.log('Running tests with concurrency:', concurrency)
......@@ -166,11 +168,13 @@ async function main() {
}
if (filterTestsBy) {
// only include the specified type
return filterTestsBy === 'none' ? true : test.startsWith(filterTestsBy)
} else {
// include all except the separately configured types
return !configuredTestTypes.some((type) => test.startsWith(type))
if (filterTestsBy === 'none') {
return true
}
return isMatchingPattern(filterTestsBy, test)
}
// include all except the separately configured types
return !configuredTestTypes.some((type) => isMatchingPattern(type, test))
})
}
......@@ -265,7 +269,7 @@ async function main() {
if (testNames.length === 0) {
console.log('No tests found for', testType, 'exiting..')
return cleanUpAndExit(0)
return cleanUpAndExit(1)
}
console.log('Running tests:', '\n', ...testNames.map((name) => `${name}\n`))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment