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

Tests are not found out of the box #1686

Closed
lmiller1990 opened this issue Jun 27, 2018 · 22 comments · Fixed by #1756
Closed

Tests are not found out of the box #1686

lmiller1990 opened this issue Jun 27, 2018 · 22 comments · Fixed by #1756
Labels
bug needs team repro We acknowledged your report and will soon try to reproduce it priority: now scope: unit-jest

Comments

@lmiller1990
Copy link
Member

lmiller1990 commented Jun 27, 2018

Version

3.0.0-rc.3

Reproduction link

https://would-not-be-useful.com could not find a good way to do this - I think it must be related to some other setting.

Steps to reproduce

vue create test_app -> choose babel and jest

yarn unit:test
yarn run v1.7.0
$ vue-cli-service test:unit
No tests found
In /Users/lachlanmiller/javascript/vue/qiita_post
  10 files checked.
  testMatch: /Users/lachlanmiller/javascript/vue/qiita_post/(tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)) - 0 matches
  testPathIgnorePatterns: /node_modules/ - 10 matches
Pattern:  - 0 matches
 ERROR  jest exited with code 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

What is expected?

It runs HelloWorld.spec.js

What is actually happening?

It does not find the test


MacOS 10.13.2 High Sierra
Happening on another machine (not sure of the macOS version for it, but it's high sierra). I can check the version tomorrow. I tried using both npm and yarn, and jest directly.

I tried both with jest config in package.json and standalone.

Also I cannot specify either:

yarn test:unit --  --runTestsByPath tests/unit/HelloWorld.spec.js

> vue-cli-service test:unit "--runTestsByPath" "tests/unit/HelloWorld.spec.js"

No tests found
No files found in /Users/lachlanmiller/javascript/vue/qiita_post.
Make sure Jest's configuration does not exclude this directory.
To set up Jest, make sure a package.json file exists.
Jest Documentation: facebook.github.io/jest/docs/configuration.html
Files: "tests/unit/HelloWorld.spec.js"

HOWEVER git cloning a project scaffolded on another PC works somehow.

Other projects on my machine are using jest no problem. Not sure what's going on. Any ideas?

@allochi
Copy link

allochi commented Jun 27, 2018

Hi, the same happened to me on MacOS 10.13.4 High Sierra, I removed the enclosing round brackets in jest.config.js and it works. basically, this works:

testMatch: [
    "<rootDir>/tests/unit/**/*.spec.(js|jsx|ts|tsx)|<rootDir>/**/__tests__/*.(js|jsx|ts|tsx)"
]

@renyuanz
Copy link

@allochi not working neither, but I'm on Windows 10
Exactly the same problem as described as @lmiller1990

@lmiller1990
Copy link
Member Author

lmiller1990 commented Jun 28, 2018

Both my machines are 10.13.2 and confirmed the bug is the same.

@allochi thanks, that works for me. Are the other brackets necessary? If not, could they be removed (not sure if that would impact other systems).

Edit, looks like jest could be the culprit (see #1691 )

@hajarrashidi
Copy link

Allochi solution on mac works. but not in windows.

@allochi
Copy link

allochi commented Jun 28, 2018

testMatch is an array, so I guess the following should work too (it did for me):

testMatch: [
    "<rootDir>/tests/unit/**/*.spec.(js|jsx|ts|tsx)",
    "<rootDir>/**/__tests__/*.(js|jsx|ts|tsx)"
]

It runs any test in the project's /tests/unit/ directory or any test in the project as long as it's in a __tests__ directory.

@allochi
Copy link

allochi commented Jun 28, 2018

If you plan to have all your tests in /tests/unit/, just use:

testMatch: [
    "<rootDir>/tests/unit/**/*.spec.(js|jsx|ts|tsx)"
]

@hajarrashidi
Copy link

Not working /:

@Akryum Akryum added bug scope: unit-jest needs team repro We acknowledged your report and will soon try to reproduce it priority: now labels Jun 28, 2018
@rdsn
Copy link

rdsn commented Jun 29, 2018

The issue on windows seems to be caused by the fact that jest v23 uses micromatch v3.1.10, while jest v22 used micromatch v2.3.11.

let micromatch = require('micromatch');

let path = 'D:\\app\\tests\\unit\\HelloWorld.spec.js';
let glob= 'D:/app/(tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx))';

console.log(micromatch([path], glob));

// with micromatch@2.3.11 logs
// [ 'D:/app/tests/unit/HelloWorld.spec.js' ]

// with micromatch@3.1.10 logs
// []

@lmiller1990
Copy link
Member Author

I think the best solution would be to downgrade to jest 22, until the bug is addressed there.

@mildc055ee
Copy link

hello, I have same problem on windows 10, however, I can run test correctly in the following way

  • remove testMatch block
  • add transformIgnorePatterns like below
    "transformIgnorePatterns": [
      "node_modules/"
    ],

@andreydos
Copy link

andreydos commented Jul 2, 2018

On Ubuntu I have the same problem, I just add an additional path to

testMatch: [
    "<rootDir>/(tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx))",
    "<rootDir>/tests/unit/*.spec.(js|jsx|ts|tsx)"  // match test specs directly in "unit" directory  
  ]

@coldino
Copy link

coldino commented Jul 2, 2018

On Windows the listed workarounds don't seem to work.

Although not idea, I found this combination means I can run tests again:

    "moduleFileExtensions": [ "ts", "js" ],
    "testMatch": [ ]

@abbyjeet
Copy link

@mildc055ee 's solution worked for me in Windows 10

@mario-d-s
Copy link

This issue is not fixed on Windows with #1756 😞. I just re-ran vue invoke unit-jest, adjusted the regex based on what was committed, and the generated HelloWorld.spec.js is still not found...

@Akryum
Copy link
Member

Akryum commented Jul 11, 2018

@mario-d-s
Copy link

@Akryum that one does work!

By the way I've just regenerated a project with vue-cli and strangely enough, now the test just works. I don't know what's changed. My CLI version is still 3.0.0-rc.3.

@kevinhofmaenner
Copy link

@mario-d-s

I scaffolded a vue-cli 3 app about ~2 weeks ago and my jest.config.js file looked like this:

module.exports = {
  moduleFileExtensions: ["js", "jsx", "json", "vue"],
  transform: {
    "^.+\\.vue$": "vue-jest",
    ".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$":
      "jest-transform-stub",
    "^.+\\.jsx?$": "babel-jest"
  },
  moduleNameMapper: {
    "^@/(.*)$": "<rootDir>/src/$1"
  },
  snapshotSerializers: ["jest-serializer-vue"],
  testMatch: [
    "<rootDir>/(tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx))"
  ]
};

When I scaffolded a new app today, jest.config.js now looks like

module.exports = {
  moduleFileExtensions: ["js", "jsx", "json", "vue"],
  transform: {
    "^.+\\.vue$": "vue-jest",
    ".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$":
      "jest-transform-stub",
    "^.+\\.jsx?$": "babel-jest"
  },
  moduleNameMapper: {
    "^@/(.*)$": "<rootDir>/src/$1"
  },
  snapshotSerializers: ["jest-serializer-vue"],
  testMatch: [
    "**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"
  ]
};

Note the difference between the testMatch array.

@mario-d-s
Copy link

@kevinhofmaenner that is what vue-cli-plugin-unit-jest 3.0.0-rc.5 does. Can you check the version?

@kevinhofmaenner
Copy link

@mario-d-s - correct, the sample app I spun up yesterday was using 3.0.0-rc.5

@onexdata
Copy link

onexdata commented Feb 12, 2019

For people having this issue, the latest version of Jest doesn't like the <rootdir> in testMatch. This happened in Jest 23/24, so if you built your jest.config.js file in and older version of Jest, then upgraded to Jest latest, you will have this issue.

Use something like this instead:

'testMatch': [
  '**/?(*.)(spec).js?(x)',
  '**/?(*.)(test).js?(x)'
],

Breaking changes like this would be nice if Jest warned you that the devs decided to implement a breaking change, instead of just giving cryptic errors when the developer does nothing wrong.

Stuff like this makes all Jest 22 and previous source code that includes a jest.config.js file broken, for example. How is this good for the community?

@ghost
Copy link

ghost commented Dec 13, 2019

@onexdata Really it would be nice if the documentation would cover this somehow. I tried ./test/*.js, test/*.js, but only **/test/*.js worked. I wonder why processing a simple glob pattern is so hard. This should be a core feature that works flawlessly instead of a barely supported and documented thing...

edit:
Lol, I thought we are in a jest issue. :-)

@mohsenuss91
Copy link

<rootDir>/tests/unit/**/*.spec.(js|jsx|ts|tsx)|<rootDir>/**/__tests__/*.(js|jsx|ts|tsx)

@allochi I try it now I've got this :

  ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { shallowMount } from '@vue/test-utils';
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs team repro We acknowledged your report and will soon try to reproduce it priority: now scope: unit-jest
Projects
None yet
Development

Successfully merging a pull request may close this issue.