Skip to content

Commit

Permalink
Add cjs modules support
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliaksandr-Lapeta authored and rosczja committed Oct 23, 2024
1 parent 4ee5a39 commit ac214d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-puppeteer-react",
"version": "11.0.0",
"version": "12.0.0",
"description": "screenshot tests for your react components in chromium using puppeteer & jest",
"main": "src/index.js",
"types": "src/index.d.ts",
Expand Down
18 changes: 16 additions & 2 deletions src/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,21 @@ const DIR = path.join(os.tmpdir(), 'jest_puppeteer_react_global_setup');

let webpackDevServer;

const getConfig = () => require(path.join(process.cwd(), 'jest-puppeteer-react.config.js'));
const getConfig = async () => {
const congifName = 'jest-puppeteer-react.config';
const statPromisified = promisify(fs.stat);

let configExt = '.cjs';

try {
await statPromisified(path.join(process.cwd(), `${congifName}${configExt}`));
} catch (e) {
// Fallback extension if CommonJS module not exist
configExt = '.js';
}

return require(path.join(process.cwd(), `${congifName}${configExt}`));
};

module.exports.setup = async function setup(jestConfig) {
const { noInfo = true, rootDir, testPathPattern, debugOnly = false } = jestConfig;
Expand All @@ -29,7 +43,7 @@ module.exports.setup = async function setup(jestConfig) {
return testPathPatterRe.test(fs.realpathSync(file));
});

const config = getConfig();
const config = await getConfig();

const entryFiles = [
path.resolve(__dirname, 'webpack/globals.browser.js'),
Expand Down

0 comments on commit ac214d1

Please sign in to comment.