-
-
Notifications
You must be signed in to change notification settings - Fork 20
Description
rules_jest/jest/private/jest_config_template.mjs
Lines 43 to 54 in 7d4a398
function _hasReporter(config, name) { | |
if (!config.reporters) { | |
config.reporters = []; | |
} | |
for (const r of config.reporters) { | |
if (Array.isArray(r)) { | |
return r.length > 0 && r[0] == name; | |
} else { | |
return r == name; | |
} | |
} | |
} |
This logic checks if the reporters needed are in the reporter array already, and if not adds it. However, you can have a reporter in the reporters array that is defined like this:
import { createRequire } from 'node:module'
import path from 'path'
import { fileURLToPath } from 'url'
/**
* NOTE(david.aghassi) - ESM doesn't have the concept
* of `__dirname` or `__filename` global variables like commonjs
* This logic allows us to use that older syntax
* while leveraging the built-ins provided by ESM
*/
const __esm_filename = fileURLToPath(import.meta.url)
const __esm_dirname = path.dirname(__esm_filename)
const __esm_require = createRequire(import.meta.url)
const config = {
reporters: ['default'].concat(
['jest-junit'].map(module => __esm_require.resolve(module))
)
}
In this case, you are providing jest the reporter through an abolute path resolved by node. This will fail the name check because it won't match identically. This case matters for me because we centralize some of our jest infra so that consuming teams don't need to define it again and again.
Now, one could argue the most effective way to solve this is to globally declare jest-junit
in your pnpm workspace, but I'm trying to avoid having global definitions when possible.
It would be ideal if this logic supported full path resolves so it doesn't try to inject jest-junit twice and fail due to module resolution problems