I started today to migrate our web components to lit-html but when i tried to run the first test i get the following error message
SyntaxError: Cannot use import statement outside a module
> 1 | import {LitElement, html, css, svg} from "lit";
| ^
2 | import {property} from 'lit/decorators.js';
3 |
with a pointer to lit\index.js
from searching the web i learned that i need to configure jest so lit will get precompiled by babel but so far no solution i found worked for me.
i made my .babelrc
to a babel.config.js
with following config:
module.exports = {
"presets": [
[
"@babel/preset-env"
]
],
"plugins": [
["transform-react-jsx", {"pragma": "h"}],
"inline-svg"
]
}
(the transform-react-js option is needed since we have a few wrapper components )
jest.config.js
has following options set:
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jest-environment-jsdom',
roots: [
'<rootDir>/src',
],
collectCoverageFrom: [
'<rootDir>/src/**/*.tsx',
'<rootDir>/src/**/*.ts',
'!<rootDir>/src/test/**',
'!<rootDir>/src/**/*.d.ts',
],
coverageReporters: [
'text-summary',
'html',
'lcov',
'clover',
],
coverageDirectory: './coverage/',
collectCoverage: true,
moduleDirectories: [
'src',
'node_modules',
],
moduleFileExtensions: [
'js',
'ts',
'tsx',
],
moduleNameMapper: {
'\\.(css)$': '<rootDir>/src/test/stubs/css.js',
},
snapshotSerializers: [
'enzyme-to-json/serializer',
],
snapshotResolver: '<rootDir>/src/test/snapshot-resolver.js',
globals: {
'ts-jest': {
tsconfig: {
allowJs: true,
},
},
},
setupFilesAfterEnv: [
'<rootDir>/src/test/jest-setup.js',
],
transform: {"^.+\\.(js|ts)x?$": 'ts-jest'},
transformIgnorePatterns: ['node_modules/(?!(lit-element|lit-html|lit|@lit)/)'],
};
i tried a few other options for transformIgnorePatterns
including passing every lit package seperately in an array with no success
did i miss an important option?