Skip to content

Commit

Permalink
fix: Clean up and accelerate jest process + coverage integration (#2416)
Browse files Browse the repository at this point in the history
## Proposed change

fix: clean up and accelerate jest process
fix: vscode integration
feat: add coverage generation (with vscode integration)

take a look to
https://app.codecov.io/github/AmadeusITGroup/otter/tree/feature%2Fjest-cleanup
to see CodeCov output

<!--
Please include a summary of the changes and the related issue.
Please also include relevant motivation and context.
-->

## Related issues

<!--
Please make sure to follow the [contribution
guidelines](https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md)
-->

*- No issue associated -*

<!-- * 🐛 Fix #issue -->
<!-- * 🐛 Fix resolves #issue -->
<!-- * 🚀 Feature #issue -->
<!-- * 🚀 Feature resolves #issue -->
<!-- * :octocat: Pull Request #issue -->
  • Loading branch information
kpanot authored Nov 8, 2024
2 parents 2c08899 + ea60094 commit dc80c32
Show file tree
Hide file tree
Showing 159 changed files with 570 additions and 493 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/code-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ on:
NX_CLOUD_ACCESS_TOKEN:
required: false
description: Token to use Nx Cloud token
CODECOV_TOKEN:
required: false
description: Token Report to Codecov

env:
NX_SKIP_NX_CACHE: ${{ inputs.skipNxCache }}
Expand Down Expand Up @@ -70,7 +73,12 @@ jobs:
env:
testCmd: ${{ inputs.affected && format('test:affected --base=remotes/origin/{0}', github.base_ref || github.ref_name) || 'test'}}
NODE_OPTIONS: ${{ runner.os == 'Windows' && '--max_old_space_size=4096' || '' }}
run: yarn ${{ env.testCmd }}
run: yarn ${{ env.testCmd }} --collectCoverage
- name: Upload results to Codecov
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
with:
flags: unittests
token: ${{ secrets.CODECOV_TOKEN }}
- name: Publish tests reports
if: always()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/it-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
NX_CLOUD_ACCESS_TOKEN:
required: false
description: Token to use Nx Cloud token
CODECOV_TOKEN:
required: false
description: Token Report to Codecov

env:
NX_SKIP_NX_CACHE: ${{ inputs.skipNxCache }}
Expand Down Expand Up @@ -106,7 +109,12 @@ jobs:
shell: bash
- name: Test
id: it-tests
run: yarn test-int
run: yarn test-int --collectCoverage
- name: Upload results to Codecov
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
with:
flags: integration
token: ${{ secrets.CODECOV_TOKEN }}
- name: Zip generated app on failure
if: failure() && steps.it-tests.conclusion == 'failure'
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
uses: ./.github/workflows/code-check.yml
secrets:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
needs: [yarn_lock_check]
with:
affected: ${{ github.event_name == 'pull_request' }}
Expand All @@ -94,6 +95,7 @@ jobs:
uses: ./.github/workflows/it-tests.yml
secrets:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
needs: [yarn_lock_check, build]
with:
skipNxCache: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release') }}
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
"typescript.preferences.preferTypeOnlyAutoImports": true,
"jest.jestCommandLine": "yarn jest",
"jest.debugMode": true,
"jest.runMode": "on-save",
"jest.runMode": {
"type": "on-save",
"coverage": true
},
"testing.openTesting": "neverOpen",
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
Expand Down
2 changes: 1 addition & 1 deletion apps/chrome-devtools/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const getJestGlobalConfig = require('../../jest.config.ut').getJestGlobalConfig;

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestGlobalConfig(),
...getJestGlobalConfig(__dirname),
projects: [
'<rootDir>/testing/jest.config.ut.js'
]
Expand Down
5 changes: 3 additions & 2 deletions apps/chrome-devtools/testing/jest.config.ut.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ const path = require('node:path');
const getJestProjectConfig = require('../../../jest.config.ut').getJestProjectConfig;
const rootDir = path.join(__dirname, '..');

const baseConfig = getJestProjectConfig(rootDir, true);

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestProjectConfig(rootDir, true),
...baseConfig,
displayName: require('../package.json').name,
rootDir,
transformIgnorePatterns: ['^.+\\.js$'],
globals: {
chrome: {
Expand Down
2 changes: 1 addition & 1 deletion apps/github-cascading-app/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const getJestGlobalConfig = require('../../jest.config.ut').getJestGlobalConfig;

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestGlobalConfig(),
...getJestGlobalConfig(__dirname),
projects: [
'<rootDir>/testing/jest.config.ut.js'
]
Expand Down
5 changes: 3 additions & 2 deletions apps/github-cascading-app/testing/jest.config.ut.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ const path = require('node:path');
const getJestProjectConfig = require('../../../jest.config.ut').getJestProjectConfig;
const rootDir = path.join(__dirname, '..');

const baseConfig = getJestProjectConfig(rootDir, false);

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestProjectConfig(rootDir, false),
...baseConfig,
displayName: require('../package.json').name,
rootDir
};
2 changes: 1 addition & 1 deletion apps/showcase/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const getJestGlobalConfig = require('../../jest.config.ut').getJestGlobalConfig;

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestGlobalConfig(),
...getJestGlobalConfig(__dirname),
projects: [
'<rootDir>/testing/jest.config.ut.js'
]
Expand Down
5 changes: 3 additions & 2 deletions apps/showcase/testing/jest.config.ut.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ const path = require('node:path');
const getJestProjectConfig = require('../../../jest.config.ut').getJestProjectConfig;
const rootDir = path.join(__dirname, '..');

const baseConfig = getJestProjectConfig(rootDir, true);

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestProjectConfig(rootDir, true),
...baseConfig,
displayName: require('../package.json').name,
rootDir
};
2 changes: 1 addition & 1 deletion apps/vscode-extension/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const getJestGlobalConfig = require('../../jest.config.ut').getJestGlobalConfig;

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestGlobalConfig(),
...getJestGlobalConfig(__dirname),
projects: [
'<rootDir>/testing/jest.config.ut.js'
]
Expand Down
5 changes: 3 additions & 2 deletions apps/vscode-extension/testing/jest.config.ut.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ const path = require('node:path');
const getJestProjectConfig = require('../../../jest.config.ut').getJestProjectConfig;
const rootDir = path.join(__dirname, '..');

const baseConfig = getJestProjectConfig(rootDir, false);

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestProjectConfig(rootDir, false),
...baseConfig,
displayName: require('../package.json').name,
rootDir
};
12 changes: 12 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
codecov:
require_ci_to_pass: false

