-
Notifications
You must be signed in to change notification settings - Fork 764
Clarity v5 fails to run Jest tests in ESM #6310
Comments
Any update on this? We are still sitting on Clarity v4 and have a big test base we can't simply convert to Karma tests. I'm glad to help with investigating, as I currently don't see any other way forward with clarity. |
Given this is v5, it may or may not be related to the issues listed in #5672 Most folks have solved this by updating/customizing their Jest config to not try to transform the Clarity Core ESM modules into Jest's custom CommonJS modules. This is not something we will have the cycles to investigate deeply in the immediate future. So if you are willing to dig deeper, we would appreciate it. |
For anyone else stumbling on this issue or #5672, I just quickly want to note what worked for me. On a brand new Angular 13 application, I've got tests running with # set up a new Angular application
npx @angular/cli@13 new
# replace Karma with Jest, following the steps from https://www.npmjs.com/package/@angular-builders/jest
npm remove karma karma-chrome-launcher karma-coverage-istanbul-reporter karma-jasmine karma-jasmine-html-reporter
rm ./karma.conf.js ./src/test.ts
npm i -D jest @types/jest @angular-builders/jest
In the /* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.json",
"compilerOptions": {
"esModuleInterop": true,
"outDir": "./out-tsc/spec",
"types": [
"jest"
],
"emitDecoratorMetadata": true
},
"files": [
"src/polyfills.ts"
],
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
} I had to adjust the /** @type {import("@jest/types").Config.InitialOptions} */
module.exports = {
transformIgnorePatterns: ["node_modules/(?!(@cds|@lit|lit|ramda|.*\\.mjs$))"],
}; Before running the tests, ensure I've got a "ClarityModule", which is imported both in my AppModule and the test module, looking as follows: import { NgModule } from "@angular/core";
import { CdsModule } from "@cds/angular";
import "@cds/core/checkbox/register.js";
@NgModule({
imports: [CdsModule],
exports: [CdsModule],
})
export class ClarityModule {} These are the contents of my {
"name": "todo-frontend",
"version": "0.0.0",
"scripts": {
"postinstall": "ngcc",
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"test:cov": "ng test --coverage",
"lint": "ng lint"
},
"private": true,
"dependencies": {
"@angular/animations": "~13.2.0",
"@angular/common": "~13.2.0",
"@angular/compiler": "~13.2.0",
"@angular/core": "~13.2.0",
"@angular/forms": "~13.2.0",
"@angular/platform-browser": "~13.2.0",
"@angular/platform-browser-dynamic": "~13.2.0",
"@angular/router": "~13.2.0",
"@cds/angular": "^5.6.4",
"@cds/city": "^1.1.0",
"@cds/core": "^5.1.1",
"modern-normalize": "^1.1.0",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-builders/jest": "^13.0.3",
"@angular-devkit/build-angular": "~13.2.6",
"@angular-eslint/builder": "13.1.0",
"@angular-eslint/eslint-plugin": "13.1.0",
"@angular-eslint/eslint-plugin-template": "13.1.0",
"@angular-eslint/schematics": "13.1.0",
"@angular-eslint/template-parser": "13.1.0",
"@angular/cli": "~13.2.6",
"@angular/compiler-cli": "~13.2.0",
"@types/jasmine": "~3.10.0",
"@types/jest": "^27.4.1",
"@types/node": "^12.11.1",
"@typescript-eslint/eslint-plugin": "5.11.0",
"@typescript-eslint/parser": "5.11.0",
"eslint": "^8.2.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"jasmine-core": "~4.0.0",
"jest": "^27.5.1",
"karma-coverage": "~2.1.0",
"ng-mocks": "^13.1.1",
"prettier": "^2.5.1",
"prettier-eslint": "^13.0.0",
"typescript": "~4.5.2"
}
} |
Hi there 👋, this is an automated message. To help Clarity keep track of discussions, we automatically lock closed issues after 14 days. Please look for another open issue or open a new issue with updated details and reference this one as necessary. |
Describe the bug
We are in the progress of upgrading from the apparently not supported but supported Clarity v4 (according to https://clarity.design/get-started/support/) to v5. We are using Jest with
jest-preset-angular
I stumbled upon issue #5672 and have the same problem. I tried both of the suggested solutions but I am still getting errors from Clarity code when trying to run unit tests with Jest.
When trying to use the experimental support for VM Modules, I get this error:
I tried using the
transformIgnorePatterns
option with no success as well.How to reproduce
Reproduction Repository: https://github.com/MalteJoe/jest-preset-angular
Specifically this commit: MalteJoe/jest-preset-angular@8e96c1f
jest-preset-angular
Repoexamples/example-app-v12
ng add @clr/angular
ng-mocks
)jest-preset-angular
documentation: https://thymikee.github.io/jest-preset-angular/docs/guides/esm-supportSteps to reproduce the behavior:
Expected behavior
The unit tests should pass.
Versions
Clarity project:
Clarity version:
Framework:
Framework version:
Angular 12
Jest 27
Node v14.17.6
The text was updated successfully, but these errors were encountered: