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

Jest not able to find test specs in Windows 10 #1062

Closed
nirkki opened this issue Nov 14, 2017 · 22 comments
Closed

Jest not able to find test specs in Windows 10 #1062

nirkki opened this issue Nov 14, 2017 · 22 comments

Comments

@nirkki
Copy link

nirkki commented Nov 14, 2017

Fresh project with 'vue init webpack just-testing' doesn't find the test files in Win 10
...
25 files checked.
testMatch: /tests//.js?(x),**/?(.)(spec|test).js?(x) - 1 match
testPathIgnorePatterns: \node_modules\ - 25 matches
Pattern: test/unit/specs - 0 matches

@LinusBorg
Copy link
Contributor

@eddyerburgh Got an idea?

@eddyerburgh
Copy link
Contributor

@nirkki can you try running:

npm run unit -- --no-watchman

I'm basing this off a stackoverflow answer.

@fedegar33
Copy link

Same issue on Windows 7. Tried to run npm run unit -- --no-watchman but the problem persists.

@nirkki
Copy link
Author

nirkki commented Nov 14, 2017

Didn't help here either. I also found some notes that Jest has had some issues with Windows paths containing special chars - but my project doesn't have those.
jestjs/jest#4467

@nirkki
Copy link
Author

nirkki commented Nov 14, 2017

Tried to troubleshoot this further: installing jest globally didn't make difference on 'npm run unit'
But it enabled me to run it from the command line - and here is the result

C:\test\jesting> jest --coverage
 PASS  test\unit\specs\HelloWorld.spec.js
  HelloWorld.vue
    √ should render correct contents (27ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.403s
Ran all test suites.
-----------------|----------|----------|----------|----------|----------------|
File             |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
-----------------|----------|----------|----------|----------|----------------|
All files        |        0 |        0 |        0 |        0 |                |
 src             |        0 |        0 |        0 |        0 |                |
  App.vue        |        0 |        0 |        0 |        0 |... 19,20,21,22 |
 src/components  |        0 |        0 |        0 |        0 |                |
  HelloWorld.vue |        0 |        0 |        0 |        0 |... 39,40,41,42 |
-----------------|----------|----------|----------|----------|----------------|

But if I give a path the result is the same as running npm run unit

 C:\test\jesting> jest test/unit/specs --coverage
No tests found
In C:\test\jesting
  28 files checked.
  testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 1 match
  testPathIgnorePatterns: \\node_modules\\ - 28 matches
Pattern: test/unit/specs - 0 matches
----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files |  Unknown |  Unknown |  Unknown |  Unknown |                |
----------|----------|----------|----------|----------|----------------|

@eddyerburgh
Copy link
Contributor

I'm not sure what to suggest. It looks like Jest has some long standing issues with Windows that I was unaware of.

All the issues I have looked at suggest that they won't be fixed by the maintainers any time soon 😕

@nirkki
Copy link
Author

nirkki commented Nov 15, 2017

Too bad, I'll revert back to Karma-Mocha. At least feel more like home there. Thanks for help!

@eddyerburgh
Copy link
Contributor

Sorry @nirkki . We'll probably move back to Karma and mocha as the default because of this issue

@eddyerburgh
Copy link
Contributor

eddyerburgh commented Nov 15, 2017

@nirkki Can you post the full path of your tests. Does it include parentheses, like C:\Program Files\tmp (x86)\project

I'm pretty sure it has to do with this issue — jestjs/jest#2381

@nirkki
Copy link
Author

nirkki commented Nov 15, 2017

No paranthesis in the path C:\test\jesting

@Akryum
Copy link
Contributor

Akryum commented Nov 15, 2017

Here is a working config for Windows 10:

{
  rootDir: "D:\\Mes documents\\GitHub\\livestorm-container\\livestorm-app",
  roots: ["<rootDir>/app/frontend"],
  moduleFileExtensions: [
    "coffee",
    "js",
    "json",
    "jsx",
    "ts",
    "vue",
    "sass",
    "scss",
    "styl",
    "css",
    "png",
    "svg",
    "gif",
    "jpeg",
    "jpg"
  ],
  moduleDirectories: [
    "app/frontend",
    "node_modules",
    "app/frontend",
    "app/frontend/packs",
    "app/frontend/common/js/",
    "app/frontend/common/vue",
    "app/frontend/common/vue/components",
    "app/frontend/api",
    "app/frontend/config",
    "config/locales-front",
    "public"
  ],
  moduleNameMapper: { "^@/(.*)$": "<rootDir>/app/frontend/$1" },
  transform: {
    "^.+.jsx?$": "<rootDir>/node_modules/babel-jest",
    ".*.(vue)$": "<rootDir>/node_modules/jest-vue"
  },
  mapCoverage: true,
  snapshotSerializers: ["<rootDir>/node_modules/jest-serializer-vue"],
  testPathIgnorePatterns: ["/node_modules/", "/vendors/"],
  setupFiles: ["<rootDir>/test/frontend/jest-setup"]
}

@robertmain
Copy link

robertmain commented Nov 16, 2017

Windows 10 user here chipping in. I find it works if I run npx jest but not npm run-script unit. To say I'm confused is an understatement.

Additionally, manually running the jest test/unit/specs --coverage command doesn't work. It seems to be interpreting the test/unit/specs as the pattern to search for unit test specs...which doesn't work for some reason. Remove that and it seems to at least find the test suites.

@eddyerburgh
Copy link
Contributor

@robertmain could you change the script to this:

"unit": "jest test/unit --coverage",

And see if that solves your issue

@Akryum
Copy link
Contributor

Akryum commented Nov 16, 2017

FYI, my script is "test:unit": "jest --config test/frontend/jest.config.js",

@Akryum
Copy link
Contributor

Akryum commented Nov 16, 2017

@nirkki @robertmain Could you please try with a clean project using vue init Akryum/webpack test-jest?

@nirkki
Copy link
Author

nirkki commented Nov 16, 2017

Here we go! Now the coverage report for HelloWorld looks right, but for App.vue not quite...

C:\test\jest-test> npm run unit

> jest-test@1.0.0 unit C:\test\jest-test
> jest --config test/unit/jest.conf.js --coverage

 PASS  test\unit\specs\HelloWorld.spec.js
  HelloWorld.vue
    √ should render correct contents (47ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        3.103s
Ran all test suites.
-----------------|----------|----------|----------|----------|----------------|
File             |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
-----------------|----------|----------|----------|----------|----------------|
All files        |     7.69 |        0 |    33.33 |     12.5 |                |
 src             |        0 |        0 |        0 |        0 |                |
  App.vue        |        0 |        0 |        0 |        0 |... 19,20,21,22 |
 src/components  |      100 |      100 |      100 |      100 |                |
  HelloWorld.vue |      100 |      100 |      100 |      100 |                |
-----------------|----------|----------|----------|----------|----------------|

@LinusBorg
Copy link
Contributor

but for App.vue not quite...

Ap.vue is doesn'T have any tests, insofar the 0% are correct. However he lines numbers are off, which we will have to fix in vue-jest I assume, right @eddyerburgh ?

We should also create a PR for this template to use @Akryum's config for windows compatibility.

@Akryum
Copy link
Contributor

Akryum commented Nov 16, 2017

We should also create a PR for this template to use @Akryum's config for windows compatibility.

@LinusBorg There is one. 😄

@LinusBorg
Copy link
Contributor

Awesome, thanks :)

@nirkki
Copy link
Author

nirkki commented Nov 16, 2017

@LinusBorg That's what I meant, the linenumbers. But if that's an vue-jest issue then this looks very promising!
image

@eddyerburgh
Copy link
Contributor

@nirkki @LinusBorg Yep this is a problem with vue-jest. Can you make an issue @nirkki https://github.com/eddyerburgh/vue-jest/issues?

@robertmain
Copy link

@eddyerburgh I doubt it will since that isn't where my test specs are
@Akryum See below:

 FAIL  test\e2e\specs\test.js
  ● Test suite failed to run

    Your test suite must contain at least one test.

      at node_modules/jest/node_modules/jest-cli/build/test_scheduler.js:95:22
          at Generator.next (<anonymous>)
          at Promise (<anonymous>)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

 PASS  test\unit\specs\HelloWorld.spec.js

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        10.432s
Ran all test suites.
-----------------|----------|----------|----------|----------|----------------|
File             |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
-----------------|----------|----------|----------|----------|----------------|
All files        |     7.69 |        0 |    33.33 |     12.5 |                |
 src             |        0 |        0 |        0 |        0 |                |
  App.vue        |        0 |        0 |        0 |        0 |... 19,20,21,22 |
 src/components  |      100 |      100 |      100 |      100 |                |
  HelloWorld.vue |      100 |      100 |      100 |      100 |                |
-----------------|----------|----------|----------|----------|----------------|
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-jest@1.0.0 unit: `jest --config test/unit/jest.conf.js --coverage`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test-jest@1.0.0 unit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\robert\AppData\Roaming\npm-cache\_logs\2017-11-16T15_08_14_710Z-debug.log

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

6 participants