blitz-js / legacy-framework

MIT License
3 stars 2 forks source link

Cannot override or append to `testPathIgnorePatterns` in jest setup #11

Open ospfranco opened 2 years ago

ospfranco commented 2 years ago

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 commented 2 years ago

Hi @ospfranco, can you try modulePathIgnorePatterns?

ospfranco commented 2 years ago
Screen Shot 2022-01-03 at 21 12 38

nope, doesn't work either

ospfranco commented 2 years ago

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 commented 2 years ago

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