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

Cannot override or append to testPathIgnorePatterns in jest setup #11

Open
ospfranco opened this issue Dec 26, 2021 · 4 comments
Open

Comments

@ospfranco
Copy link

What is the problem?

I have an internal module for deploying some AWS units, this internally have their own tests, when running yarn test with blitzjs, the tests inside the aws folder are picked up, which is undersirable (since they have their own compilation target/config)

I've tried setting testPathIgnorePatterns in the jest.config.ts file but it doesn't seem to be working, no matter what I do my tests are still picked up, could this be a problem with the blitz jest preset?

Paste all your error logs here:

$ yarn test
yarn run v1.22.17
$ jest
Determining test suites to run...Loaded env from /Users/osp/Developer/productlane/.env.test.local
Loaded env from /Users/osp/Developer/productlane/.env
 PASS   SERVER  app/projects/queries/getProjects.test.ts
  #getProjects
    ✓ get (13 ms)

 PASS   CLIENT  app/pages/index.test.tsx
  ✓ Renders home page with Sign up button (35 ms)

 FAIL   CLIENT  aws/test/aws.test.ts
  ● Test suite failed to run

    Your test suite must contain at least one test.

      at onResult (node_modules/@jest/core/build/TestScheduler.js:175:18)
      at node_modules/@jest/core/build/TestScheduler.js:304:17
      at node_modules/emittery/index.js:260:13
          at Array.map (<anonymous>)
      at Emittery.Typed.emit (node_modules/emittery/index.js:258:23)

Test Suites: 1 failed, 2 passed, 3 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        2.859 s, estimated 3 s
Ran all test suites in 2 projects.
error Command failed with exit code 1.

Paste all relevant code snippets here:

import type { Config } from "@jest/types"

const config: Config.InitialOptions = {
  preset: "blitz",
  testPathIgnorePatterns: ["<rootDir>/aws/"],
  clearMocks: true,
  verbose: true,
}

export default config

What are detailed steps to reproduce this?

  1. Create a subfolder with tests
  2. Try to ignore the subfolder in the jest config
  3. Jest should skip the specified folder

Run blitz -v and paste the output here:

$ blitz -v                               
Loaded env from /Users/osp/Developer/productlane/.env.local
Loaded env from /Users/osp/Developer/productlane/.env
macOS Monterey | darwin-arm64 | Node: v16.12.0

blitz: 0.44.0 (global)
blitz: 0.44.4 (local)

  Package manager: yarn 
  System:
    OS: macOS 12.1
    CPU: (8) arm64 Apple M1
    Memory: 216.25 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.12.0 - ~/.nvm/versions/node/v16.12.0/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.12.0/bin/yarn
    npm: 8.1.0 - ~/.nvm/versions/node/v16.12.0/bin/npm
    Watchman: 2021.11.15.00 - /opt/homebrew/bin/watchman
  npmPackages:
    @prisma/client: 3.6.0 => 3.6.0 
    blitz: 0.44.4 => 0.44.4 
    prisma: 3.6.0 => 3.6.0 
    react: 18.0.0-beta-149b420f6-20211119 => 18.0.0-beta-149b420f6-20211119 
    react-dom: 18.0.0-alpha-5ca4b0433-20211020 => 18.0.0-alpha-5ca4b0433-20211020 
    typescript: ~4.5 => 4.5.2 

Please include below any other applicable logs and screenshots that show your problem:

Screen Shot 2021-12-26 at 10 58 24

@beerose
Copy link
Contributor

beerose commented Jan 3, 2022

Hi @ospfranco, can you try modulePathIgnorePatterns?

@ospfranco
Copy link
Author

Screen Shot 2022-01-03 at 21 12 38

nope, doesn't work either

@ospfranco
Copy link
Author

Any idea on how to mitigate this in the meantime? before it was just annoying, now I'm integrating playwright tests and now it's just confusing because jest tries to run those as well

@beerose
Copy link
Contributor

beerose commented Jan 10, 2022

Ok, so Blitz's jest-preset has hardcoded ignored paths: https://github.com/blitz-js/blitz/blob/canary/packages/blitz/jest-preset.js#L28, so that issue is there. However, I managed to workaround it with the following code:

// jest.config.ts
import type { Config } from "@jest/types"
const blitzPreset = require("blitz/jest-preset")

const config: Config.InitialOptions = {
  ...blitzPreset,
  projects: blitzPreset.projects.map(p => ({
    ...p,
    testPathIgnorePatterns: [...p.testPathIgnorePatterns, "FOLDER_TO_IGNORE"]
  }))
}

export default config

@beerose beerose changed the title Jest testPathIgnorePatterns not working Cannot override or append to testPathIgnorePatterns in jest setup Jan 13, 2022
@dillondotzip dillondotzip transferred this issue from blitz-js/blitz Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants