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

test-main.js in base directory is not watched #521

Closed
jamestalmage opened this issue Apr 27, 2013 · 9 comments
Closed

test-main.js in base directory is not watched #521

jamestalmage opened this issue Apr 27, 2013 · 9 comments

Comments

@jamestalmage
Copy link
Contributor

Followed the Require.js example on the site, with the exception of putting test-main.js in the root directory of the project.

karma.conf.js includes it as follows

   {pattern:'test-main.js', watched:true, included:true,served:true}

Tests will run correctly - but changes to test-main.js to not trigger a test run.

Moving the file to test/test-main.js solves the issue. Tests rerun every time the file is changed.

I tried other included:true files in the base directory (i.e. not the require.js config file), and they worked just fine. It does not appear to be related to it being an included file.

I also changed the file name to test-main-file.js. That did not solve the issue. It does not appear to be any sort of name collision.

Once, while renaming the file I did have karma still running, and it logged a notice that the file went missing.

With logLevel = LOG_DEBUG no log events are fired simply by changing the contents of test-main.js and saving.

@vojtajina
Copy link
Contributor

Can you share your full karma.conf.js ? You probably have some other pattern before the test-main.js, that matches the file and is not watched.

@jamestalmage
Copy link
Contributor Author

How about I just do this: https://github.com/jamestalmage/karma-issue-521

@jamestalmage
Copy link
Contributor Author

Updated the repo with clearer instructions to reproduce

@vojtajina
Copy link
Contributor

Woow, you are right, that was actually a bug! Thanks for very nice report, it was super easy to reproduce and debug with your example @jamestalmage !

It's fixed in master (and stable).

Btw, it's better, if you server only chai module, so that the glob does not have to traverse your whole node_modules:

files = [
  // ...
  {pattern: 'node_modules/chai/**/*.js', included:false, watched:false, served:true}
];

@jamestalmage
Copy link
Contributor Author

Thanks, glad to help!

As for optimizing the pattern for glob, that makes sense. Even more so with require.js as window.__karma__.files contains every file in the node_modules directory (which are then scanned again by each browser under test to find the files that match my test RegEx). Even your example is somewhat inefficient, it matches 27 files when only 1 is needed (node_modules/chai/chai.js). Obviously, that is easy enough to fix with a more specific pattern, but as my dependency list grows, tracking down the most efficient pattern for each dependency might get cumbersome. In addition, that path information is kinda getting duplicated in test-main.js (might be unavoidable, but entering it twice feels wrong).

Is there room for an additional file pattern option (maybe indexed) that could be set to false to tell karma not to include it in the window.__karma__.files array, so browsers are not scanning all those files to find tests?

If the indexed option were added, you could do some further optimizations, for 'served-only' files. In this case, don't build a glob against the pattern, defer processing it until a matching request is made from the browser. By served-only I mean included:false, watched:false, indexed:false, served:true.

Maybe I am making things too difficult and we only need a simpler servDirs config option completely separate from files, that basically allows you to list directories that will be served in their entirety (not included / watched / etc):

files = [
/// files that you want included and/or watched for changes and/or might be tests
];

servedDirs = [
'images',
'node_modules', 
'bower_components'  
];

@vojtajina
Copy link
Contributor

The __karma__.files IS a map of all served files. I don't see reasons for adding "indexed". Rather use files and exclude to define your deps as explicitly as possible.

@jamestalmage
Copy link
Contributor Author

@vojtajina I'm a bit confused as to how to get the updated version. I've tried all the following:

npm install -g karma
npm install karma
sudo npm install -g karma
sudo npm install karma

tried npm cache clear before each, as well as repeating with karma@canary.

I am obviously missing something.

@vojtajina
Copy link
Contributor

@jamestalmage sorry, you are not missing anything, I'm just stupid - I didn't push any release to npm since this change. Sorry I was very busy last month and didn't have any time for Karma. I will do it soon.

@vojtajina
Copy link
Contributor

@jamestalmage it's pushed in NPM, please update...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants