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

Server is not closed after request #187

Closed
serge1peshcoff opened this issue Nov 10, 2017 · 4 comments
Closed

Server is not closed after request #187

serge1peshcoff opened this issue Nov 10, 2017 · 4 comments

Comments

@serge1peshcoff
Copy link

I am using chai-http to write the tests like that:

  it('should reject requests without X-Auth-Token', (done) => {
    omscoreStub = nock('http://omscore-nginx')
      .post('/api/tokens/user')
      .replyWithFile(200, path.join(__dirname, '..', 'assets', 'oms-core-valid.json'));

    chai.request(server)
      .get('/getUser')
      .end((err, res) => {
        res.should.have.status(403);
        res.body.success.should.be.false;

        done();
      });
  });

  it('should fail if the user is unauthorized', (done) => {
    omscoreStub = nock('http://omscore-nginx')
      .post('/api/tokens/user')
      .replyWithFile(200, path.join(__dirname, '..', 'assets', 'oms-core-unauthorized.json'));

    chai.request(server)
      .get('/getUser')
      .set('X-Auth-Token', 'foobar')
      .end((err, res) => {
        res.should.have.status(403);
        res.body.success.should.be.false;

        done();
      });
  });

The thing is, requests to another services are cached in memory of my application, and the first time it doesn't use the cached version, as needed, but the second time I run it, it uses the cached version. That means that the app isn't closed after 1st request somehow. Also I tried to put debut statements inside the callback after server start, and they are executed only once per the whole test run, not for each test. And I need the server to be restarted after each test.
How can I accomplish it?

chai-http v3.0.0, chai v3.5.0, Node v8.7.0, Mac OS x 10.13.1

@serge1peshcoff
Copy link
Author

Well I've looked into the source code of my installed version, compared it with the code in this repository, and it seems like the changes to close the connection after request (the last commits) are not in the NPM repository (I've installed the NPM version twice, just to be sure, and these changes are not there). Can you please update the NPM package?

@vieiralucas
Copy link
Member

Hello @serge1peshcoff
This should be fixed once #184 gets released
For now you can follow #178 workarounds or use master:

npm i --save-dev https://github.com:chaijs/chai-http

@serge1peshcoff
Copy link
Author

@vieiralucas Is there any ETA or the release date?

@aandis
Copy link

aandis commented May 18, 2019

hey @vieiralucas installing from master doesn't fix this. Any other workarounds? I want the server to restart for each it test block.

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