title: ECONNREFUSED 127.0.0.1:3000 at TCPConnectWrap.afterConnect [as oncomplete] errno: 'ECONNREFUSED',
body: <p>I am running some test on a mocked (facebook/google)strategy but the problem I have when run those test one by one it's running but when I run them simultaneously they are not working after the first test, the connection of the application fails immediately.</p>
  
  <p>I tried to run in different describe but nothing has changed I am using nodejs and @passport-next/passport-mocked as a dependency to help me to mock those strategies.</p>
  
  <pre><code>  import chai from 'chai';
  import chaiHttp from 'chai-http';
  import passport from 'passport';
  import '../config/passport';
  import { describe, it } from 'mocha';
  import server from '../index';
  
  chai.use(chaiHttp);
  const should = chai.should();
  
  describe.only('login through facebook', () =&gt; {
    it('redirects to facebook', (done) =&gt; {
      chai
        .request(server)
        .get('/api/v1/users/auth/facebook')
        .end((_err, res) =&gt; {
          res.redirects[0].should.contain('api/v1/users/auth/facebook/callback?__mock_strategy_callback=true');
          done();
        });
    });
    it('redirects to google', (done) =&gt; {
      chai
        .request(server)
        .get('/api/v1/users/auth/google')
        .end((_err, res) =&gt; {
            console.log(_err);
          // res.redirects[0].should.contain('api/v1/users/auth/google/callback?__mock_strategy_callback=true');
          done();
        });
    });
  
  
  });
  
  </code></pre>
  
  <p>this is my test file</p>
  
  <pre><code>import passport from 'passport';
  import config from './auth';
  
  
  let FacebookStrategy;
  let GooglePlusStrategy;
  if (process.env.NODE_ENV !== 'test') {
    FacebookStrategy = require('passport-facebook');
    GooglePlusStrategy = require('passport-google-oauth20');
  } else {
    FacebookStrategy = require('passport-mocked').Strategy;
    GooglePlusStrategy = require('passport-mocked').OAuth2Strategy;
  }
  
  passport.use(new FacebookStrategy({
    name: 'facebook',
    clientID: '2618632188182397',
    clientSecret: 'f8a48d72223691ad05ca936fa20049e9',
    callbackURL: 'http://localhost:3000/api/v1/users/auth/facebook/callback',
    profileFields: ['id', 'displayName', 'photos', 'email']
  }, (accessToken, refreshToken, profile, done) =&gt; {
    const firstName = profile._json.firstName;
    const lastName = profile._json.last_name;
    const email = profile.emails[0].value;
    const user = { firstName, lastName, email };
    // console.log(profile);
    done(null, user);
  }));
  
  
  passport.use(new GooglePlusStrategy({
    name: 'google',
    clientID: config.google.clientID,
    clientSecret: config.google.clientSecret,
    callbackURL: 'http://localhost:3000/api/v1/users/auth/google/callback'
  }, (accessToken, refreshToken, profile, cb) =&gt; {
    const user = {
      username: profile.displayName,
      email: profile.emails[0].value,
      isverified: true
    };
    console.log(profile);
    cb(null, user);
  }));
  
  passport.serializeUser((user, done) =&gt; {
    done(null, user);
  });
  
  passport.deserializeUser((user, done) =&gt; {
    done(null, user);
  });
  
  export default passport;
  
  </code></pre>
  
  <p>this is my passport configuration</p>
  
  <pre><code>const server = app.listen(process.env.PORT || 3000, () =&gt; {
    // eslint-disable-next-line no-console
    console.log(`Listening on port ${server.address().port}`);
  });
  </code></pre>
  
  <p>this is my app index</p>
  
  <pre><code>app.get('/auth/facebook', passport.authenticate('facebook', { scope: ['email'] }));
  
  app.get('/auth/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/login' }), (req,res) =&gt; res.send("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;"));
  
  
  app.get('/auth/google', passport.authenticate('google', { scope: ['email', 'profile'] }));
  
  app.get('/auth/google/callback', passport.authenticate('google'), (req,res) =&gt; res.send("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;") );
  </code></pre>
  
  <p>these are my routes</p>
  
  <p>I expect the result of my test to in format of <strong><em>json</em></strong> but right now when I run the result in <strong><em>null</em></strong> and I git error</p>
  
  <pre><code>Listening on port 3000
    login through facebook
      ✓ redirects to facebook (57ms)
  { Error: connect ECONNREFUSED 127.0.0.1:3000
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
    errno: 'ECONNREFUSED',
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '127.0.0.1',
    port: 3000,
    response: undefined }
      ✓ redirects to google
  </code></pre>
  
  <p>the error I am getting</p>