Giter VIP home page Giter VIP logo

Comments (5)

jbblanchet avatar jbblanchet commented on August 21, 2024

I don't have a lot of details, so I'm sorry if I ask obvious questions, but are you closing your Express server at the end of the tests?

from gulp-jasmine.

jperry avatar jperry commented on August 21, 2024

no. Is there something to pipe in as jasmine automatically handles the starting of the express server so I would have expected it to stop on it's own.

from gulp-jasmine.

jbblanchet avatar jbblanchet commented on August 21, 2024

Neither jasmine nor gulp-jasmine knows express, so your express server is either started in your specs or by one of the module you load. Once again, I don't have a lot of details on your use case, but if I were to guess, you probably have something like this:

server.spec.js:

var server = require("../server");

server.js:

var express = require("express");
var app = express();
app.listen(9000);

Is that the case?

from gulp-jasmine.

jperry avatar jperry commented on August 21, 2024

yes, that is the pretty similar to what we have. I wonder how jasmine-node does it then within grunt which is what we had before. Sorry for not providing enough information.

from gulp-jasmine.

jbblanchet avatar jbblanchet commented on August 21, 2024

I haven't worked with grunt that much, so I can't help you on that, but I think the current jasmine behavior is correct. Setup and teardown are the responsibility of the tests, not the framework. I'll close this issue, but feel free to discuss it further if you think this is a required feature.

If you want a quick fix, you can listen to the end of the stream in your gulp file with: .on('end', function() { and force close node.

As an aside, a pattern that I found useful for building and testing express servers is setting the server up in a module and starting it in another. Something like that:

server.js

var express = require("express");

function Server () {
    this._app = express();

    this._app.get("/", function (req, res) {
        res.send("Hello world!");
    })
}

Server.prototype.start = function (port, otherOptions) {
    this._instance = this._app.listen(port);
};

Server.prototype.stop = function (cb) {
    this._instance.close(cb);
};

module.exports = new Server();

start.js

var server = require("./server");

server.start(process.env.port, "other options");

This way, when you import server.js in your specs, you can start and stop it manually in your tests, either in beforeAll/endAll or beforeEach/endEach depending on the atomicity of your tests.

Hope this helps.

from gulp-jasmine.

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.