Skip to content

Commit

Permalink
additional test runner refactoring (#53406)
Browse files Browse the repository at this point in the history
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: JJ Kasper <22380829+ijjk@users.noreply.github.com>
  • Loading branch information
ztanner and ijjk authored Aug 1, 2023
1 parent fc52e02 commit 3b1ccbf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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:
Expand Down
56 changes: 30 additions & 26 deletions run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => ({
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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))
})
}

Expand Down Expand Up @@ -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`))
Expand Down

0 comments on commit 3b1ccbf

Please sign in to comment.