diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 716543c5d9e76..aa47ddd237b51 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -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: diff --git a/run-tests.js b/run-tests.js index bb6000baeb90d..a08cdbe09498f 100644 --- a/run-tests.js +++ b/run-tests.js @@ -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`))