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

Nx does not recognize existing jest.preset files if using .cjs or .mjs #20449

Closed
1 of 4 tasks
kevintyj opened this issue Nov 28, 2023 · 1 comment · Fixed by #23437
Closed
1 of 4 tasks

Nx does not recognize existing jest.preset files if using .cjs or .mjs #20449

kevintyj opened this issue Nov 28, 2023 · 1 comment · Fixed by #23437
Assignees
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug

Comments

@kevintyj
Copy link

kevintyj commented Nov 28, 2023

Current Behavior

Using NX within an ESM based project, renaming jest.preset.js to jest.preset.cjs to add support for the jest preset file in cjs form.
Every time a NX generate command is ran ie: @nx/angular:library, nx does not recognize the existing jest.preset.cjs file and generates a new jest.preset.js file.
With every library creation, the generated jest.preset.js has to be deleted from project root and have to modify the generated jest.config.ts file within the new library with the correct preset path to jest preset

Expected Behavior

Recognize all accepted jest.preset file extensions jest-preset.json, jest-preset.js, jest-preset.cjs or jest-preset.mjs (https://jestjs.io/docs/configuration) from project root.

GitHub Repo

No response

Steps to Reproduce

  1. Create a new NX angular monorepo
  2. Change the name of jest.preset.js to jest.preset.cjs
  3. Generate a new angular library using NX

Nx Report

   Node   : 21.1.0
   OS     : darwin-arm64
   pnpm   : 8.9.2

   nx (global)        : 17.1.2
   nx                 : 17.1.3
   @nx/js             : 17.1.3
   @nx/jest           : 17.1.3
   @nx/eslint         : 17.1.3
   @nx/workspace      : 17.1.3
   @nx/angular        : 17.1.3
   @nx/devkit         : 17.1.3
   @nx/esbuild        : 17.1.3
   @nx/eslint-plugin  : 17.1.3
   @nx/express        : 17.1.3
   @nx/node           : 17.1.3
   @nx/playwright     : 17.1.3
   typescript         : 5.2.2

Failure Logs

No response

Package Manager Version

pnpm 8.9.2

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

Tried editing the jest config file as shown below to see if NX recognizes the changed file. The config file has no effect on nx generate behavior and the issue is still reproduced.

import { getJestProjects } from '@nx/jest';

export default {
    projects: [
        ...getJestProjects(),
        '<rootDir>/jest.preset.cjs',
    ],
};
@AgentEnder AgentEnder added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Dec 1, 2023
leosvelperez added a commit that referenced this issue May 17, 2024
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #20449
FrozenPandaz pushed a commit that referenced this issue May 21, 2024
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #20449

(cherry picked from commit 217a349)
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants