GithubHelp home page GithubHelp logo

gulp-jasmine's Introduction

gulp-jasmine

Run Jasmine 3 tests in Node.js

Issues with the output should be reported on the Jasmine issue tracker.

Install

$ npm install --save-dev gulp-jasmine

Usage

const gulp = require('gulp');
const jasmine = require('gulp-jasmine');

exports.default = () => (
	gulp.src('spec/test.js')
		// gulp-jasmine works on filepaths so you can't have any plugins before it
		.pipe(jasmine())
);

API

jasmine(options?)

options

Type: object

verbose

Type: boolean
Default: false

Display spec names in default reporter.

includeStackTrace

Type: boolean
Default: false

Include stack traces in failures in default reporter.

reporter

Type: object | object[]

Reporters to use.

const gulp = require('gulp');
const jasmine = require('gulp-jasmine');
const reporters = require('jasmine-reporters');

exports.default = () => (
	gulp.src('spec/test.js')
		.pipe(jasmine({
			reporter: new reporters.JUnitXmlReporter()
		}))
);

Creating your own reporter.

timeout

Type: number
Default 5000

Time to wait in milliseconds before a test automatically fails.

errorOnFail

Type: boolean
Default: true

Stops the stream on failed tests.

config

Type: object

Passes the config to Jasmine's loadConfig 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.

FAQ

Babel

Add require('babel-core/register'); to the top of your gulpfile.js. Make sure to read the Babel docs.

gulp-jasmine's People

Contributors

anders-g-hansen avatar dylanb avatar ehmicky avatar floatinghotpot avatar jbblanchet avatar kevva avatar mjeanroy avatar mrmusa avatar ntwb avatar richienb avatar samverschueren avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gulp-jasmine's Issues

Cannot run gulp-jasmine in a watch task

If you run gulp-jasmine in a gulp.watch task, then the tests are run N times for each execution of the task instead of 1 time (where N is the number of times that the task has run in the past +1).

If this is the gulpfile.js

var gulp = require('gulp');
var jasmine = require('gulp-jasmine');

gulp.task('jasmine', function() {
    gulp.src('testfile.js')
        .pipe(jasmine())
});

gulp.task('watch', function () {
    gulp.watch(['file.js'], function(event) {
      gulp.run('jasmine');
    });
});

and this is the testfile.js file

var assert = require('assert'),
    test = require('./file');

describe('Test', function () {
    it('Should run this test', function () {
        test();
        assert.ok(true);
    });
});

and file.js is

module.exports = function () {
};

Change file.js and save, change it again and save and you will see that the test is run twice instead of once.

gulp-jasmine fails to test if module loader is SystemJS ???

So I may be new to this thing, but I am trying to use gulp to build, lint and test my demo solution. The app is using Angular 2, Gulp, SystemJS, gulp-tslint and gulp-jasmine, however I am unable to get the gulp-jasmine to run without falling over. It complains with the following

events.js:141
throw er; // Unhandled 'error' event
^
TypeError: Invalid System.register call. Anonymous System.register calls can on
ly be made by modules loaded by SystemJS.import and not via script tags.
at SystemJSNodeLoader. (D:\ng2demo\node_modules\systemjs\dist\sys
tem.src.js:2981:17)
at SystemJSNodeLoader. (D:\ng2demo\node_modules\systemjs\dist\sys
tem.src.js:3655:29)
at SystemJSNodeLoader. (D:\ng2demo\node_modules\systemjs\dist\sys
tem.src.js:4142:33)
at SystemJSNodeLoader.reduceRegister_ (D:\ng2demo\node_modules\systemjs\dist
\system.src.js:4142:33)
at SystemJSNodeLoader.pushRegister_ (D:\ng2demo\node_modules\systemjs\dist\s
ystem.src.js:2699:14)
at SystemJSNodeLoader.SystemJSLoader.register (D:\ng2demo\node_modules\syste
mjs\dist\system.src.js:2937:10)
at Object. (D:\ng2demo\app\assets\services\config.service.spec.js
:4:8)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)

The JS file it is attempting to run is a spec written in TypeScript and transpiled to JS with gulp-typescript. So the top line of the file is...

System.register(['angular2/core', 'angular2/http', 'angular2/http/testing', './config.service'], function(exports_1, context_1) {
//Do Stuff
});

It is this line it has a problem with, any ideas ???

Jasmine doesn't seems to recognize my js functions

I'm trying to make a task to execute some tests on my scripts. Therefore when I call a function on spec files it says that my functions are not defined.

e.g:

spec.js

describe("A suite", function() {
  it("contains spec with an expectation", function() {
    var a = returnNumber();
    expect(a).toBe(1);
  });
});

Thats the task I've been working on:

var jasmine = require('gulp-jasmine');

gulp.task('default', () =>
    gulp.src('assets/js/*.js')
        .pipe(jasmine({
            config: {
                spec_dir: 'assets',
                spec_files: [
                    'js/spec/*.js'
                ],
                helpers: [
                    'js/src/*.js'
                ]
            }
        }))
);

Add support for captureExceptions

Right now I use the 'jasmine-async-errors' to work around the problem, but jasmine has a setting for it that should work, but doesn't seem to work in gulp-jasmine. This is what I'd like to work:

      .pipe(jasmine({
        captureExceptions: true
      }));

(to be clear, this is the issue I'm trying to solve: mhevery/jasmine-node#267 (comment))

Broken with Jasmine 2.5.0?

When running gulp-jasmine with the newly released Jasmine 2.5.0, my gulp task of the form:

gulp.task('name', function() {
  return gulp.src(['...']).pipe(gulpJasmine());
});

never actually completes. With Jasmine 2.4.x, it works as expected. I'm not sure if this is a bug or intentional change in the way Jasmine works that will require a fix in gulp-jasmine.

My actual gulp task that fails when Jasmine is upgraded is: https://github.com/angular/mobile-toolkit/blob/0b0df9b0d8d2674db405b0854096ed61fb791bf3/service-worker/worker/gulpfile.ts#L374

Thanks!

emitting error on failed test

I'm wondering if this will not break some configuration as there is no easy way to distinguish between an exception thrown and failing test. Maybe the plugin should emit something different, ie. 'failure'?

Crashing on uncaught asynchronous exception

Given this gulp task:

gulp.task('test', function() {
    return gulp.src("*.spec.js")
        .pipe(jasmine());
});

and this spec:

describe("a test", function () {
    it("should work", function (done) {
        setTimeout(function () {
            throw "Exception";
            done();
        }, 1);
    });
});

the output will be:

[16:24:21] Starting 'test'...
Running 1 specs.

a test
C:\POC\test-gulp-jasmine\test.spec.js:4
            throw "Exception";
            ^
Exception

It would be nice to be able to catch the exception and return gracefully, but I guess this must be managed by jasmine directly and might not be possible at all.

Things that could be related:

Jasmine test browserified code

I'm trying to get gulp to build/transform my code with browserify/envify, and then test the transformed code with jasmine.

The browserify works:

gulp.src('./test/*')
  .pipe(browserify({ transform: ['reactify', 'envify'] }))
  .pipe(
    es.map(function (file, callback) {
      console.log(file.contents.toString()) //=> transformed code! :D
    })
  )

However when I pipe it into jasmine, I get failing tests which show code that is not reactified/envified:

gulp.src('./test/*')
  .pipe(browserify({ transform: ['reactify', 'envify'] }))
  .pipe(
    jasmine({ verbose: true }) //=> unexpected <ReactComponent/> (untransformed code)
  )

Injecting jquery/dom

I realize this isn't really an issue with gulp-jasmine per se, but more of a question regarding headless testing in jasmine. I just haven't been able to find the answer anywhere.

However, is there a path to injecting jquery into the gulp-jasmine tests. My end goal is to mock $.ajax calls.

Thanks

It is an error when I call the method spyon & andCallFake

The success when using jasmine-node command

PC4762:jasmine newgyu$ jasmine-node test/ExampleSpec.js
..

Finished in 0.007 seconds
2 tests, 2 assertions, 0 failures, 0 skipped

But, it fails when using gulp-jasmine

PC4762:jasmine newgyu$ gulp test
[21:00:04] Using gulpfile ~/temp/jasmine/gulpfile.js
[21:00:04] Starting 'test'...
[21:00:04] Finished 'test' after 15 ms
Running 2 specs.

example
    use spy: failed
    unuse spy: passed

Failures:
1) example use spy
1.1) TypeError: undefined is not a function
    TypeError: undefined is not a function
        at Object.<anonymous> (/Users/newgyu/temp/jasmine/test/ExampleSpec.js:6:26)

2 specs, 1 failure
Finished in 0.004 seconds

Sample Code: https://gist.github.com/NewGyu/64ddef2561fdee2b63af

jasmine is not defined

Hi,
I'm trying to use a Jasmine reporter.

The intial build was :

// Include gulp
var gulp = require('gulp');
var jasmine = require('gulp-jasmine');

gulp.task('specs', function () {
    return gulp.src('src/spec/*.js')
        .pipe(jasmine();
});

It works correctly.

To add a reporter, I just add a require at the top of the gulpfile.js. And this operation fails :

var jasmine = require('gulp-jasmine');
var reporters = require('jasmine-reporters');

Result :

gulp build
ReferenceError: jasmine is not defined
    at C:\***\node_modules\jasmine-reporters\src\jasmine.console_reporter.js:2:11
    at Object.<anonymous> (C:\***\node_modules\jasmine-reporters\src\jasmine.console_reporter.js:144:3)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\***node_modules\jasmine-reporters\src\load_reporters.js:1:63)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)

    at Object.<anonymous> (C:\***\gulpfile.js:18:17)

Any idea ?

Dependencies?

I'm actually new to unit testing in general, so this question may seem daft, but how do I load a dependancy like Angular? ie, I have a test like this:

describe("Foo", function() {
  beforeEach(angular.mock.module('app'));
  it('should have an AuthController', function (){
    expect(app.authCtrl).toBeDefined();
  });
});

But I get this error running the test:
ReferenceError: angular is not defined

export jasmine object

Sometimes it's convenient to access jasmine object directly and set it up however you need it.
My use case is that I want to use fail-fast. If jasmine object was exported, I could write a gulp task like below:

var $ = require('gulp-load-plugins')();

gulp.task('test', () => {
    var failFast = require('jasmine-fail-fast');
    $.jasmine.jasmine.getEnv().addReporter(failFast.init());
    return gulp.src('./spec/*.js')
        .pipe($.jasmine({ verbose: true }));
});

Exporting jasmine object would be a two line code change.
I can submit a PR if you give me a "good to go".

Jasmine helpers being unloaded but not reloaded

I am using the main jasmine npm module (not jasmine-node or variants of that), and running my tests inside a gulp watch task.

The first run of my test works perfectly, but on the second run, my helpers are unloaded and no longer available. What's going on here? I see some other similar/related pull requests and read through a few similar issues.

I tried using gulp-shell to execute my tests, but that fails because of an environment setup problem (using wemux on a remote server with other people which seems to kill permissions in child processes).

What's my best option for automatically re-loading my helpers without modifying all my tests? I have many files, and it wouldn't be feasable (in terms of maintenance) to manually require(...) the helpers in each one.

Error trying to use config in Node 6

Hi!

I got this error, seems to be relate to Node 6 release.

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.join (path.js:466:7)
    at ~~~\node_modules\jasmine\lib\jasmine.js:93:38
    at Array.forEach (native)
    at Jasmine.loadConfig (~~~\node_modules\jasmine\lib\jasmine.js:92:20)
    at module.exports (~~~\node_modules\gulp-jasmine\index.js:36:11)
    at Gulp.gulp.task (~~~\gulpfile.js:26:7)
    at module.exports (~~~\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (~~~\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (~~~\node_modules\orchestrator\index.js:214:10)

Here is my gulpfile.js

const gulp = require('gulp');
const jasmine = require('gulp-jasmine');

const paths = {
  scripts: ['./server/**/*.js'],
  specs: ['./server/**/*[Ss]pec.js']
}

var jasmineConfig = {
  "spec_files": [
    "**/*[sS]pec.js"
  ],
  "helpers": [
    "spec/helpers/**/*.js"
  ],
  "stopSpecOnExpectationFailure": false,
  "random": false
}



gulp.task('test', () => {
  gulp
    .src(paths.specs)
    .pipe(
      jasmine({
        config: jasmineConfig
      })
    );
});

gulp.task('default', [
  'test',
  'watch'
]);

gulp.task('watch', () => {
  gulp.watch(paths.scripts, ['test']);
});

I try already with

var jasmineConfig = require('./spec/support/jasmine.json');

Or even inline with no declare variable, but it doesn't work, however the configuration gets loaded, it show that error. If no configuration gets loaded, it shows nothing.

EDIT: I fixed. I was missing the "spec_dir" for the configuration. Thanks!

Waiting for jasmine to end before going on

I have trouble figuring out how to wait for jasmine to be done. What I basically want to achieve is to have the tests be reported by Istanbul:

gulp.src('target/**/*Spec.js').pipe(jasmine()).pipe(istanbul.writeReports());

This does not work, as Instanbul starts writing reports while jasmine is still running. So I tried sequencing the tasks by introducing methods with callbacks like so:

function testAll(callback) {
    "use strict";
    gulp.src('target/**/*Spec.js')
        .pipe(jasmine())
        .on('end', callback);
}

My issue here is, when I use 'finish', the callback is invoked before jasmine is done. And wenn I use 'end', as suggested in another issue, the callback never gets invoked.
Any suggestion on what I am missing?

Thanks,
Stefan

Modules:
[email protected]
[email protected]
[email protected]

Reporter Example

Was wondering if someone could provide an example of using this to produce a JUnit XML report? Thanks.

multiple error logs

// spec

describe("Gulp", function() {
    it("should be a streaming build system", function() {
        expect(gulp).toBeDefined();
    });
});

// gulpfile

var gulp = require('gulp'),
    jasmine = require('gulp-jasmine');

gulp.task('test', function () {
    return gulp.src('js/test/*Spec.js')
        .pipe(jasmine())
        .pipe(gulp.dest('dist/js'));
});

// output

$ gulp test
[19:29:57] Using gulpfile ~/testingGulp/Gulpfile.js
[19:29:57] Starting 'test'...
F

Failures: 
1) Gulp should be a streaming build system
1.1) ReferenceError: gulp is not defined

