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

config:migrate results in error message #756

Closed
Vinnl opened this issue Sep 24, 2018 · 3 comments · Fixed by #757
Closed

config:migrate results in error message #756

Vinnl opened this issue Sep 24, 2018 · 3 comments · Fixed by #757

Comments

@Vinnl
Copy link

Vinnl commented Sep 24, 2018

Issue :

When I ran with an updated ts-jest, I received a notification that my configuration was outdated, and that I could run ts-jest config:migrate to migrate it. I did, but unfortunately, the migration resulted in Jest mentioning the following configuration error:

Configuration options testMatch and testRegex cannot be used together.

Expected behavior :

Tests executing successfully, or at least the configuration still being valid.

Debug log:

Was empty.

Minimal repo :

My original configuration.
{
    "clearMocks": true,
    "transform": {
      "^.+\\.tsx?$": "ts-jest"
    },
    "testRegex": "(/lib/__tests__/.*\\.(test|spec))\\.(ts|js)$",
    "testPathIgnorePatterns": [
      "lib/__tests__/__coverage__"
    ],
    "moduleFileExtensions": [
      "ts",
      "js"
    ],
    "collectCoverage": true,
    "collectCoverageFrom": [
      "lib/**/*.{js,ts}",
      "!lib/**/*.d.ts",
      "!lib/interfaces/**"
    ],
    "coveragePathIgnorePatterns": [
      "lib/__tests__/__coverage__",
      "lib/lambda/getUploadUrl.ts"
    ],
    "coverageReporters": [
      "json",
      "lcov",
      "text",
      "text-summary"
    ],
    "coverageDirectory": "lib/__tests__/__coverage__",
    "coverageThreshold": {
      "global": {
        "branches": 100,
        "functions": 100,
        "lines": 100,
        "statements": 100
      }
    },
    "globals": {
      "ts-jest": {
        "tsConfig": "lib/tsconfig.json"
      }
    }
  }
Configuration after migration
{
    "clearMocks": true,
    "testRegex": "(/lib/__tests__/.*\\.(test|spec))\\.(ts|js)$",
    "testPathIgnorePatterns": [
      "lib/__tests__/__coverage__"
    ],
    "moduleFileExtensions": [
      "js",
      "ts"
    ],
    "collectCoverage": true,
    "collectCoverageFrom": [
      "lib/**/*.{js,ts}",
      "!lib/**/*.d.ts",
      "!lib/interfaces/**"
    ],
    "coveragePathIgnorePatterns": [
      "lib/__tests__/__coverage__",
      "lib/lambda/getUploadUrl.ts"
    ],
    "coverageReporters": [
      "json",
      "lcov",
      "text",
      "text-summary"
    ],
    "coverageDirectory": "lib/__tests__/__coverage__",
    "coverageThreshold": {
      "global": {
        "branches": 100,
        "functions": 100,
        "lines": 100,
        "statements": 100
      }
    },
    "globals": {
      "ts-jest": {
        "tsConfig": "lib/tsconfig.json"
      }
    },
    "preset": "ts-jest"
  }

The diff:

   "jest": {
     "clearMocks": true,
-    "transform": {
-      "^.+\\.tsx?$": "ts-jest"
-    },
     "testRegex": "(/lib/__tests__/.*\\.(test|spec))\\.(ts|js)$",
     "testPathIgnorePatterns": [
       "lib/__tests__/__coverage__"
     ],
     "moduleFileExtensions": [
-      "ts",
-      "js"
+      "js",
+      "ts"
     ],
     "collectCoverage": true,
     "collectCoverageFrom": [
@@ -60,9 +57,10 @@
     },
     "globals": {
       "ts-jest": {
-        "tsConfigFile": "lib/tsconfig.json"
+        "tsConfig": "lib/tsconfig.json"
       }
-    }
+    },
+    "preset": "ts-jest"
   },

As you can see, I don't use the testMatch option anyway - I suppose the preset has it somewhere? If so, the migration tool should probably do something with the existing option? Unfortunately, I couldn't transform testRegex to testMatch myself, because Jest could no longer find my tests, so I'm not sure what the solution should be.

@huafu
Copy link
Collaborator

huafu commented Sep 24, 2018

@Vinnl thanks for reporting! The ts-jest uses testMatch since jest uses this as the default method to match test files. I guess this issue should be a doc issue.

To fix this, you need to set testMatch to null as the preset can't know what's you're overriding later on. I'm going to update the issue title so that it's related to doc.

Update: This should also be mentioned in the doc when using preset.

@huafu huafu added this to the 23.10.2 milestone Sep 24, 2018
@Vinnl
Copy link
Author

Vinnl commented Sep 24, 2018

Ehm wow, that was ridiculously fast - I was still working on the formatting of the issue. But thanks, setting testMatch to null solves it! Wouldn't the solution then be to have the migration tool set it to null as well when testRegex is present?

@huafu
Copy link
Collaborator

huafu commented Sep 24, 2018

Was updating while I got your answer hehe!

@huafu huafu added the 🐛 Bug label Sep 24, 2018
huafu added a commit to huafu/ts-jest that referenced this issue Sep 24, 2018
hyochan added a commit to dooboolab-community/dooboo-native-ts that referenced this issue Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants