Skip to content

Commit

Permalink
update shouldRunTurboDevTest
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Jun 23, 2023
1 parent c198b58 commit d4dd064
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions test/lib/turbo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let loggedTurbopack = false

/**
* Utility function to determine if a given test case needs to run with --turbo.
*
Expand All @@ -12,36 +14,13 @@ export function shouldRunTurboDevTest(): boolean {
return false
}

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) {
console.log(
`Running tests with --turbo via custom environment variable __INTERNAL_NEXT_DEV_TEST_TURBO_DEV`
)
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 (isMatch) {
console.log(
`Running tests with --turbo via custom environment variable __INTERNAL_NEXT_DEV_TEST_TURBO_GLOB_MATCH`
const shouldRunTurboDev = !!process.env.TURBOPACK
if (shouldRunTurboDev && !loggedTurbopack) {
require('console').log(
`Running tests with turbopack because environment variable TURBOPACK is set`
)
loggedTurbopack = true
}

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

0 comments on commit d4dd064

Please sign in to comment.