1 spec, 1 failure
Finished in 0.004 seconds


Failures: 
1) Gulp should be a streaming build system
1.1) ReferenceError: gulp is not defined

1 spec, 1 failure
Finished in 0.006 seconds


Failures: 
1) Gulp should be a streaming build system
1.1) ReferenceError: gulp is not defined

1 spec, 1 failure
Finished in 0.006 seconds


Failures: 
1) Gulp should be a streaming build system
1.1) ReferenceError: gulp is not defined

1 spec, 1 failure
Finished in 0.007 seconds

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Tests failed

Preprocessing

Sorry to open an issue for more of a question, but I can't find a solution to an issue I'm having.

I'm trying to use gulp-jasmine to run my test suite which imports scripts that contain JSX and ES6 code. I can't find any way to add a preprocessor, I've tried passing your module options as you would to a normal jasmine configuration with preprocessors (using babel), but no luck. Ideally I'd like to use my custom preprocessing function which runs ReactTools.transform under the hood but I'm open to any other solutions too.

Would be much appreciated if you could help out.

I get an error when attempting to use reporter option `Cannot call method 'addReporter' of undefined`

in the gulpfile:

gulp.task('back_unit', function(cb) {
  require('minijasminenode'); // puts jasmine in global namespace
  require('jasmine-reporters'); // depends on jasmine in global namespace
  // Readme is missing return statement for gulp stream in task
  return gulp.src('./test/back/unit/*.spec.js')
    .pipe(plugins.jasmine({
      verbose: true,
      reporter: new jasmine.JUnitXmlReporter()
    }));
});

results in:

TypeError: Cannot call method 'addReporter' of undefined
    at Object.jasmine.Env.addReporter (/Users/dev/Documents/project/contracts/node_modules/gulp-jasmine/node_modules/minijasminenode/lib/jasmine-1.3.1.js:883:17)
    at Object.module.exports [as jasmine] (/Users/dev/Documents/project/contracts/node_modules/gulp-jasmine/index.js:16:18)
    at Gulp.gulp.task.gulp.src.pipe.plugins.protractor.protractor.configFile (/Users/dev/Documents/project/contracts/gulpfile.js:382:19)

Please let me know if i'm doing this wrong or if there is an absolute simpler way to integrate reporters.

End Process

Is there a way to end it after finishing the tests:

gulp.task('testBE', ['watch-backend'], function () {
  return gulp.src(paths.specs + '/backend/**/*.spec.js')
    .pipe($.jasmine({verbose: true}));
});

It would be useful because then mongoose connections are not opened/ models are not loaded twice. I always have to quit the process in my terminal. I found this but it does not work:
http://stackoverflow.com/questions/27158530/cant-tell-when-jasmine-is-done-running

Node modules cache is not emptied

When running gulp-jasmine with gulp.watch, the node module cache has to be cleared between tests for both the spec files and the code file to be the updated version.

The current code

var modId = require.resolve(resolvedPath);
var files = require.cache[modId];
if (typeof files !== 'undefined') {
    for (var i in files.children) {
        delete require.cache[files.children[i].id];
    }
}

delete require.cache[modId];

appears to work for clearing the test file, but not the dependencies.

Here's the code I use in my gulp file to make sure that all files are reloaded:

for (var prop in require.cache) {
    if (prop.indexOf("node_modules") === -1) {
        delete require.cache[prop];
    }
}

This basically clears everything that isn't bolted to the floor. It's blunt, but rather effective.

I have a few concerns in integrating it to gulp-jasmine:

  • It's such a large purge, that I worry that it could lead to problems with certain types of projects. I can't think of any examples, but that doesn't mean that it wouldn't happen. So I think an option should be added to deactivate the logic and fall back to simply deleting the test file from the cache.
  • It still won't empty the cache between spec files. That would insure that each file is really independent of each other, but I'm not sure it's doable without going inside jasmine.
  • I'm not sure how to setup the tests for that. Probably the easiest way would be to have a dummy code file, and run the tests in a gulp.watch while I update the file, but that's not something that can be really automated.

What do you think?

Test babel code

I am trying to test babel code:

var gulp = require("gulp"),
    jasmine = require("gulp-jasmine"),
    babel = require("gulp-babel");

module.exports = function () {
    gulp.src(["index.js", "src/**/*.js", "spec/**/*[sS]pec.js"])
        .pipe(babel({
            "presets": ["es2015"],
            "plugins": ["transform-runtime"]
        }))
        .pipe(jasmine())
};

I got

events.js:141
      throw er; // Unhandled 'error' event
      ^
SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:414:25)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at D:\creation\software developer\projects\javascript-project-template\node_modules\jasmine\lib\jasmine.js:63:5
    at Array.forEach (native)
    at Jasmine.loadSpecs (D:\creation\software developer\projects\javascript-project-template\node_modules\jasmine\lib\jasmine.js:62:18)

Any idea about what I am missing?

Running tests inside watch ends watch

When I execute gulp-jasmine inside a watch the watch stops after the first test run. I'd expect it to continue watching and keep running tests whenever the appropriate files change. Sample gulp code:

...
gulp.task('test', ['compile'], function () {
    return gulp.src('build/tests/**/*.spec.js')
        .pipe(jasmine());
});

gulp.task('watch', ['default'], function () {
    gulp.watch(['src/**/*.ts', 'tests/**/*.ts'], ['default']);
});

Sample output:

[11:51:19] Finished 'compile' after 4.49 s
[11:51:19] Starting 'test'...
.............................................

45 specs, 0 failures
Finished in 0 seconds
myprompt$

I'm fairly new to node style Javascript so possible I've misunderstood something.

Properly handle asynchrony

Running the tests will directly report the task as finished, although the tests are still running. To properly wait for them to finish I need to work around that using the following:

gulp.task('test', function(cb) {
    gulp.src('specs/*.js')
        .pipe(jasmine())
        .pipe({
            on: function () {},
            emit: function () {},
            removeListener: function () {},
            end: cb
        });
});

How to load test support js files

I am trying to use this plug-in, however, when I have a spec file that relies on a existing js file, it throws errors. I can see how to trigger it based on the Spec file (below) but how do I load the associated src/test.js file

gulp.task('jasmine', function () {
return gulp.src('spec/testSpec.js')
.pipe(jasmine());
});

Exits immediately on javascript syntax error

I'm working on a project that uses jasmine, selenium, and webdriverio to drive selenium based tests. I started using gulp-jasmine yesterday and have been running into a problem where the gulp execution just exits as soon as a syntax error is encountered in any of my jasmine test files.

This is a problem because my test process starts 2 node servers to support the tests and these (as well as the Selenium driver) are all left running when this exists. I'm running with the following gulp tasks:

gulp.task('selenium:jasmine', ['server:test', 'server:capture_api', 'selenium'], function (done) {
  return gulp.src('test/spec/**/*.js')
    .pipe(jasmine())
    .on('error', function(err) {
      console.log(err.toString());
      done();
    });
});

gulp.task('integration', ['selenium:jasmine'], function () {
  node_capture_api.kill();
  selenium.child.kill();
  browserSync.exit();
});

In this case, the on('error' is never run so the processes are never cleaned up.

issues with require caching

we're doing something like this:

sqs_to_db_spec.js

describe('sqsToDb', () => {
  let DynamoDB, SQS;
  let sqsToDb;

  beforeEach(() => {
    const AWS = require('aws-sdk');
    DynamoDB = jasmine.createSpyObj('DynamoDB', ['putItem']);
    SQS = jasmine.createSpyObj('SQS', ['receiveMessage', 'deleteMessage']);

    spyOn(AWS, 'SQS').and.returnValue(SQS);

    spyOn(AWS, 'DynamoDB').and.returnValue(DynamoDB);

    delete require.cache[require.resolve('../../api/lambdas/sqs_to_db')]; // manually clear cache
    sqsToDb = require('../../api/lambdas/sqs_to_db').handler;
  });

  it('does thing', () => {
    // assertion
  });

  it('does other thing', () => {
    // other assertion
  });
)};

sqs_to_db.js

const AWS = require('aws-sdk');
const SQS = new AWS.SQS();
const DynamoDB = new AWS.DynamoDB();

exports.handler = () => {
  // do stuff
}

if we don't manually delete the cached sqs_to_db we get test pollution with our spies. we create a new spy in the beforeEach before the second it but sqs_to_db.js is never reloaded, so it continues to use the spy from the first it

we put some print messages in deleteRequireCache in gulp-jasmine/index.js and it looks like it's only trying to delete sqs_to_db_spec.js from the cache, but it's not cached

hangs at end of tests

When running against a set of nodejs tests they pass but it never exists.

gulp.task('test-server', function () {
  return gulp.src('spec/server/**/*.js')
    .pipe(jasmine());
});

Output which then requires a ctrl-c

[23:11:11] Starting 'test-server'...
Express server listening on 9000, in development mode
....

4 specs, 0 failures
Finished in 0 seconds
[23:11:13] Finished 'test-server' after 2.12 s

Any idea?

Parallel streams using gulp-jasmine prevent tests from all streams from being run.

If one stream is running with gulp-jasmine and another stream uses gulp-jasmine then only the stream that completes first will actually run that streams tests (the tests from the other stream are not run).

Example test:

it('should run all tests when new tests are added while running tests.', function (done) {
    var numTasks = 0;
    var output = '';
    var oldWrite = process.stdout.write;
    process.stdout.write = function (str) {
        output += str;
    };
    var startStream = function() {
        numTasks++;
        var stream = jasmine({
            timeout: 9000,
            verbose: true
        });
        var reader = through2.obj(function (file, enc, cb) {
            cb();
        }, function (cb) {
            process.stdout.write = out;
            assert.equal(output.match(/should pass another test: passed/g).length, 1);
            if (--numTasks <= 0) {
                done();
            }
            cb();
        });

        stream.pipe(reader);

        return stream;
    };

    var otherFixtureStream = startStream();
    var fixtureStream = startStream();


    fixtureStream.write(new gutil.File({
        path: 'fixture.js',
        contents: new Buffer('')
    }));

    otherFixtureStream.write(new gutil.File({
        path: 'otherFixture.js',
        contents: new Buffer('')
    }));

    fixtureStream.end();
    otherFixtureStream.end();
});

otherFixture.js:

describe('other fixture', function () {
    it('should pass another test', function (done) {
        expect(1).toBe(1);
        done();
    });
});

Ends before tests actually end when using asychronous tests

Ending process when end is called:

~/git/project  1s
ᐅ gulp test
[19:20:29] Using gulpfile ~/git/project/gulpfile.js
[19:20:29] Starting 'lint'...
[19:20:29] Finished 'lint' after 20 ms
[19:20:29] Starting 'test'...
[19:20:29] Finished 'test' after 15 ms
ok 1 - project.js : should throw an error when no token is given
ok 2 - project.js : should allow passing token as a string
ok 3 - project.js : should support passing options object as first argument

When not ending the process on end:

~/git/project  1s
ᐅ gulp test
[19:21:55] Using gulpfile ~/git/project/gulpfile.js
[19:21:55] Starting 'lint'...
[19:21:55] Finished 'lint' after 21 ms
[19:21:55] Starting 'test'...
[19:21:55] Finished 'test' after 15 ms
ok 1 - project.js : should throw an error when no token is given
ok 2 - project.js : should allow passing token as a string
ok 3 - project.js : should support passing options object as first argument
ok 4 - project.js : should not request ClientIP when flag is set
1..4
#4 specs, 0 failures, 0 skipped, 0 disabled in 0.107s.
# NOTE: disabled specs are usually a result of xdescribe.

how to pass configuration to reporters?

I'm using gulp-jasmine with jasmine-spec-reporter like this:

var jasmine = require('gulp-jasmine');
var SpecReporter = require('jasmine-spec-reporter');

gulp.task('test', function(){
    return gulp.src('tests/**/[^_]*.spec.js')
    .pipe(jasmine({
        reporter: new SpecReporter(),
        errorOnFail: false
    }));
});

how do I pass a configuration parameters to this spec reporter?

Required modules don't get cleared from cache

I have a simple module:

// in app/modules/session/app-token.js
var AppToken, config, uuid;
uuid = require('node-uuid');
config = require('../../config');

module.exports = AppToken = (function() {
  var generateSecureToken;

  function AppToken() {
    this.token = generateSecureToken();
    this.expires = config.get('appTokenExpires');
  }

  generateSecureToken = function() {
    console.log("---> Generating secure token...");
    return uuid.v4();
  };

  return AppToken;
})();

with a corresponding Jasmine unit test:

// in app/modules/session/app-token-spec.js
var AppToken;
AppToken = require('./app-token');

describe('AppToken', function() {
  return it("generates uuid version 4 token", function() {
    var appToken, regex;
    appToken = new AppToken();
    console.log("appToken: " + appToken.token);
    regex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
    expect(appToken.token).toMatch(regex);
  });
});

The nodemon is restarted on a change to a *.js file and the 'unit' task is run.

// in gulfile.js
... ... ...
gulp.task('unit', function () {
  return gulp.src(['app/**/*-spec.js'])
    .pipe(using())
    .pipe(jasmine());
});

gulp.task('watch-unit', function() {
  gulp.watch('app/**/*-spec.js', ['unit']);
});

gulp.task('restart-node', function () {
  nodemon(
    {
      // verbose: true,
      script: 'app/app.js',
      watch: 'app/',
      ext: 'js',
      ignore: ['*-spec.*'],
      env: { 'NODE_ENV': 'development' }
    }
  )

  .on('change', ['unit'])
  .on('restart', function () {
    console.log('restarted!')
  });

gulp.task('watch', ['watch-coffee', 'watch-unit', 'restart-node']);
gulp.task('default', ['watch']);

The problem I am facing is that changes to the module app-token.js aren't picked when tests are run up unless I shutdown and restart gulp. My guess that the module is cached because of this
require line in the spec:

AppToken = require('./app-token');

If I require it this way, then everything works as expected:

requireUncached = require('require-uncached');
AppToken = requireUncached('./app-token');

What can be done, so the changes in the modules are automatically picked up? Thank you.

gulp-jasmine does not end properly with jasmine 2.3

test.spec.js:

describe("a test", function() {
    it("runs", function () {
        expect(1).toBe(1); 
    });
});

gulpfile.js:

gulp.task('test', function () {
    return gulp.src('test.spec.js')
        .pipe(jasmine());
});

run gulp test

Process ends unexpectedly after running the test, but is fine with jasmine 2.2.

CoffeeScript Support

Is it possible to run spec files written in CoffeeScript without compiling them to JS first?

Feature Request : Ability to pre-load dependencies

Will be great to be have this option so that source files, third party libraries, helpers etc can be loaded in as modules.

Right now, I have to concat my dependencies so that my tests will pass.

gulp.src(['unit-tests/src/*.js','unit-tests/spec/SpecHelper.js','unit-tests/spec/PlayerSpec.js'])
        .pipe(plugins.concat('unit-tests.js'))
        .pipe(gulp.dest('dist/js'))
        .pipe(plugins.jasmine());
});

Module did not self-register

Hi,

I have this issue while running gulp-jasmine:

[11:49:37] Error in plugin 'gulp-jasmine'
Message:
    Module did not self-register.

with node v0.12.0 and npm 2.7.1
I've seen that node 0.12 might be the problem (like with node-sass)

I hope you'll be able to fix because I was really enjoying using your gulp plugin :)

Error TypeError: Object #<Object> has no method 'addMatchers'

When creating custom matcher the following error is seen
TypeError: Object # has no method 'addMatchers'

here is my code

beforeEach(function() {
calc = new Calculator();

this.addMatchers({

  toBeTwo: function(){

    this.message = function(){

      return this.actual + " is not two";
    }

return this.actual === 2;
}
});

});

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.