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: ...@@ -131,7 +131,7 @@ jobs:
uses: ./.github/workflows/build_reusable.yml uses: ./.github/workflows/build_reusable.yml
with: with:
skipForDocsOnly: 'yes' 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 secrets: inherit
test-turbopack-integration: test-turbopack-integration:
...@@ -146,7 +146,7 @@ jobs: ...@@ -146,7 +146,7 @@ jobs:
with: with:
nodeVersion: 16 nodeVersion: 16
skipForDocsOnly: 'yes' 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 secrets: inherit
test-next-swc-wasm: test-next-swc-wasm:
...@@ -169,7 +169,7 @@ jobs: ...@@ -169,7 +169,7 @@ jobs:
uses: ./.github/workflows/build_reusable.yml uses: ./.github/workflows/build_reusable.yml
with: with:
skipForDocsOnly: 'yes' 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 secrets: inherit
...@@ -184,7 +184,7 @@ jobs: ...@@ -184,7 +184,7 @@ jobs:
uses: ./.github/workflows/build_reusable.yml uses: ./.github/workflows/build_reusable.yml
with: with:
skipForDocsOnly: 'yes' 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 secrets: inherit
test-integration: test-integration:
...@@ -199,7 +199,7 @@ jobs: ...@@ -199,7 +199,7 @@ jobs:
with: with:
nodeVersion: 16 nodeVersion: 16
skipForDocsOnly: 'yes' 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 secrets: inherit
test-firefox-safari: test-firefox-safari:
......
...@@ -41,11 +41,18 @@ const TIMINGS_API_HEADERS = { ...@@ -41,11 +41,18 @@ const TIMINGS_API_HEADERS = {
} }
const testFilters = { const testFilters = {
unit: 'unit/', development: new RegExp(
e2e: 'e2e/', '^(test/(development|e2e|unit)|packages/.*/src/.*)/.*\\.test\\.(js|jsx|ts|tsx)$'
production: 'production/', ),
development: 'development/', 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/', examples: 'examples/',
integration: 'test/integration/',
e2e: 'test/e2e/',
} }
const mockTrace = () => ({ const mockTrace = () => ({
...@@ -70,6 +77,14 @@ const cleanUpAndExit = async (code) => { ...@@ -70,6 +77,14 @@ const cleanUpAndExit = async (code) => {
}, 1) }, 1)
} }
const isMatchingPattern = (pattern, test) => {
if (pattern instanceof RegExp) {
return pattern.test(test)
} else {
return test.startsWith(pattern)
}
}
async function getTestTimings() { async function getTestTimings() {
let timingsRes let timingsRes
...@@ -119,27 +134,14 @@ async function main() { ...@@ -119,27 +134,14 @@ async function main() {
filterTestsBy = testFilters.unit filterTestsBy = testFilters.unit
break break
} }
case 'development': { case 'all': {
filterTestsBy = testFilters.development filterTestsBy = 'none'
break
}
case 'production': {
filterTestsBy = testFilters.production
break
}
case 'e2e': {
filterTestsBy = testFilters.e2e
break break
} }
case 'examples': { default: {
filterTestsBy = testFilters.examples filterTestsBy = testFilters[testType]
break break
} }
case 'all':
filterTestsBy = 'none'
break
default:
break
} }
console.log('Running tests with concurrency:', concurrency) console.log('Running tests with concurrency:', concurrency)
...@@ -166,11 +168,13 @@ async function main() { ...@@ -166,11 +168,13 @@ async function main() {
} }
if (filterTestsBy) { if (filterTestsBy) {
// only include the specified type // only include the specified type
return filterTestsBy === 'none' ? true : test.startsWith(filterTestsBy) if (filterTestsBy === 'none') {
} else { return true
// include all except the separately configured types }
return !configuredTestTypes.some((type) => test.startsWith(type)) 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() { ...@@ -265,7 +269,7 @@ async function main() {
if (testNames.length === 0) { if (testNames.length === 0) {
console.log('No tests found for', testType, 'exiting..') console.log('No tests found for', testType, 'exiting..')
return cleanUpAndExit(0) return cleanUpAndExit(1)
} }
console.log('Running tests:', '\n', ...testNames.map((name) => `${name}\n`)) 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