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

jest-junit report check will incorrectly fail if the reporter is provided via require.resolve #201

Open
Aghassi opened this issue Dec 1, 2023 · 0 comments
Labels
untriaged Requires traige

Comments

@Aghassi
Copy link

Aghassi commented Dec 1, 2023

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

@github-actions github-actions bot added the untriaged Requires traige label Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged Requires traige
Projects
Status: No status
Development

No branches or pull requests

1 participant