Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest test fails when environment is configured with webpack-hot-middleware

So I'm running a very basic Jest test to test if one of my routes returns a 200.

import request from 'supertest';
import app from './../app';

describe('GET /', () => {
  it('should render properly', async () => {
    await request(app).get('/api/testing').expect(200);
  });
});

This was working perfectly then I configured webpack-hot-middleware and it seems to break at line 2 where I import app.

TypeError: setInterval(...).unref is not a function

  at createEventStream (node_modules/webpack-hot-middleware/middleware.js:50:17)
  at webpackHotMiddleware (node_modules/webpack-hot-middleware/middleware.js:12:21)
  at Object.<anonymous> (server/app.js:62:73)
  at Object.<anonymous> (server/test/routes.test.js:2:38)

If I remove the following code from my app.js the tests all run fine.

  app.use(middleware);
  app.use(webpackHotMiddleware(compiler));
  app.get('*', (req, res) => {
    res.write(middleware.fileSystem.readFileSync(path.join(__dirname, '../dist/index.html')));
    res.end();
  });

Has anyone configured Jest for webpack-hot-middleware? I'm kind of lost because I feel like I've tried everything.

like image 234
Chris Pena Avatar asked Jan 04 '23 18:01

Chris Pena


1 Answers

You must set testEnvironment Jest config option to node. unref() exists in Node.js only.

like image 68
bigslycat Avatar answered Jan 07 '23 23:01

bigslycat