-
Notifications
You must be signed in to change notification settings - Fork 43
Description
This package is not declared as ES6 module in package.json:
{
"name": "@patternslib/patternslib",
"type": "module",
...
}We still use CommonJS require in the webpack config, in jest config, etc.
It would not only be more convenient to unify everything and be able to use ES6 import statements everywhere - this is now even becoming a problem.
The latest Jest releases seems to expect the module under test to be declared as ES6 module, otherwise it complains with this:
FAIL src/pat/subform/subform.test.js
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation, specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
Patterns/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_con_af8c4dab4e47dfe0b1295a84669ca747/node_modules/@patternslib/dev/jest/setup-tests.js:2
import "regenerator-runtime/runtime";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1318:40)
After declaring @patternslib/patternslib as module, it complains with that:
thet@thes:Patterns$ jest src/
ReferenceError: require is not defined
at file:///Patterns/jest.config.js:1:14
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:400:35)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:427:47)
at loadESMFromCJS (node:internal/modules/cjs/loader:1561:24)
at Module._compile (node:internal/modules/cjs/loader:1712:5)
at Object..js (node:internal/modules/cjs/loader:1895:10)
at Module.load (node:internal/modules/cjs/loader:1465:32)
at Function._load (node:internal/modules/cjs/loader:1282:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
After extending the transformIgnorePatterns from jest.config.js like that (done in a local checkout of @patternslib/dev and yarn-linked into Patterns):
transformIgnorePatterns: [
"jest.config.js",
"/node_modules/(?!@patternslib/)(?!@plone/)(?!preact/)(?!screenfull/).+\\.[t|j]sx?$",
],I could run the tests but then it fails due to a lot of other breaking changes in Jest, which is a different story.
A ES6 conversion needs to be done for all the Patternslib packages.
If we would have patternslib-core this would come in handy, as we currently have a dispute on version names and this would definetly be a breaking change without any user (ideally) noticing it... Different story again.