'How to change default files matches of unit test in vue-cli 3

I'm using vue-cli 3.0 and created project with manual features selecting unit test(mocha + chai). Default files matches are: any files in tests/unit that end in .spec.(ts|js). Is there any way to change target directory and files pattern?

I want to change the target directory from tests/unit to root directory where the package.json file is. But I cannot find how to change target directory.

And I tried this to change file pattern. But it doesn't work.

"scripts": {
    "test:unit": "vue-cli-service test:unit --glob '*.test.js'"
}

I read this also: https://github.com/vuejs/vue-cli/issues/1245. I need what @iamceege said exactly. Should I set test environment by myself without default setting?



Solution 1:[1]

package.json

"scripts": {
   ...,
   "test": "vue-cli-service test:unit --watch --recursive 'src/**/*_test.ts'",
   ...
},

Official documentation:

Unit test plugin parameters (mocha)

Arguments of the webpack (mocha)

Solution 2:[2]

try without the single quotes around the blob

"scripts": {
    "test:unit": "vue-cli-service test:unit --glob *.test.js"
}

Solution 3:[3]

In your jest.config.js file you can define a testMatch variable. Full options here.

Since you want the root directory, you could try something like:

// inside jest.config.js
    testMatch: [
      '*.test.js']

Note you can chain multiple selectors in the array.

Solution 4:[4]

try with this code ,work for me

yarn test:unit --  --runTestsByPath tests/unit/convert-time-frame.spec.js 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jack
Solution 2 Brent
Solution 3 Linx8
Solution 4 Qasem