diff --git a/.github/workflows/node-tests.yml b/.github/workflows/node-tests.yml index a3710249866ee..ee5d615acc914 100644 --- a/.github/workflows/node-tests.yml +++ b/.github/workflows/node-tests.yml @@ -25,8 +25,8 @@ jobs: uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 id: versions with: - fallbackNode: '^12' - fallbackNpm: '^6' + fallbackNode: '^16' + fallbackNpm: '^7' test: runs-on: ubuntu-latest @@ -50,6 +50,15 @@ jobs: - name: Test run: npm run test + # Waiting for https://github.com/jestjs/jest/pull/14207 + # - name: Test and process coverage + # run: npm run test:coverage + + # - name: Collect coverage + # uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 + # with: + # files: ./coverage/lcov.info + jsunit: runs-on: ubuntu-latest needs: versions diff --git a/.gitignore b/.gitignore index de380d992bb10..e05e79eec6dc5 100644 --- a/.gitignore +++ b/.gitignore @@ -154,6 +154,7 @@ Vagrantfile /config/config-autotest-backup.php /config/autoconfig.php clover.xml +/coverage # Tests - dependencies tests/acceptance/vendor/ diff --git a/jest.config.ts b/jest.config.ts index 3743203324216..8594e60c1c751 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -37,34 +37,50 @@ const ignorePatterns = [ const config: Config = { testMatch: ['/**/*.(spec|test).(ts|js)'], - modulePathIgnorePatterns: [ - '/apps2/', - '/apps-extra/', - ], - transformIgnorePatterns: [ - 'node_modules/(?!(' + ignorePatterns.join('|') + ')/)', - ], - clearMocks: true, - collectCoverageFrom: [ - '/**/*.{js,vue}', - ], + clearMocks: true, setupFilesAfterEnv: ['/__tests__/jest-setup.ts'], testEnvironment: 'jest-environment-jsdom', preset: 'ts-jest/presets/js-with-ts', - // Allow mocking svg files - moduleDirectories: ['node_modules', '/'], - moduleNameMapper: { - '^.+\\.svg(\\?raw)?$': '/__mocks__/svg.js', - }, + roots: [ + '/__mocks__', + '/__tests__', + '/apps', + '/core', + ], transform: { // process `*.js` files with `babel-jest` '^.+\\.js$': 'babel-jest', '^.+\\.vue$': '@vue/vue2-jest', }, + transformIgnorePatterns: [ + 'node_modules/(?!(' + ignorePatterns.join('|') + ')/)', + ], + + // Waiting for https://github.com/jestjs/jest/pull/14207 + // collectCoverageFromTestedOnly: true, + collectCoverageFrom: [ + '/**/*.{ts,js,vue}', + '!**/node_modules/**', + '!**/l10n/**', + '!**/logger.{ts,js}', + ], + coveragePathIgnorePatterns: [ + '/__mocks__/', + '/__tests__/', + ], + + // Allow mocking svg files + moduleNameMapper: { + '^.+\\.svg(\\?raw)?$': '/__mocks__/svg.js', + }, + modulePathIgnorePatterns: [ + '/apps2/', + '/apps-extra/', + ], } export default config diff --git a/package.json b/package.json index 5e58a7f7ee328..78367496da875 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "lint:fix": "eslint 'apps/*/src/**/*.{vue,js}' 'core/src/**/*.{vue,js}' --fix", "test": "jest", "test:watch": "jest --watch", + "test:coverage": "jest --coverage", "test:jsunit": "karma start tests/karma.config.js --single-run", "sass": "sass --style compressed --load-path core/css core/css/ $(for cssdir in $(find apps -mindepth 2 -maxdepth 2 -name \"css\"); do if ! $(git check-ignore -q $cssdir); then echo -n \"$cssdir \"; fi; done)", "sass:watch": "sass --watch --load-path core/css core/css/ $(for cssdir in $(find apps -mindepth 2 -maxdepth 2 -name \"css\"); do if ! $(git check-ignore -q $cssdir); then echo -n \"$cssdir \"; fi; done)",