clet icon indicating copy to clipboard operation
clet copied to clipboard

Does not work with Jest in CommonJS

Open LiKang6688 opened this issue 3 years ago • 5 comments

Details:

    .../node_modules/.pnpm/[email protected]/node_modules/clet/lib/runner.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { EOL } from 'os';
                                                                                      ^^^^^^

    SyntaxError: Cannot use import statement outside a module

LiKang6688 avatar Oct 18 '22 16:10 LiKang6688

could you provide a mini example repository?

btw: plan to rewrite clet with ts then build esm and cjs, but honestly I don't have time recently.

atian25 avatar Oct 19 '22 02:10 atian25

Was running into this as well. I had to force Jest to transform a bunch of dependencies (including clet), and patch clet to not use import.meta.

Mrtenz avatar Mar 22 '23 15:03 Mrtenz

@Mrtenz what do you mean you "patched" clet to not use import.meta? What doesn't the Babel transform @babel/plugin-syntax-import-meta work?

Sweetog avatar Jul 01 '23 06:07 Sweetog

@Sweetog We're not using Babel to run tests, so we can't use that. Instead, I created a Yarn patch:

https://github.com/MetaMask/snaps/blob/1a0dd93ba3841c387bf6803d1d154d369bc4e45a/.yarn/patches/clet-npm-1.0.1-8523231bdc.patch#L36

This line seemed to be unnecessary, and it works fine without.

Mrtenz avatar Jul 01 '23 09:07 Mrtenz

What are the ergonomics of best practices to clet to run in continuous integration environment? I do not need to use Jest, but I need to a "test runner" if you will. I could run a process that executes imports but than I might need to manage parallel tests running and consolidate assertion output and errors etc.

I definitely am having troubles using clet with my CLI and Jest because of ESM versus CommonJs mixture.

I have tried a plethora of babel-jest and babel transforms and just cannot get around the import.metaissue

Sweetog avatar Jul 03 '23 19:07 Sweetog