comment:
layout: "condensed_header, condensed_files, condensed_footer"
behavior: default

component_management:
default_rules:
statuses:
- type: project
target: auto
2 changes: 1 addition & 1 deletion jest.config.it.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const getJestProjectConfig = require('./jest.config.ut').getJestProjectConfig;
*/
module.exports.getJestConfig = (rootDir, options) => ({
...getJestProjectConfig(rootDir, false, options),
rootDir: '..',
setupFilesAfterEnv: null,
testPathIgnorePatterns: [
'<rootDir>/.*/templates/.*'
Expand All @@ -21,5 +20,6 @@ module.exports.getJestConfig = (rootDir, options) => ({
['jest-junit', {outputDirectory: '<rootDir>/dist-test', outputName: 'it-report.xml'}],
'github-actions'
],
coverageReporters: ['cobertura'],
testTimeout: 30 * 60 * 1000
});
19 changes: 12 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const { getJestProjects } = require('@o3r/workspace');
const { getJestGlobalConfig } = require('./jest.config.ut');

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
/**
* Workspace global jest configuration
* Note: It is for IDE Test run and debugging purpose, you may want to run `yarn test` instead
* @type {import('ts-jest/dist/types').JestConfigWithTsJest}
**/
module.exports = {
...getJestGlobalConfig(__dirname),
coverageReporters: undefined,
reporters: undefined,
passWithNoTests: true,
projects: [
...getJestProjects(__dirname),
...getJestProjects(__dirname, 'testing/jest.config.*.{j,t}s')
...getJestProjects(__dirname, 'testing/jest.config.{ut,ut.builders}.{j,t}s')
],
globalSetup: 'jest-preset-angular/global-setup',
reporters: [
'default',
'github-actions'
]
globalSetup: 'jest-preset-angular/global-setup'
};
17 changes: 14 additions & 3 deletions jest.config.ut.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ module.exports.getJestProjectConfig = (rootDir, isAngularSetup, options) => {
return {
preset: 'ts-jest',
setupFilesAfterEnv: ['<rootDir>/testing/setup-jest.ts'],
rootDir: '.',
rootDir,
moduleNameMapper,
modulePathIgnorePatterns: [
'<rootDir>/dist',
'<rootDir>/src/package.json'
],
testMatch: [
'<rootDir>/**/*.spec.ts'
],
testPathIgnorePatterns: [
'<rootDir>/.*/templates/.*',
'\\.it\\.spec\\.ts$'
Expand Down Expand Up @@ -75,13 +78,21 @@ module.exports.getJestProjectConfig = (rootDir, isAngularSetup, options) => {
* Jest configuration that can be set at root level
* @returns {import('ts-jest/dist/types').JestConfigWithTsJest}
*/
module.exports.getJestGlobalConfig = () => {
module.exports.getJestGlobalConfig = (rootDir) => {
return {
testTimeout: 30000,
coverageReporters: ['cobertura'],
reporters: [
'default',
['jest-junit', {outputDirectory: '<rootDir>/dist-test', outputName: 'ut-report.xml'}],
['jest-junit', { outputDirectory: '<rootDir>/dist-test', outputName: 'ut-report.xml' }],
'github-actions'
],
rootDir,
testMatch: [
'<rootDir>/**/*.spec.ts'
],
testPathIgnorePatterns: [
'\\.spec\\.ts$'
]
}
}
18 changes: 13 additions & 5 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,24 @@
"specs": [
"base",
"{projectRoot}/**/*.spec.ts",
"!{projectRoot}/**/*.it.spec.ts",
"{projectRoot}/jest.config.*",
"{projectRoot}/testing/**/*",
"!{projectRoot}/testing/jest.config.it.js",
"{projectRoot}/mocks/**/*",
"{workspaceRoot}/jest.config.ut.js"
"{workspaceRoot}/jest.config.ut.js",
"{workspaceRoot}/codecov.yml"
],
"integration-test": [
"base",
"{projectRoot}/testing/jest.config.it.js",
"{projectRoot}/**/*.it.spec.ts",
"{workspaceRoot}/jest.config.it.js",
"{workspaceRoot}/packages/*/create/src/*.ts",
"!{workspaceRoot}/packages/*/create/src/*.spec.ts",
"{workspaceRoot}/packages/@o3r/test-helpers/src/**/*.ts",
"!{workspaceRoot}/packages/@o3r/test-helpers/src/**/*.spec.ts"
"!{workspaceRoot}/packages/@o3r/test-helpers/src/**/*.spec.ts",
"{workspaceRoot}/codecov.yml"
],
"plugins": [
"base",
Expand Down Expand Up @@ -161,10 +167,12 @@
},
"builders",
"schematics",
"source",
"specs"
],
"outputs": [
"{projectRoot}/dist-test/ut-report.xml"
"{projectRoot}/dist-test/ut-report.xml",
"{projectRoot}/coverage/cobertura-coverage.xml"
],
"options": {
"passWithNoTests": false,
Expand All @@ -191,12 +199,12 @@
},
"source",
"schematics",
"specs",
"integration-test",
"^schematics"
],
"outputs": [
"{projectRoot}/dist-test/it-report.xml"
"{projectRoot}/dist-test/it-report.xml",
"{projectRoot}/coverage/cobertura-coverage.xml"
],
"options": {
"quiet": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/@ama-sdk/client-angular/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const getJestGlobalConfig = require('../../../jest.config.ut').getJestGlobalConf

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestGlobalConfig(),
...getJestGlobalConfig(__dirname),
projects: [
'<rootDir>/testing/jest.config.ut.js',
'<rootDir>/testing/jest.config.ut.builders.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const path = require('node:path');
const getJestProjectConfig = require('../../../../jest.config.ut').getJestProjectConfig;
const rootDir = path.join(__dirname, '..');

const baseConfig = getJestProjectConfig(rootDir, false);

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestProjectConfig(rootDir, false),
...baseConfig,
displayName: `${require('../package.json').name}/builders`,
rootDir,
testPathIgnorePatterns: [
'<rootDir>/.*/templates/.*',
'<rootDir>/src/.*',
'\\.it\\.spec\\.ts$'
...baseConfig.testPathIgnorePatterns,
'<rootDir>/src/.*'
]
};
10 changes: 5 additions & 5 deletions packages/@ama-sdk/client-angular/testing/jest.config.ut.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ const path = require('node:path');
const getJestProjectConfig = require('../../../../jest.config.ut').getJestProjectConfig;
const rootDir = path.join(__dirname, '..');

const baseConfig = getJestProjectConfig(rootDir, false);

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestProjectConfig(rootDir, false),
...baseConfig,
displayName: require('../package.json').name,
rootDir,
fakeTimers: {
enableGlobally: true
},
testPathIgnorePatterns: [
'<rootDir>/.*/templates/.*',
...baseConfig.testPathIgnorePatterns,
'<rootDir>/builders/.*',
'<rootDir>/schematics/.*',
'\\.it\\.spec\\.ts$'
'<rootDir>/schematics/.*'
]
};
2 changes: 1 addition & 1 deletion packages/@ama-sdk/client-beacon/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const getJestGlobalConfig = require('../../../jest.config.ut').getJestGlobalConf

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestGlobalConfig(),
...getJestGlobalConfig(__dirname),
projects: [
'<rootDir>/testing/jest.config.ut.js',
'<rootDir>/testing/jest.config.ut.builders.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const path = require('node:path');
const getJestProjectConfig = require('../../../../jest.config.ut').getJestProjectConfig;
const rootDir = path.join(__dirname, '..');

const baseConfig = getJestProjectConfig(rootDir, false);

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestProjectConfig(rootDir, false),
...baseConfig,
displayName: `${require('../package.json').name}/builders`,
rootDir,
testPathIgnorePatterns: [
'<rootDir>/.*/templates/.*',
'<rootDir>/src/.*',
'\\.it\\.spec\\.ts$'
...baseConfig.testPathIgnorePatterns,
'<rootDir>/src/.*'
]
};
Loading

0 comments on commit dc80c32

Please sign in to comment.