Giter Site home page Giter Site logo

add --watch option about jasmine-npm HOT 19 CLOSED

geddski avatar geddski commented on August 17, 2024 2
add --watch option

from jasmine-npm.

Comments (19)

 avatar commented on August 17, 2024 63

@slackersoft

This allows more flexibility for people to pick the watcher library that works best for them

Why there is the following statement on the Jasmine Docs:

Comes out of the box with everything you need to test your code.

Re-running tests is also a purpose of most of the existing tasks runners.
Take a look at http://mochajs.org as example.

from jasmine-npm.

slackersoft avatar slackersoft commented on August 17, 2024 24

At this point, I think it makes more sense to leave the code to do the watching of your specs and production code to one of the many external libraries that are built specifically for that. This allows more flexibility for people to pick the watcher library that works best for them, and to update or change it without having to wait for Jasmine to release a new version. It also won't (as @Izhaki says) cause the Jasmine team to have to deal with or troubleshoot any issues related to the watching not working correctly.

Thanks for all the input. Closing this. Thanks for using Jasmine!

from jasmine-npm.

Isaddo avatar Isaddo commented on August 17, 2024 19

@danmartinez101 if you install nodemon and jasmine globally

npm install -g nodemon
npm install -g jasmine

you can just run nodemon --exec jasmine in command line.

from jasmine-npm.

hendrauzia avatar hendrauzia commented on August 17, 2024 3

It can be tricky to be implemented if someone is using babel-node to run their jasmine node tests. I have to use the following code in order to run jasmine test files using babel-node automatically on any changes to test or code:

./node_modules/nodemon/bin/nodemon.js -w spec/lib -w lib ./node_modules/babel-cli/bin/babel-node.js ./node_modules/jasmine/bin/jasmine.js --random=true

The good thing is, it can be put as an npm script as follows:

// package.json
"scripts": {
  "watch": "./node_modules/nodemon/bin/nodemon.js -w spec/lib -w lib ./node_modules/babel-cli/bin/babel-node.js ./node_modules/jasmine/bin/jasmine.js --random=true"
}

from jasmine-npm.

Izhaki avatar Izhaki commented on August 17, 2024 2

I'm going against the stream and would argue jasmine shouldn't support a watch function.

To begin with, I think only very light projects will need a watch on jasmine only. Many projects involve more than one watch.

Then, adding watch to jasmine means adding complexity and maintenance overhead (even if the implementation simply delegates the job to another module).

The task of watching files is not a trivial one - this repository will start seeing issues related to watch not working on Windows, double triggering, no triggering and so forth that have nothing to do with jasmine.

Finally, and most importantly, recall the separation of concerns principle. Ideally jasmine should change for its prime purpose only - running tests.

Don't quite see the issue with this using nodemon or gulp or grunt or:

  "scripts": {
    "watch:specs": "chokidar -p 'src/**/*.spec.ts' -c 'npm run test'",
    "test": "./jasmine.js"
  }

from jasmine-npm.

champi-dev avatar champi-dev commented on August 17, 2024 2

This works for me:

{
    "test": "jasmine",
    "test:watch": "nodemon -e js --exec 'npm run test'"
}

from jasmine-npm.

 avatar commented on August 17, 2024 1

I have found that using nodemon is great for this. Alternatives include supervisor and forever, but nodemon has been the best for me.

It might be worthwhile to look into one of these tools that already handle restarting processes on various events, including filesystem changes.

In my experience, installing jasmine as a local dev dependency and then configuring the npm test command as to run jasmine with nodemon works well.

 npm install --save-dev jasmine nodemon
 ./node_modules/.bin/nodemon ./node_modules/.bin/jasmine 

from jasmine-npm.

amavisca avatar amavisca commented on August 17, 2024

Can you describe what feature you're interested in a bit more? Is it rerunning your tests every time a file has changed?

from jasmine-npm.

geddski avatar geddski commented on August 17, 2024

Yep! Anytime a test or a src file has changed, should be configurable probably.

from jasmine-npm.

amavisca avatar amavisca commented on August 17, 2024

I was originally doubting the usefulness of this feature, but I played around with something similar and it's not a bad idea. I'd be happy to take a look at a pull request for this.

from jasmine-npm.

geddski avatar geddski commented on August 17, 2024

yeah I found it super useful in Mocha and jasmine-node.

from jasmine-npm.

geddski avatar geddski commented on August 17, 2024

This is such a common feature in a test runner, shouldn't have to combine with external tools to mimic it.

It's also incredibly easy to implement using the gaze node lib:

gaze('**/*', function(err, watcher) {
    this.on('all', function(event, filepath) {
        // rerun jasmine
    });
});

I can work up a PR with this if you're interested.

from jasmine-npm.

amavisca avatar amavisca commented on August 17, 2024

@geddski I'd still be happy to see a PR on this!

from jasmine-npm.

geddski avatar geddski commented on August 17, 2024

@amavisca you got it

from jasmine-npm.

slackersoft avatar slackersoft commented on August 17, 2024

Because jasmine-npm uses require to load your spec file, which probably also use require to load the system under test, I think it makes the most sense for a jasmine --watch command to fork a child process that will get its own require cache so it will always run with the current code.

from jasmine-npm.

 avatar commented on August 17, 2024

@Isaddo Yea, that is more concise for the most common scenario. I probably should have use that up above... Personally, I like to refrain from installing global cli packages because I often need to use different versions of jasmine, etc for different project concurrently. It may have changed since the last time I tried, but I found that a global install would override a local install so I had to go with the longer commands.

from jasmine-npm.

sabrehagen avatar sabrehagen commented on August 17, 2024

nodemon --exec jasmine is working for me. However, would still be nice to have this as part of jasmine.

from jasmine-npm.

slackersoft avatar slackersoft commented on August 17, 2024

Given how easy it is to accomplish this without any changes to jasmine-npm itself, we would prefer to spend our limited development time working on other features. We'd be happy to review a pull request that implements it.

from jasmine-npm.

jameswilddev avatar jameswilddev commented on August 17, 2024

I'd like to see this too. Some of the other Jasmine test runners implement this (but are missing other features) and seem to get better performance when re-running tests. (presumably some kind of caching going on)

from jasmine-npm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.