Skip to content

Commit

Permalink
emit "jasmineDone" event after tests are complete (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbblanchet authored and sindresorhus committed Jun 18, 2016
1 parent 2c54576 commit 26cb78a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ module.exports = function (opts) {

cb(null, file);
}, function (cb) {
var self = this;

try {
if (jasmine.helperFiles) {
jasmine.helperFiles.forEach(function (helper) {
Expand All @@ -81,7 +83,14 @@ module.exports = function (opts) {
deleteRequireCache(modId);
});
}
jasmine.addReporter(new SilentReporter(cb, errorOnFail));
jasmine.addReporter(new SilentReporter(function (error) {
if (error) {
cb(error);
} else {
self.emit('jasmineDone');
cb();
}
}, errorOnFail));
jasmine.execute();
} catch (err) {
cb(new gutil.PluginError('gulp-jasmine', err, {showStack: true}));
Expand Down
11 changes: 8 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gulp-jasmine [![Build Status](https://travis-ci.org/sindresorhus/gulp-jasmine.svg?branch=master)](https://travis-ci.org/sindresorhus/gulp-jasmine)

> Run [Jasmine 2](http://jasmine.github.io/2.1/introduction.html) tests in Node.js
> Run [Jasmine 2](http://jasmine.github.io/2.4/introduction.html) tests in Node.js
*Issues with the output should be reported on the Jasmine [issue tracker](https://github.com/jasmine/jasmine/issues).*

Expand Down Expand Up @@ -65,7 +65,7 @@ gulp.task('default', () =>
);
```

[Creating your own reporter.](http://jasmine.github.io/2.1/custom_reporter.html)
[Creating your own reporter.](http://jasmine.github.io/2.4/custom_reporter.html)

##### timeout

Expand All @@ -85,8 +85,13 @@ Stops the stream on failed tests.

Type: `object`

Passes the config to Jasmine's [loadConfig](http://jasmine.github.io/2.3/node.html#section-Load_configuration_from_a_file_or_from_an_object.) method.
Passes the config to Jasmine's [loadConfig](http://jasmine.github.io/2.4/node.html#section-Load_configuration_from_a_file_or_from_an_object.) method.

#### events

##### jasmineDone

Emitted after all tests have been completed. For a discussion about why `jasmineDone` and not `end` nor `finish`, see [pull request #71](https://github.com/sindresorhus/gulp-jasmine/pull/71).

## FAQ

Expand Down
10 changes: 5 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ function jasmine(file, options) {
output += str;
};

stream.on('data', () => {});

stream.on('error', reject);

stream.on('end', () => {
stream.on('jasmineDone', () => {
resolve(output);
});

Expand Down Expand Up @@ -64,11 +62,13 @@ test.cb('run the test only once even if called in succession', t => {
}, cb => {
process.stdout.write = out;
t.is(output.match(/should pass: passed/g).length, 1);
t.end();
cb();
t.end();
});

process.stdout.write = str => output += str;
process.stdout.write = str => {
output += str;
};
stream.pipe(reader);

stream.write(new gutil.File({
Expand Down

0 comments on commit 26cb78a

Please sign in to comment.