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

supertest & mocha problems with integration tests #338

Closed
Avcajaraville opened this issue May 18, 2016 · 4 comments
Closed

supertest & mocha problems with integration tests #338

Avcajaraville opened this issue May 18, 2016 · 4 comments

Comments

@Avcajaraville
Copy link

I am having a bad time trying to know what is going on here.

I'm setting some integration tests with mocha & supertest.

My problem is that the time showed on each "it" block is not reliable.

If I copy paste the same test, always, the first test takes like 5 times more. I know this must be something Im missing here, but can't understand why.

I know about require cache issue, but I don't think is related with my problem.

This is my test:

var express = require( 'express' );
var supertest = require( 'supertest' );
var should = require('should');


describe( 'dummy describe', function() {

  var app, request;

  beforeEach(function() {
    app = express();
    app.get( '/', function( req, res ) {
      res.send( 'hey' );
    });
    request = supertest(app)
      .get('/')
      .set('User-Agent', 'my cool browser')
      .set('Accept', 'text/plain');
  });


  it( 'should do a dummy test', function( done ) {
    request
      .end( function( err, res ) {
        res.status.should.equal( 200 );
        res.text.should.equal( 'hey' );
        done();
    });
  });

  it( 'should do a dummy test', function( done ) {
    request
      .end( function( err, res ) {
        res.status.should.equal( 200 );
        res.text.should.equal( 'hey' );
        done();
    });
  });

});

Note that test is exactly the same.

This are my results:

captura de pantalla 2016-05-18 a las 12 39 49

Even more, if I add more tests (same test); I still get the same results:

captura de pantalla 2016-05-18 a las 12 41 11

I don't think this is a normal behaviour, since it don't give me a reliable metric.

So, question is who is caching here ? or why is this happening ?

Not sure if this issue is related with Mocha, supertest, node's http module, or what.

Thanks in advance !

stack overflow question

@roccomuso
Copy link

+1

@aimer1124
Copy link

Change beforeEach to before

@Avcajaraville
Copy link
Author

@aimer1124 No, thats not correct. Thats not what I am looking for.

Related: nodejs/help#173

@Avcajaraville
Copy link
Author

Not fixed, but closing it anyway. This is probably due to time to set sockets

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

3 participants