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

Add CJS priority for Puppeteer environment #110

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "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",
Expand Down
16 changes: 15 additions & 1 deletion src/PuppeteerReactEnvironment.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
const path = require('path');
const { TestEnvironment } = require('jest-environment-puppeteer');
const { promisify } = require('util');
const fs = require('fs');

class PuppeteerReactEnvironment extends TestEnvironment {
async setup() {
await super.setup();

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;
Expand Down
6 changes: 3 additions & 3 deletions src/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading