jest: Test with puppeteer is failed

🐛 Bug Report

I need to run puppeteer tests in separate browser sessions, so I need not the settings for puppetter as described in configure section on the site. So I added puppeteer to the project and wrote the test: App1.test.js

import puppeteer from 'puppeteer';

let page;
let browser;

beforeAll(async () => {
    browser = await puppeteer.launch();
    page = await browser.newPage();

    await page.goto('https://google.com/');
});

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

it('should load without error', async () => {
    const text = await page.evaluate(() => document.body.textContent);

    expect(text).toContain('google');
});

it is failed with error:

 ● Test suite failed to run

    Cannot find module './types/standard' from 'index.js'

      at Resolver.resolveModule (../node_modules/jest-resolve/build/index.js:210:17)
      at Object.<anonymous> (../node_modules/puppeteer/node_modules/mime/index.js:4:27)

To Reproduce

npm run test

Expected behavior

test is passed

Link to repl or repo (highly encouraged)

here is repo

Run npx envinfo --preset jest

  System:
    OS: Windows 7
    CPU: x64 AMD FX(tm)-6300 Six-Core Processor
  Binaries:
    Yarn: 1.6.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.1.0 - C:\Program Files\nodejs\npm.CMD


About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

You’ve changed the default moduleFileExtensions, mime does not include .json in its require: https://github.com/broofa/node-mime/blob/c013a0835a0a7d2c3a91e01fa3c5e08349ddc894/index.js#L4

This fixes it:

diff --git i/jest.config.js w/jest.config.js
index 61714aa..4b5dc49 100644
--- i/jest.config.js
+++ w/jest.config.js
@@ -12,7 +12,7 @@ const config = {
         '**/?(*.)+(spec|test).js?(x)',
         '**/?(*.)+(spec|test).ts?(x)',
     ],
-    moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
+    moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json'],
     moduleNameMapper: {
         '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
             '../config/jest/mocks/fileMock.js',