Jest-puppeteer: Unable to run server using https

Created on 10 Sep 2018  ·  4Comments  ·  Source: smooth-code/jest-puppeteer

I have an app that is running using https. I need to set up e2e testing environment for it.

If I set in the jest-puppeteer.config.js the server option protocol to 'http' the test runner ignores the server started on https://localhost:3000 and terminated by timeout running no tests.
The output is

yarn run v1.9.4
$ NODE_ENV=test jest --useStderr --forceExit --runInBand --no-cache --detectOpenHandles --config config/jest/config.e2e.js
Determining test suites to run...
Jest dev-server output:
[Jest Dev server] $ node --max-old-space-size=4096 ./scripts/start.js
[Jest Dev server] NODE_ENV: test
[Jest Dev server] Starting the development server...
[Jest Dev server] start detecting webpack modules cycles
[Jest Dev server] end detecting webpack modules cycles
[Jest Dev server] start detecting webpack modules cycles
[Jest Dev server] end detecting webpack modules cycles
[Jest Dev server] 

Compile done in: 159.054s
[Jest Dev server] Compiled with warnings.
[Jest Dev server] Warning in ./~/ajv/lib/async.js
96:20-33 Critical dependency: the request of a dependency is an expression
    at process._tickCallback (internal/process/next_tick.js:180:9)
Warning in ./~/ajv/lib/async.js
119:15-28 Critical dependency: the request of a dependency is an expression
    at process._tickCallback (internal/process/next_tick.js:180:9)
Warning in ./~/ajv/lib/compile/index.js
13:21-34 Critical dependency: the request of a dependency is an expression
    at process._tickCallback (internal/process/next_tick.js:180:9)
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.

Server has taken more than 240000ms to start.

☝️ You can set "server.launchTimeout" in jest-puppeteer.config.js
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

If in the jest-puppeteer.config.js I skip the server option protocol or set it to null the test runner starts tests execution right after the call of the server start (not waiting while the app is started). My app is compiled up to 4 minutes. Hence to avoid termination by timeout I removed timeout restriction from page.goto and set the test case timeout to 4 minutes. However once the app compiled I get net::ERR_SPDY_PROTOCOL_ERROR at https://localhost:3000/login error.
The output is

yarn run v1.9.4
$ NODE_ENV=test jest --useStderr --forceExit --runInBand --no-cache --detectOpenHandles --config config/jest/config.e2e.js
Determining test suites to run...
Jest dev-server output:
[Jest Dev server] $ node --max-old-space-size=4096 ./scripts/start.js
[Jest Dev server] NODE_ENV: test
[Jest Dev server] Starting the development server...
[Jest Dev server] start detecting webpack modules cycles
end detecting webpack modules cycles
[Jest Dev server] start detecting webpack modules cycles
[Jest Dev server] end detecting webpack modules cycles
[Jest Dev server] 

Compile done in: 157.259s
 FAIL  tests/e2e/home.test.js (157.404s)
  home page
    ✕ contains a particular text (155336ms)

  ● home page › contains a particular text

    net::ERR_SPDY_PROTOCOL_ERROR at https://localhost:3000/login

      at navigate (node_modules/puppeteer/lib/Page.js:622:37)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        158.343s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Please, note that if I use http (not https) in the app, in the test case and in the jest-puppeteer.config.js everything is fine i.e. the test suite is passed and executed once the app is started but I need to use https.

Test Case

/*global TimeoutLength windowSize*/
import puppeteer from 'puppeteer';
import expect from 'expect-puppeteer';

describe('home page', () => {
  let browser;
  let page;

  beforeAll(async () => {
    jest.setTimeout(TimeoutLength);

    browser = await puppeteer.launch({
      headless: false,
      args: [`--window-size=${windowSize.width},${windowSize.height}`],
      ignoreHTTPSErrors: true
    });
    page = await browser.newPage();
    await page.setViewport(windowSize);
  });

  it('contains a particular text', async () => {
    await page.goto('https://localhost:3000/login', {
      timeout: 0
    });
    await expect(page).toMatch('My Accounts');
  }, TimeoutLength);

  afterAll(() => {
    browser.close();
  });
});

jest-puppeteer.config.js

module.exports = {
  server: {
    command: 'NODE_ENV=test yarn start',
    debug: true,
    launchTimeout: 240000,
    port: 3000,
    protocol: 'http',//or skipped i.e. protocol: null
    usedPortAction: 'kill'
  }
};

Jest config

module.exports = {
  rootDir: '../..',
  testURL: 'http://localhost',
  setupFiles: [
    '<rootDir>/config/jest/setup.js'
  ],
  transform: {
    '^.+\\.(js|jsx)?$': '<rootDir>/config/jest/transform.js'
  },
  moduleDirectories: [
    'node_modules',
    'src'
  ],
  globals: {
    TimeoutLength: 240000,
    windowSize: {
      width: 1200,
      height: 900
    }
  },
  verbose: true,
  preset: 'jest-puppeteer',
  setupTestFrameworkScriptFile: 'expect-puppeteer',
  testRegex: '.*\\.(test)\\.js$',
  testPathIgnorePatterns: [
    'config/babel.test.js'
  ]
};
bug 🐛

Most helpful comment

Looks like there's a healthier alternative to wait-port. https://www.npmjs.com/package/wait-on

All 4 comments

Looks like there's a healthier alternative to wait-port. https://www.npmjs.com/package/wait-on

Hi @langri-sha
Thank you for your suggestion, look like the wait-on package better than wait-for package.

I will be very happy to replace wait-port to wait-on. What do you thinking @neoziro

Hi @langri-sha, hi @xiaoyuhen. It is OK for me, if it works better, let's use it!

hi @alexander-elgin

after merge this PR and floow this guide

will able to run server using https

Was this page helpful?
0 / 5 - 0 ratings

Related issues

macabeus picture macabeus  ·  4Comments

timwis picture timwis  ·  5Comments

undrafted picture undrafted  ·  4Comments

rodoabad picture rodoabad  ·  3Comments

songguohfut picture songguohfut  ·  6Comments