Skip to content

Commit

Permalink
feat: prepare jest coverage support
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed Jun 20, 2023
1 parent cfc691b commit c9ab5a3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/node-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Vagrantfile
/config/config-autotest-backup.php
/config/autoconfig.php
clover.xml
/coverage

# Tests - dependencies
tests/acceptance/vendor/
Expand Down
48 changes: 32 additions & 16 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,50 @@ const ignorePatterns = [

const config: Config = {
testMatch: ['<rootDir>/**/*.(spec|test).(ts|js)'],
modulePathIgnorePatterns: [
'<rootDir>/apps2/',
'<rootDir>/apps-extra/',
],
transformIgnorePatterns: [
'node_modules/(?!(' + ignorePatterns.join('|') + ')/)',
],
clearMocks: true,
collectCoverageFrom: [
'<rootDir>/**/*.{js,vue}',
],

clearMocks: true,
setupFilesAfterEnv: ['<rootDir>/__tests__/jest-setup.ts'],

testEnvironment: 'jest-environment-jsdom',
preset: 'ts-jest/presets/js-with-ts',

// Allow mocking svg files
moduleDirectories: ['node_modules', '<rootDir>/'],
moduleNameMapper: {
'^.+\\.svg(\\?raw)?$': '<rootDir>/__mocks__/svg.js',
},
roots: [
'<rootDir>/__mocks__',
'<rootDir>/__tests__',
'<rootDir>/apps',
'<rootDir>/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: [
'<rootDir>/**/*.{ts,js,vue}',
'!**/node_modules/**',
'!**/l10n/**',
'!**/logger.{ts,js}',
],
coveragePathIgnorePatterns: [
'<rootDir>/__mocks__/',
'<rootDir>/__tests__/',
],

// Allow mocking svg files
moduleNameMapper: {
'^.+\\.svg(\\?raw)?$': '<rootDir>/__mocks__/svg.js',
},
modulePathIgnorePatterns: [
'<rootDir>/apps2/',
'<rootDir>/apps-extra/',
],
}

export default config
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down

0 comments on commit c9ab5a3

Please sign in to comment.