Skip to content

Commit

Permalink
test(test-utils): utility for --turbo testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Nov 23, 2022
1 parent e079fbb commit 06d8acc
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/lib/next-test-utils.js
Expand Up @@ -867,3 +867,38 @@ export function findAllTelemetryEvents(output, eventName) {
)
return events.filter((e) => e.eventName === eventName).map((e) => e.payload)
}

/**
* Utility function to determine if a given test case needs to run with --turbo.
*
* This is primarily for the gradual test enablement with latest turbopack upstream changes.
*
* Note: it could be possible to dynamically create test cases itself (createDevTest(): it.each([...])), but
* it makes hard to conform with existing lint rules. Instead, starting off from manual fixture setup and
* update test cases accordingly as turbopack changes enable more test cases.
*/
export function shouldRunTurboDevTest() {
const shouldRunTurboDev = !!process.env.__INTERNAL_NEXT_DEV_TEST_TURBO_DEV
// short-circuit to run all the test with --turbo enabled skips glob matching costs
if (shouldRunTurboDev) {
return true
}

const shouldRunTurboDevWithMatches =
!!process.env.__INTERNAL_NEXT_DEV_TEST_TURBO_GLOB_MATCH

// By default, we do not run any tests with `--turbo` flag.
if (!shouldRunTurboDevWithMatches) {
return false
}

const glob = require('glob')
const matches = glob.sync(
process.env.__INTERNAL_NEXT_DEV_TEST_TURBO_GLOB_MATCH
)
const testPath = expect.getState().testPath
const isMatch = matches.some((match) => testPath.includes(match))

// If the test path matches the glob pattern, add additional case to run the test with `--turbo` flag.
return isMatch
}

0 comments on commit 06d8acc

Please sign in to comment.