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

Enabling spawned server output (stdout, stderr) for debugging #44

Closed
mhipszki opened this issue Apr 19, 2018 · 2 comments
Closed

Enabling spawned server output (stdout, stderr) for debugging #44

mhipszki opened this issue Apr 19, 2018 · 2 comments

Comments

@mhipszki
Copy link

When a server command is specified in jest-puppeteer.config.js but for some reason e.g. misconfigured port etc. we cannot connect to the spawned server, Jest will just hang forever in a state Determining test suites to run...

screen shot 2018-04-19 at 8 57 09 am

Actually when the ports are not matching this it waits forever for the port to be opened:

    if (config.server.port) {
      await waitPort({ port: config.server.port, output: 'silent' })
    }

Adding e.g. a debug option to the server config could help developers to find out what's causing the issue e.g.

// jest-puppeteer.config.js
module.exports = {
  server: {
    command: 'node server.js',
    port: 4444,
    debug: true
  },
}

The implementation is simple, the spawned child process needs listeners on both stdout and stderr so that we can console.log whatever happens in there:

    server = spawnd(config.server.command, {
      shell: true,
      env: process.env,
      cwd: cwd(),
      ...config.server.options,
    })

    // allow logging the spawned process output to our own shell
    if (config.server.debug) {
      server.stdout.on('data', data => {
        console.log(data)
      })

      server.stderr.on('data', data => {
        console.log(data)
      })
    }

Also the output: 'silent' option of wait-port could be turned off to show that we're actually waiting for the port to be opened.

    if (config.server.port) {
      await waitPort({ port: config.server.port, ...!debug && { output: 'silent' } })
    }
@mhipszki
Copy link
Author

I'm happy to create a PR for this if there's interest.

@gregberge
Copy link
Member

Yes I would be happy to have that feature, also I think we should be able to define a timeout to avoid waiting forever. Can you do this? Thanks!

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

2 participants