jest-puppeteer icon indicating copy to clipboard operation
jest-puppeteer copied to clipboard

Permission denied when starting dev-server

Open davidrv87 opened this issue 5 years ago • 4 comments

💥 Regression Report

I have been using dev-server for a while to start the server before running my tests without having to run them as sudo. After the upgrade to 4.3.0, the code will throw and undefined error.

I say undefined because there is a Promise rejection without error (see this line).

The code above is called here. Although, that line of code in my node_modules/jest-environment-puppeteer/global.js is

try {
    await (0, _jestDevServer.setup)(config.server);
} catch (error) {
    if (error.code === _jestDevServer.ERROR_TIMEOUT) {
[...]

This is the stacktrace:

TypeError: Cannot read property 'code' of undefined
    at setup (/Users/david/Projects/cards-preflight-service/node_modules/jest-environment-puppeteer/lib/global.js:35:17)
    at process._tickCallback (internal/process/next_tick.js:68:7)

If I manually edit this line to reject with the error then the stacktrace looks like this:

Error: listen EACCES: permission denied 127.0.0.1:80
    at Server.setupListenHandle [as _listen2] (net.js:1262:19)
    at listenInCluster (net.js:1327:12)
    at GetAddrInfoReqWrap.doListen [as callback] (net.js:1460:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:61:10)

Last working version

Worked up to version: 4.2.0

Stopped working in version: 4.3.0

To Reproduce

My jest-puppeteer.config.js has always looked like this:

module.exports = {
  server: {
    command: 'node test/fixtures/dummy_frontend/serv.js',
    port: 80
  },
  launch: {
    dumpio: false,
    headless: process.env.HEADLESS !== 'false',
    args: ['--no-sandbox', '--disable-setuid-sandbox']'
  },
  browserContext: 'incognito'
};

Expected behavior

The dev-server starts as it used to start on port 80, test run and the dev-server is killed at the end.

Run npx envinfo --system --binaries --npmPackages expect-puppeteer,jest-dev-server,jest-environment-puppeteer,jest-puppeteer,spawnd --markdown --clipboard

Paste the results here:

## System:
 - OS: macOS 10.14.5
 - CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
 - Memory: 571.46 MB / 16.00 GB
 - Shell: 3.2.57 - /bin/bash
## Binaries:
 - Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
 - Yarn: 1.16.0 - /usr/local/bin/yarn
 - npm: 6.9.0 - ~/.nvm/versions/node/v10.16.0/bin/npm
## npmPackages:
 - jest-dev-server: 4.3.0 => 4.3.0 
 - jest-environment-puppeteer: 4.3.0 => 4.3.0 
 - jest-puppeteer: 4.3.0 => 4.3.0 

davidrv87 avatar Jul 17 '19 12:07 davidrv87

Hello @davidrv87, could you try to submit a PR to fix it?

gregberge avatar Jul 23 '19 14:07 gregberge

To be quite honest, I don't know the fix for this. I can only point you to the lines where the issue is found. At the very most, I could submit the PR to address the issue of the rejected promise without error but it is basically changing this line

From:

err.code === 'EADDRINUSE' ? resolve(cleanupAndReturn(true)) : reject(),

to:

err.code === 'EADDRINUSE' ? resolve(cleanupAndReturn(true)) : reject(err),

This will produce a more meaningful error and things will be easier to debug.

davidrv87 avatar Jul 24 '19 06:07 davidrv87

@davidrv87 OK let's do it for now.

gregberge avatar Aug 06 '19 10:08 gregberge

This bug can be fixed by this.

server: {
  command: 'node server.js',
},

And it only appear when set port at 80.

server: {
  command: 'node server.js',
  port: 80
},

abrcdf1023 avatar Oct 03 '19 07:10 abrcdf1023

Using port 80 is not a good idea. If you have to do it, then start jest with a user that has the required permission to start a server on this port.

gregberge avatar Feb 04 '23 15:02 gregberge