jasmine / jasmine-npm

A jasmine runner for node projects.
MIT License
376 stars 145 forks source link

Problem excluding files #205

Closed 3nriqu390 closed 1 year ago

3nriqu390 commented 1 year ago

I have a monorepo with multiple subprojects each one with its node modules. Jasmine is running at a global level and i want to exclude the node modules from 1 of the subprojects. The relative path from the root of the project to the subproject i want to exclude would be src/client/example-folder-1/example-folder-2/subproject/node_modules . I have this config for jasmine.

{ "spec_dir": "./src/client", "spec_files": ["/*.spec.ts"], "helpers": ["../tests/helpers/*/.js"], "stopSpecOnExpectationFailure": true, "exclude": ["node_modules/*.spec.ts"], "random": false }

It should in theory exclude every test inside the node modules of every project, but it is still running the test i dont want to run. I have this libraries installed

"jasmine": "^3.8.0", "jasmine-spec-reporter": "^7.0.0", "jasmine-ts": "^0.4.0", "@types/jasmine": "^3.8.2",

How could i exclude the files.

sgravrock commented 1 year ago

Something like this should do what you want:

{
  "spec_dir": "./src/client",
  "spec_files": [
    "**/*.spec.ts",
    "!**/node_modules/**"
  ],
  "helpers": ["../tests/helpers/**/*.js"]
} 
3nriqu390 commented 1 year ago

Something like this should do what you want:

{
  "spec_dir": "./src/client",
  "spec_files": [
    "**/*.spec.ts",
    "!**/node_modules/**"
  ],
  "helpers": ["../tests/helpers/**/*.js"]
} 

Already tried it, and also giving the route relative to the specific node modules folder with the issue. It doesn't work, the only thing i can think is that the global project and the specific project with the issue have a different node js version. Could this have an impact in the exclude??

sgravrock commented 1 year ago

the global project and the specific project with the issue have a different node js version. Could this have an impact in the exclude??

No, but that could be another problem: Jasmine runs in the version of Node that you use to invoke it. If you're fine with all your tests running in the same version of Node, the setup you're describing could work for you. But if you need tests in different subprojects to run in different versions of Node, you'll need to invoke Jasmine separately for each one. And at that point you could sidestep the exclude problem by having a separate config file for each subproject.

Most likely, the problem is that the exclude glob doesn't match the actual paths you're trying to exclude. I tried it out locally and it works for paths like src/client/example-folder-1/node_modules/foo/bar/foo.spec.ts, but maybe your paths are different in some important way.

There's not really enough for me to go on here. Something about your setup is different than what I'm doing, and I don't know what it is. But I can take another look if you provide exact working steps to reproduce or a repo containing a minimal reproducible example.

sgravrock commented 1 year ago

Closing due to inactivity. Feel free to open a new issue if you still need help and you're able to provide a reliable way for me to reproduce the problem.