question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest Schematic still adds `setupFile` & `tsConfig`

See original GitHub issue

Current Behavior

When generating a project with jest it creates the correct jest.config.js with setupFilesAfterEnv & tsConfig but it adds setupFile & tsConfig to the test architect as well.

https://github.com/nrwl/nx/blob/3b8a10f073/packages/jest/src/schematics/jest-project/lib/update-workspace.ts#L18

Expected Behavior

Because setupFile & tsConfig options were removed from all test architects during the migration to Nx10 it seems unintended, that these options are still generated.

Steps to Reproduce

  • Generate Nx Workspace with an Angular app npx create-nx-workspace@latest test-jest --preset="angular" --appName="test-jest"

  • Look at the projects.test-jest.architect.test.options in the angular.json

        "test": {
          "builder": "@nrwl/jest:jest",
          "options": {
            "jestConfig": "apps/test-jest/jest.config.js",
            "tsConfig": "apps/test-jest/tsconfig.spec.json", // <-- was removed during Nx10 migration
            "passWithNoTests": true,
            "setupFile": "apps/test-jest/src/test-setup.ts" // <-- was removed during Nx10 migration
          }
        }
  • The jest.config.js contains this information as expected
module.exports = {
  name: 'test-jest',
  preset: '../../jest.config.js',
  setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'], // <-- `projects.test-jest.architect.test.options.setupFile`
  globals: {
    'ts-jest': {
      tsConfig: '<rootDir>/tsconfig.spec.json', // <-- `projects.test-jest.architect.test.options.tsConfig`
      stringifyContentPathRegex: '\\.(html|svg)$',
      astTransformers: [
        'jest-preset-angular/build/InlineFilesTransformer',
        'jest-preset-angular/build/StripStylesTransformer',
      ],
    },
  },
  coverageDirectory: '../../coverage/apps/test-jest',
  snapshotSerializers: [
    'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js',
    'jest-preset-angular/build/AngularSnapshotSerializer.js',
    'jest-preset-angular/build/HTMLCommentSerializer.js',
  ],
};

Environment

  nx : Not Found
  @nrwl/angular : 10.0.11
  @nrwl/cli : 10.0.11
  @nrwl/cypress : 10.0.11
  @nrwl/eslint-plugin-nx : Not Found
  @nrwl/express : Not Found
  @nrwl/jest : 10.0.11
  @nrwl/linter : Not Found
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : Not Found
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 10.0.11
  @nrwl/web : Not Found
  @nrwl/workspace : 10.0.11
  typescript : 3.9.7

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Cammisulicommented, Aug 25, 2020

Yes, I think a migration should be added again. It’ll most likely be the same set up as the original migration (without the jest config modifications 😄 )

0reactions
twittwercommented, Aug 24, 2020

@ZachJW34 I would have started this afternoon, but you can take it - thx 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Jest
Configuring Jest. The Jest philosophy is to work great by default, but sometimes you just need more configuration power.
Read more >
Jest + Typescript + Absolute paths (baseUrl) gives error
I was struggling with the same problem and actually it turns out that a simple change seems to do the trick.
Read more >
Migrating an Nx Workspace From Karma to Jest
In this article I want to describe how we can migrate an nx workspace with an angular application from karma to use jest,...
Read more >
ESM Support | jest-preset-angular - GitHub Pages
mjs to add to Jest setup file to ensure that Jest can set up test environment properly. import 'jest-preset-angular/setup-jest.mjs'; ...
Read more >
nrwl-nx/community - Gitter
Now I can simply yarn add @my-org/themes wherever I like to use it, ... Angular: 8.3.20 @nrwl/schematics: 8.10.0 @nrwl/jest: 9.0.4 jest: 25.1.0.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found