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

Runner is not a constructor #12

Open
Emobe opened this issue Dec 10, 2022 · 4 comments
Open

Runner is not a constructor #12

Emobe opened this issue Dec 10, 2022 · 4 comments

Comments

@Emobe
Copy link

Emobe commented Dec 10, 2022

I get complaints that the runner is not a constructor when trying to use this library in a couple of projects.

Here is my config in one of my projects

import type { Config } from 'jest';

export default async (): Promise<Config> => ({
  verbose: true,
  runner: "@kayahr/jest-electron-runner",
  testEnvironment: "@kayahr/jest-electron-runner/environment",
  preset: 'ts-jest/presets/default-esm',
  transform: {
    '^.+\\.m?[tj]s?$': ['ts-jest', { useESM: true }],
  },
  moduleNameMapper: {
    '^(\\.{1,2}/.*)\\.(m)?js$': '$1',
  },
  testRegex: '(/tests/.*|(\\.|/)(test|spec))\\.(m)?ts$',
  coverageDirectory: 'coverage',
  collectCoverageFrom: [
    'src/**/*.ts',
    'src/**/*.mts',
    '!src/**/*.d.ts',
    '!src/**/*.d.mts',
  ],
});

The other project this happens in does not use ESM and still gets an issue of no constructor

@Emobe
Copy link
Author

Emobe commented Dec 15, 2022

Also I get this error sometimes.

Error: Cannot find module 'node:fs'
Require stack:
- /home/emobe/projects/pixijs/node_modules/@kayahr/jest-electron-runner/lib/main/electron/runTest.js
- /home/emobe/projects/pixijs/node_modules/@kayahr/jest-electron-runner/lib/main/electron/rpc/JestWorkerRPC.js
- /home/emobe/projects/pixijs/node_modules/@kayahr/jest-electron-runner/lib/main/electron/electron_process_injected_code.js
- /home/emobe/projects/pixijs/node_modules/electron/dist/resources/default_app.asar/main.js
- 
    at Module._resolveFilename (internal/modules/cjs/loader.js:887:15)
    at Function.n._resolveFilename (electron/js2c/browser_init.js:261:1128)
    at Module._load (internal/modules/cjs/loader.js:732:27)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
    at Module.require (internal/modules/cjs/loader.js:959:19)
    at require (internal/modules/cjs/helpers.js:88:18)

@kayahr
Copy link
Owner

kayahr commented Dec 15, 2022

Please do not report different problems in the same issue. I moved the second problem to #13

@kayahr
Copy link
Owner

kayahr commented Dec 15, 2022

@Emobe Can you please create a minimal but complete example project on Github with a simple unit test that does nothing so I can reproduce the problem by running npm test or something similiar? Looks like you are using ts-jest and maybe you are using even more esoteric stuff which may conflict with jest-electron-runner. Maybe with a complete project to reproduce the problem I can find a solution. or at least identify which part is responsible for the problem.

The complete error message with stack trace would also be useful.

@unional
Copy link

unional commented Feb 21, 2023

I'm suspecting this is related to CJS vs ESM.

I'm getting this error in my project:

        TypeError: (0 , json_bigint_1.default) is not a function                                                        
                                                                                                                        
          1 | import JSONbig from 'json-bigint'                                                                         
          2 |                                                                                                           
        > 3 | export const json = JSONbig({ useNativeBigInt: true })

When I look at the trace, it is loading the cjs version of the code (e.g. ./cjs/json.js) instead of the ESM version which I configure ts-jest to use.

The difference here is about esModuleInterop, which for the ESM code, that flag is off, while for CJS code, that flag needs to be on.

Once I change the ts-jest to load a config with esModuleInterop: true, the test goes through.

At this point, I don't know where the problem is. The same tests runs fine in Node.js and jsdom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants