Skip to content

Commit 53c6368

Browse files
committed
try debugging
1 parent 9158595 commit 53c6368

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

test/puppeteer-environment.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,51 @@ import NodeEnvironment from 'jest-environment-node';
1010

1111
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
1212

13-
export default class PuppeteerEnvironment extends NodeEnvironment.default {
13+
// Debug the NodeEnvironment structure
14+
console.log('NodeEnvironment import type:', typeof NodeEnvironment);
15+
console.log('Has default property:', 'default' in NodeEnvironment);
16+
if ('default' in NodeEnvironment) {
17+
console.log('Default property type:', typeof NodeEnvironment.default);
18+
}
19+
20+
// More robust determination of the correct Environment class
21+
let NodeEnvironmentClass;
22+
try {
23+
if (typeof NodeEnvironment === 'function') {
24+
console.log('Using NodeEnvironment directly as constructor');
25+
NodeEnvironmentClass = NodeEnvironment;
26+
} else if (
27+
NodeEnvironment.default &&
28+
typeof NodeEnvironment.default === 'function'
29+
) {
30+
console.log('Using NodeEnvironment.default as constructor');
31+
NodeEnvironmentClass = NodeEnvironment.default;
32+
} else if (NodeEnvironment.__esModule && NodeEnvironment.NodeEnvironment) {
33+
// Some ESM patterns expose the class differently
34+
console.log('Using NodeEnvironment.NodeEnvironment as constructor');
35+
NodeEnvironmentClass = NodeEnvironment.NodeEnvironment;
36+
} else {
37+
console.log('Falling back to direct import');
38+
NodeEnvironmentClass = NodeEnvironment;
39+
}
40+
41+
// Verify we have a valid constructor
42+
if (typeof NodeEnvironmentClass !== 'function') {
43+
console.error(
44+
'Final NodeEnvironmentClass is not a constructor!',
45+
typeof NodeEnvironmentClass
46+
);
47+
// Last resort fallback - use dynamic import to avoid linter warning
48+
// eslint-disable-next-line global-require
49+
const fallbackEnv = Function('return require("jest-environment-node")')();
50+
NodeEnvironmentClass = fallbackEnv.default || fallbackEnv;
51+
}
52+
} catch (error) {
53+
console.error('Error determining NodeEnvironment class:', error);
54+
throw new Error(`Failed to load Jest NodeEnvironment: ${error.message}`);
55+
}
56+
57+
export default class PuppeteerEnvironment extends NodeEnvironmentClass {
1458
async setup() {
1559
await super.setup();
1660
// get the wsEndpoint

0 commit comments

Comments
 (0)