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

Unable to Override .swcrc exclude Array in Jest with @swc/jest transformer #9768

Open
piotrkabacinski opened this issue Dec 1, 2024 · 0 comments
Labels

Comments

@piotrkabacinski
Copy link

piotrkabacinski commented Dec 1, 2024

Describe the bug

Hello! I stumbled upon a possible issue while trying to override default .swcrc config in Jest.

I followed the documentation and updated my jest.config.ts file:

// ...
import { readFileSync } from "fs";

const swcConfig = JSON.parse(
  readFileSync(`${__dirname}/.swcrc`, "utf-8")
) as Record<string, unknown>;

const config: Config = {
 // ...
 transform: {
    "^.+\\.(t|j)sx?$": [
      "@swc/jest",
      {
        ...swcConfig,
        exclude: [], // Attempt to override exclude
      },
    ],
  }

My goal is to override exclude array (for production build I ignore *.test.ts files).

Unofrtuenatly, when trying to run test I got:

FAIL  <path to file>.test.ts
  ● Test suite failed to run

cannot process file because it's ignored by .swcrc

Is there anything I do wrong in that case? Packages versions I use:

Input code

No response

Config

{
  "$schema": "https://swc.rs/schema.json",
  "jsc": {
    "target": "es2022",
    "baseUrl": "./",
    "paths": {
      "src/*": ["./src/*"]
    },
    "parser": {
      "syntax": "typescript",
      "tsx": false
  },
  "externalHelpers": true
  },
  "module": {
    "type": "es6"
  },
  "exclude": [".*\\.test\\.ts$", ".*\\.map$", ".*\\.d.ts", "test/"],
  "sourceMaps": false 
}

Playground link (or link to the minimal reproduction)

https://github.com/piotrkabacinski/swc_jest_config_issue

SWC Info output

No response

Expected behavior

exclude array should be overwritten by custom config in jest.config.ts

Actual behavior

No response

Version

0.2.37

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant