nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.27k stars 2.32k forks source link

It looks like if test are executed twice. #7424

Closed jsanz1209 closed 2 years ago

jsanz1209 commented 2 years ago

Hello, does it happen to anyone that it seems as if the tests were executed twice?

I mean, I have 1289 tests in my project and in console it appears that 2578 were executed., (In the screenshot below I have taken the screenshot almost at the end of the execution, it shows 2551 of these) but when the final report is being generated, it appears the 1289 tests.

I have updated Angular (12.2.10) , Jest and Nx to their latest version.

My package.json is as follows:

{ "name": "frontend", "version": "1.0.2", "license": "MIT", "scripts": { "ng": "nx", "nx": "nx", "start": "nx serve", "build": "ng build", "build:prod": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --configuration production --aot --build-optimizer && gzipper compress ./www", "build:test": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --configuration production --aot --build-optimizer --configuration=test && gzipper compress ./www", "test": "node --max-old-space-size=8192 --expose-gc node_modules/jest/bin/jest.js --coverage --verbose false --logHeapUsage --ci", "test-watch": "jest --watchAll --coverage --verbose false --logHeapUsage --maxWorkers=11", "lint": "nx workspace-lint && ng lint", "e2e": "ng e2e", "affected:apps": "nx affected:apps", "affected:libs": "nx affected:libs", "affected:build": "nx affected:build", "affected:e2e": "nx affected:e2e", "affected:test": "nx affected:test", "affected:lint": "nx affected:lint", "affected:dep-graph": "nx affected:dep-graph", "affected": "nx affected", "format": "nx format:write", "format:write": "nx format:write", "format:check": "nx format:check", "update": "ng update @nrwl/workspace", "workspace-schematic": "nx workspace-schematic", "dep-graph": "nx dep-graph", "help": "nx help", "postinstall": "ngcc", "compodoc": "compodoc -p ./tsconfig.compodoc.json -s", "build-webpack-analyzer": "ng build --stats-json", "run-webpack-analyzer": "webpack-bundle-analyzer www/stats.json", "sonar-linux": "./node_modules/sonar-scanner/bin/sonar-scanner", "sonar-windows": ".\node_modules\sonar-scanner\bin\sonar-scanner" }, "author": "José Ignacio Sanz García", "private": true, "dependencies": { "@angular-material-components/datetime-picker": "^5.1.0", "@angular/animations": "12.2.10", "@angular/cdk": "12.2.10", "@angular/common": "12.2.10", "@angular/compiler": "12.2.10", "@angular/core": "12.2.10", "@angular/elements": "12.2.10", "@angular/forms": "12.2.10", "@angular/localize": "^12.2.10", "@angular/material": "12.2.10", "@angular/platform-browser": "12.2.10", "@angular/platform-browser-dynamic": "12.2.10", "@angular/platform-server": "12.2.10", "@angular/pwa": "^0.1102.11", "@angular/router": "12.2.10", "@angular/service-worker": "12.2.10", "@compodoc/compodoc": "^1.1.13", "@ctrl/ngx-codemirror": "^4.1.1", "@fullcalendar/core": "^5.6.0", "@ng-select/ng-select": "^6.1.0", "@ngrx/component-store": "12.5.0", "@ngrx/effects": "12.5.0", "@ngrx/entity": "12.5.0", "@ngrx/router-store": "12.5.0", "@ngrx/store": "12.5.0", "@ngrx/store-devtools": "12.5.0", "@ngx-translate/core": "^13.0.0", "@ngx-translate/http-loader": "^6.0.0", "@nrwl/eslint-plugin-nx": "12.10.0", "@nrwl/workspace": "12.10.0", "@typescript-eslint/eslint-plugin": "^4.22.1", "@typescript-eslint/parser": "^4.22.1", "chart.js": "^2.9.4", "classlist.js": "^1.1.20150312", "codemirror": "^5.61.0", "crypto-js": "^4.0.0", "eslint-plugin-cypress": "^2.11.2", "file-saver": "^2.0.5", "fs": "0.0.1-security", "google-libphonenumber": "^3.2.21", "html2canvas": "^1.0.0-rc.7", "html2pdf.js": "^0.10.1", "jest-canvas-mock": "^2.3.1", "jest-leak-detector": "^27.0.6", "jsdom": "^16.6.0", "jspdf": "^2.3.1", "jspdf-autotable": "^3.5.14", "lodash": "^4.17.21", "mammoth": "^1.4.18", "ng-mocks": "^12.5.0", "ngx-material-file-input": "^2.1.1", "ngx-swiper-wrapper": "^10.0.0", "npm": "^7.23.0", "posthtml-beautify": "^0.7.0", "primeicons": "^4.1.0", "primeng": "^11.4.0", "project": "^0.1.6", "properties-parser": "^0.3.1", "quill": "^1.3.7", "rxjs": "^6.6.7", "screenfull": "^5.1.0", "textarea-caret": "^3.1.0", "to-px": "^1.1.0", "tslib": "^2.2.0", "weak-napi": "^2.0.2", "web-animations-js": "^2.3.2", "xlsx": "^0.17.1", "zone.js": "0.11.4" }, "devDependencies": { "@angular-devkit/build-angular": "12.2.10", "@angular-devkit/schematics": "^12.2.10", "@angular-eslint/eslint-plugin": "12.3.1", "@angular-eslint/eslint-plugin-template": "12.3.1", "@angular-eslint/template-parser": "12.3.1", "@angular/cli": "12.2.10", "@angular/compiler-cli": "12.2.10", "@angular/language-service": "12.2.10", "@ngrx/schematics": "12.5.0", "@nrwl/angular": "12.10.0", "@nrwl/cypress": "12.10.0", "@nrwl/jest": "12.10.0", "@types/chart.js": "^2.9.31", "@types/crypto-js": "^4.0.1", "@types/google-libphonenumber": "^7.4.21", "@types/html2canvas": "0.0.36", "@types/jest": "27.0.2", "@types/jspdf": "^1.3.3", "@types/lodash": "^4.14.168", "@types/textarea-caret": "^3.0.0", "@types/to-px": "^1.1.1", "cypress": "^7.2.0", "eslint": "^7.25.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-prettier": "^3.4.0", "gzipper": "^4.5.0", "html-docx-js-typescript": "^0.1.5", "jest": "27.2.3", "jest-junit": "^12.2.0", "jest-preset-angular": "10.0.1", "jest-sonar": "^0.2.12", "posthtml": "^0.15.2", "prettier": "2.3.1", "protractor": "^7.0.0", "sonar-scanner": "^3.1.0", "string.prototype.replaceall": "^1.0.5", "swiper": "^6.5.9", "ts-jest": "27.0.5", "ts-loader": "^9.1.1", "ts-node": "^9.1.1", "typescript": "4.3.5", "webpack-bundle-analyzer": "^4.4.0", "webpack-cli": "^4.6.0" }, "browser": { "crypto": false } }

The base jest.config.js (the one in the root) is as follows:

module.exports = { testMatch: ['/+(*.)+(spec|test).+(ts|js)?(x)'], transform: { '^.+\.(ts|js|html)$': 'ts-jest', }, resolver: '@nrwl/jest/plugins/resolver', moduleFileExtensions: ['ts', 'js', 'html'], coverageDirectory: '/coverage', reporters: ['default', 'jest-junit', ['jest-sonar', { outputDirectory: './', outputName: 'test-report.xml', reportedFilePath: 'absolute' }], ], setupFiles: [ '/test-setup.ts' ], coverageReporters: ["json", "lcov", "clover", "text", "text-summary", "cobertura"], collectCoverageFrom: [ "*/.ts", "!/node_modules/", "!/vessel.ts", "!/*.module.ts", "!/routes.ts", "!/paths.ts", "!*/.token.ts", "!/*.collection.ts", "!/*.enum.ts", "!*/.model.ts", "!/.mock.ts", "!/polyfills.ts", "!/main.ts", "!/index.ts", "!/help*.ts", "!/admin-help/", "!/*.environment.ts", "!*/environment.ts", "!/typings.d.ts" ], projects: [ '/libs/core', '/libs/menu-ui', '/libs/shared', '/apps/ioms-main', '/apps/auth', '/apps/side-menu', '/apps/dashboard', '/apps/messaging', '/apps/administration', '/apps/data-request', '/apps/vessels', '/apps/compliance-data' ] };

My jest-preset.js is the following:

const nxPreset = require('@nrwl/jest/preset');

nxPreset.transform = { '^.+\.(ts|js|html)$': 'jest-preset-angular' }; module.exports = { ...nxPreset };

the test-setup.ts that is in the root is the following: import 'jest-canvas-mock'; import '@frontend/core/mocks/libs/rxjs.mock';

console.warn = (message: string) => { if(!message.includes('Could not find Angular Material core theme. Most Material components may not work as expected. For more info refer to the theming guide: https://material.angular.io/guide/theming')) { console.warn(message); } };

the jest.config.js files of the different projects are as the following:

module.exports = { displayName: 'core', name: 'core', coverageDirectory: '../../coverage/libs/core', preset: '../../jest.preset.js', setupFiles: ['./../../test-setup.ts'], setupFilesAfterEnv: ['/src/test-setup.ts'], globals: { 'ts-jest': { tsconfig: '/tsconfig.spec.json', stringifyContentPathRegex: '\.(html|svg)$' }, }, snapshotSerializers: [ 'jest-preset-angular/build/serializers/no-ng-attributes', 'jest-preset-angular/build/serializers/ng-snapshot', 'jest-preset-angular/build/serializers/html-comment', ] };

What could be happening?

Capture

Capture2

Thanks in advance.

FrozenPandaz commented 2 years ago

Can you replicate this on the Nx Examples repo?

There are 32 tests there... if you put a for loop around a test suite, you should be able to emulate 1000 tests or so... I only see it count up to 1000 :confused: Could you provide a repo that would helps us reproduce this?

jsanz1209 commented 2 years ago

Hi @FrozenPandaz! Thanks for your answer.

I can't share my repository due to confidencial issue, but I could replicate this on Nx Example Repo, but only adding another project, for example, currently the repo only have one angular project (product), I added another project (order), so in total I have 35 tests and I could watch almost 64 tests while jest was executing.

The command that I executed for replicate this was jest --coverage

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.