Skip to content

Commit aa5a4bc

Browse files
committed
fix: also detect imported jest
1 parent 016db3f commit aa5a4bc

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

bundler/bundle.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,17 @@ export const build = async (...files) => {
245245

246246
// copy of loader/jest
247247
input.push(`await (await import(${stringify(resolveSrc('jest.setup.js'))})).setupJest();`)
248-
249-
const ignoreFrom = /\/test\/src\/(jest(\.(mock|snapshot))?\.js|engine\.pure\.cjs|expect\.cjs)$/u // rechecked to not use those apis if no outside usage
250-
specificLoadPipeline.push(async (source, filepath) => {
251-
if (ignoreFrom.test(filepath.replaceAll('\\', '/'))) return source
252-
haveJestAPIs.expect ||= /(^|[^#])\bexpect([(.]|$)/mu.test(source)
253-
haveJestAPIs.exodus ||= /jest\.exodus/u.test(source)
254-
return source
255-
})
256248
}
257249

250+
const ignoreFrom = /\/test\/src\/(jest(\.(mock|snapshot))?\.js|engine\.pure\.cjs|expect\.cjs)$/u // rechecked to not use those apis if no outside usage
251+
specificLoadPipeline.push(async (source, filepath) => {
252+
if (ignoreFrom.test(filepath.replaceAll('\\', '/'))) return source
253+
if (!options.jest && !/@(exodus\/test\/jest|jest\/globals)/u.test(source)) return source
254+
haveJestAPIs.expect ||= /(^|[^#])\bexpect([(.]|$)/mu.test(source)
255+
haveJestAPIs.exodus ||= /jest\.exodus/u.test(source)
256+
return source
257+
})
258+
258259
for (const file of files) importFile(file)
259260

260261
const filename = files.length === 1 ? `${files[0]}-${uuid().slice(0, 8)}` : `bundle-${uuid()}`

0 commit comments

Comments
 (0)