jasmine / jasmine-npm

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

globs in helpers containing test cases run when excluded by spec_files #164

Closed Myrdden closed 3 years ago

Myrdden commented 3 years ago

So, here's a dummy setup:

spec/
  should_run.js
  include/
    should_also_run.js
  exclude/
    should_not_run.js

So I'm trying to exclude exclude/, but nothing of the following I've tried has worked.

[ "**/*.js", "!exclude/**" ]
[ "**/*.js" "!exclude/**/*" ]
[ "**/*.js", "!exclude/**/*.*" ]
[ "!exclude/**" ]

How do I exclude specific directory(s) and run everything else?

Myrdden commented 3 years ago

Right so my actual goal was to have it run any js file in spec whilst excluding helpers/ and evidently if there's a test condition in helpers/ it will get run regardless of what spec_files says so I suppose that solves my problem... I don't know if this is a bug per say or I'm just using the app wrong.

sgravrock commented 3 years ago

I'm not sure I fully understand your situation, but I think it's something like this:

Is that right? If so, the behavior you're seeing is expected and not a bug. Calling it during startup creates a test, regardless of what file it was called from. If you don't want the helper file to be loaded at all, make sure that none of the globs in jasmine.json match it. If you want it to load but don't want it to create tests, remove the calls to describe, it, etc.

If I've misunderstood the situation, please provide more information. A minimal, working example including complete copies of jasmine.json and the helper file, along with their paths, would help a lot.

slackersoft commented 3 years ago

Jasmine considers helper files as separate from spec files. The main reason the helper files are expected to live within the spec_files folder is to keep them separate from production code. Anything that matches the helpers globs (with exclusions, etc.) will always be loaded for any Jasmine execution. The general recommendation is that any calls to describe and it should be only in spec files.

Myrdden commented 3 years ago

Fair enough, will do. Thanks!