diff --git a/package.json b/package.json index b38fceb..5568d01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jest-puppeteer-react", - "version": "12.0.0", + "version": "12.0.1", "description": "screenshot tests for your react components in chromium using puppeteer & jest", "main": "src/index.js", "types": "src/index.d.ts", diff --git a/src/PuppeteerReactEnvironment.js b/src/PuppeteerReactEnvironment.js index 0e3fc76..8bdc6a9 100644 --- a/src/PuppeteerReactEnvironment.js +++ b/src/PuppeteerReactEnvironment.js @@ -1,5 +1,7 @@ const path = require('path'); const { TestEnvironment } = require('jest-environment-puppeteer'); +const { promisify } = require('util'); +const fs = require('fs'); class PuppeteerReactEnvironment extends TestEnvironment { async setup() { @@ -7,7 +9,19 @@ class PuppeteerReactEnvironment extends TestEnvironment { const rootPath = process.cwd(); // of your project under test - const config = require(path.join(rootPath, 'jest-puppeteer-react.config.js')); + const configName = 'jest-puppeteer-react.config'; + const statPromisified = promisify(fs.stat); + + let configExt = '.cjs'; + + try { + await statPromisified(path.join(process.cwd(), `${configName}${configExt}`)); + } catch (e) { + // Fallback extension if CommonJS module not exist + configExt = '.js'; + } + + const config = require(path.join(rootPath, `${configName}${configExt}`)); if (!config.port) { config.port = 1111; diff --git a/src/global.js b/src/global.js index fdb9d84..7e67054 100644 --- a/src/global.js +++ b/src/global.js @@ -16,19 +16,19 @@ const DIR = path.join(os.tmpdir(), 'jest_puppeteer_react_global_setup'); let webpackDevServer; const getConfig = async () => { - const congifName = 'jest-puppeteer-react.config'; + const configName = 'jest-puppeteer-react.config'; const statPromisified = promisify(fs.stat); let configExt = '.cjs'; try { - await statPromisified(path.join(process.cwd(), `${congifName}${configExt}`)); + await statPromisified(path.join(process.cwd(), `${configName}${configExt}`)); } catch (e) { // Fallback extension if CommonJS module not exist configExt = '.js'; } - return require(path.join(process.cwd(), `${congifName}${configExt}`)); + return require(path.join(process.cwd(), `${configName}${configExt}`)); }; module.exports.setup = async function setup(jestConfig) {