Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

additional test runner refactoring #53406

Merged
merged 8 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading