jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.23k stars 6.46k forks source link

top level `transform` is not available in `projects` #11411

Open JounQin opened 3 years ago

JounQin commented 3 years ago

๐Ÿ› Bug Report

As title.

To Reproduce

Steps to reproduce the behavior:

https://github.com/markuplint/markuplint/blob/main/package.json#L62

move the two transform options into top level

test cases will be unable to run any more.

Expected behavior

No error

Link to repl or repo (highly encouraged)

As above.

envinfo

  System:
    OS: macOS 11.3.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 12.22.1 - ~/.nvm/versions/node/v12.22.1/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.12 - ~/.nvm/versions/node/v12.22.1/bin/npm
  npmPackages:
    jest: ^26.6.3 => 26.6.3
ahnpnl commented 3 years ago

Seem like projects doesnโ€™t inherit from top level config, not sure if other config options have the same behavior too, probably yes.

ahnpnl commented 3 years ago

probably Jest maintainers can tell if projects can inherit root config options.

igorpupkinable commented 2 years ago

probably Jest maintainers can tell if projects can inherit root config options.

Unfortunately it does not. I ended up duplicating everything twice for my unit and integration tests setup. https://github.com/facebook/jest/issues/10991#issuecomment-1137699168

The only two options I could find working are

cortexcompiler commented 2 years ago

This is somewhat confusing to me, some baffling behavior:

I am finding to have this make sense I need to share common config (leveraging an import and spread operator or maybe this: https://github.com/facebook/jest/issues/10991#issuecomment-1185427440) between the root jest config and the sub-projects, so that I can run jest from the root or the sub-projects and have the same behavior. The main benefit I can see right now from using jest projects instead of something like npm workpaces and npm run test --workspaces=true is the combination of the coverage reporting.

ddbtrmatic commented 1 year ago

Either this feature is not working as intended, or the documentation is incorrect.

https://jestjs.io/docs/configuration#projects-arraystring--projectconfig

image

With a monorepo setup, I have a root jest.config.js which includes

/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
  projects: ['<rootDir>/packages/**/jest.config.js'],
  preset: 'ts-jest',
  testEnvironment: 'node',
  testPathIgnorePatterns: ['/node_modules/', '<rootDir>/dist/'],
};

Each package contains a jest.config.js with these contents.

/** @type {import('jest').Config} */
module.exports = {
  displayName: 'my-package',
  preset: 'ts-jest',
  testEnvironment: 'node'
};

However, testPathIgnorePatterns is not being copied into the child context for each project, and files in /dist are read by jest. If I add testPathIgnorePatterns to the child jest.config.js, then the files are properly ignored.

github-actions[bot] commented 9 months ago

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

igorpupkinable commented 9 months ago

Bump