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

improve "preset not found" error message #6863

Merged
merged 2 commits into from Aug 18, 2018

Conversation

ranyitz
Copy link
Contributor

@ranyitz ranyitz commented Aug 18, 2018

Summary

After the discussion on #6538

This PR adds a descriptive error message for a case when preset module exists but doesn't have jest-preset.js or jest-preset.json files at the root

Test plan

Add a test case for it in normalize.test.js

@codecov-io
Copy link

codecov-io commented Aug 18, 2018

Codecov Report

Merging #6863 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6863      +/-   ##
==========================================
+ Coverage   66.97%   66.98%   +<.01%     
==========================================
  Files         250      250              
  Lines       10355    10358       +3     
  Branches        3        3              
==========================================
+ Hits         6935     6938       +3     
  Misses       3419     3419              
  Partials        1        1
Impacted Files Coverage Δ
packages/jest-config/src/normalize.js 91.43% <100%> (+0.1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21e35cc...a239f83. Read the comment docs.

@SimenB
Copy link
Member

SimenB commented Aug 18, 2018

Mind rebasing? :)

… doesn't have 'jest-preset.js' or 'jest-preset.json' files at the root
@kristianmandrup
Copy link

kristianmandrup commented Nov 22, 2018

I'm still having major issues trying to use the default preset

$ cat ./node_modules/ts-jest/jest-preset.js 
module.exports = require('./presets/default/jest-preset')

My jest.config.js in same directory

module.exports = {
  preset: './node_modules/ts-jest/jest-preset.js',
  testEnvironment: 'node'
};

Tried this before, generated as per config:init option

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node'
};
$ jest
Validation Error:

  Preset ts-jest not found.

But it is right there

$ cat ./node_modules/ts-jest/presets/default/jest-preset.js 
module.exports = require('..').defaults

Note: Created my project via typescript-starter and tried to switch from ava to jest but have not been able to just yet. Config nightmare still!!

My package dependencies

"dependencies": {
    "sha.js": "^2.4.11",
    "@types/jest": "^23.3.9" 
  },
  "devDependencies": {
    "codecov": "^3.1.0",
    "cz-conventional-changelog": "^2.1.0",
    "gh-pages": "^2.0.0",
    "npm-run-all": "^4.1.3",
    "nyc": "^13.0.1",
    "opn-cli": "^3.1.0",
    "prettier": "^1.14.3",
    "standard-version": "^4.4.0",
    "trash-cli": "^1.4.0",
    "ts-jest": "^23.10.5",
    "tslint": "^5.11.0",
    "tslint-config-prettier": "^1.15.0",
    "tslint-immutable": "^4.7.0",
    "typedoc": "^0.13.0",
    "typescript": "^3.0.3"
  },
 

Thanks

@kristianmandrup
Copy link

Would be helpful if the error message also returned the absolute path of the require so as to make it a bit easier to debug. Thanks

@kristianmandrup kristianmandrup mentioned this pull request Nov 22, 2018
@kristianmandrup
Copy link

Finally got it working, using a hardcoded config.

module.exports = {
  "roots": [
    "<rootDir>/src"
  ],
  "transform": {
    "^.+\\.tsx?$": "ts-jest"
  },
  "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
  "moduleFileExtensions": [
    "ts",
    "tsx",
    "js",
    "jsx",
    "json",
    "node"
  ],
}

@SimenB
Copy link
Member

SimenB commented Nov 23, 2018

It worked for me (at least using yarn).

$ npx typescript-starter # chose hello as name, using yarn and a node project
$ cd hello
$ yarn add -D jest ts-jest @types/jest
$ yarn ts-jest config:init
$ yarn jest
Test Suites: 3 failed, 3 total
Tests:       0 total
Snapshots:   0 total
Time:        2.787s
Ran all test suites.

Tests failed with either being unable to find ava or missing type annotations on the t callback, both expected. Can run jest-codemods to transform the tests.

@kristianmandrup can you provide a reproduction?

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants