Skip to content

Commit

Permalink
test: improve test coverage by fixing coverage pattern & remove unused
Browse files Browse the repository at this point in the history
Related to #127
  • Loading branch information
GerkinDev committed Jul 19, 2022
1 parent 47bf765 commit bc588b2
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 111 deletions.
68 changes: 39 additions & 29 deletions jest.config.base.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
const { resolve } = require( 'path' );
const { resolve, relative } = require( 'path' );

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
const baseConfig = {
/**
* @param package - Package name
* @returns {import('ts-jest/dist/types').InitialOptionsTsJest} - Opts.
*/
const baseConfig = package => ( {
preset: 'ts-jest',
testEnvironment: 'node',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
tsconfig: `<rootDir>/packages/${package}/tsconfig.spec.json`,
},
},
moduleNameMapper: {
'^#plugintestbed$': resolve( __dirname, './packages/plugintestbed' ),
'^@knodes/typedoc-(plugin.*)$': resolve( __dirname, './packages/$1/src' ),
'^#plugintestbed$': resolve( __dirname, './packages/plugintestbed/src' ),
},
setupFilesAfterEnv: [ 'jest-extended/all' ],
watchPathIgnorePatterns: [ '<rootDir>/__tests__/mock-fs/' ],
};
watchPathIgnorePatterns: [ '<rootDir>/.*/__tests__/mock-fs/.*/docs' ],
modulePathIgnorePatterns: [ '<rootDir>/.*/__tests__/mock-fs/.*/' ],
} );
const anyExt = '.{c,m,}{t,j}s{x,}';
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest[]} */
module.exports = {
anyExt,
projects: [
{
...baseConfig,
displayName: {
name: 'unit',
color: 'blue',
module.exports = projectDir => {
const package = relative( resolve( __dirname, 'packages' ), projectDir );
const base = baseConfig( package );
return {
rootDir: resolve( __dirname, 'packages', package ),
projects: [
{
...base,
displayName: {
name: 'unit',
color: 'blue',
},
testMatch: [ `<rootDir>/packages/${package}/src/**/*.spec${anyExt}` ],
},
testMatch: [ `<rootDir>/src/**/*.spec${anyExt}` ],
},
{
...baseConfig,
displayName: {
name: 'integration',
color: 'green',
{
...base,
displayName: {
name: 'integration',
color: 'green',
},
testMatch: [ `<rootDir>/packages/${package}/__tests__/integration/**/*.spec${anyExt}` ],
},
testMatch: [ `<rootDir>/__tests__/integration/**/*.spec${anyExt}` ],
},
],
collectCoverageFrom: [
'src/**',
`!**/*.spec${anyExt}`,
],
],
collectCoverageFrom: [
'packages/*/src/**',
`!**/*.spec${anyExt}`,
],
};
};
module.exports.anyExt = anyExt;
14 changes: 3 additions & 11 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@ const { resolve } = require( 'path' );

const { isString } = require( 'lodash' );

const { anyExt } = require( './jest.config.base' );
const { getProjects } = require( './tools/utils' );

const projects = getProjects();
const maxNameLength = Math.max( ...projects.map( p => p.name.length ) );
module.exports = {
collectCoverageFrom: [
'**/src/**',
`!**/index${anyExt}`,
'!**/__tests__/**',
`!**/*.spec${anyExt}`,
],
// ...baseConfig,
projects: projects
.map( ( { path, ...other } ) => {
const jestConfigPath = [ 'jest.workspace.config.js', 'jest.config.js' ]
Expand All @@ -24,12 +16,12 @@ module.exports = {
return { ...other, path, jestConfigPath };
} )
.filter( ( { jestConfigPath } ) => isString( jestConfigPath ) )
.map( ( { jestConfigPath, path, name } ) => {
.map( ( { jestConfigPath, name } ) => {
const config = require( jestConfigPath );
if( config.projects ){
return config.projects.map( pp => ( { name, jestConfig: { ...pp, rootDir: path }} ) );
return config.projects.map( pp => ( { name, jestConfig: { ...pp }} ) );
} else {
return { name, jestConfig: { ...config, rootDir: path }};
return { name, jestConfig: { ...config }};
}
} )
.flat( 1 )
Expand Down
8 changes: 1 addition & 7 deletions packages/plugin-code-blocks/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const { resolve } = require( 'path' );

const base = require( '../../jest.config.base' );
const base = require( '../../jest.config.base' )( __dirname );
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
...base,
Expand All @@ -11,8 +9,4 @@ module.exports = {
setupFilesAfterEnv: [ ...base.projects[1].setupFilesAfterEnv, '@testing-library/jest-dom' ],
},
],
watchPathIgnorePatterns: [
...( base.watchPathIgnorePatterns ?? [] ),
resolve( __dirname, '__tests__/integration/mock-fs/.*' ),
],
};

This file was deleted.

2 changes: 0 additions & 2 deletions packages/plugin-code-blocks/src/models/reflections/index.ts

This file was deleted.

This file was deleted.

8 changes: 1 addition & 7 deletions packages/plugin-monorepo-readmes/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const { resolve } = require( 'path' );

const base = require( '../../jest.config.base' );
const base = require( '../../jest.config.base' )( __dirname );
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
...base,
Expand All @@ -11,8 +9,4 @@ module.exports = {
setupFilesAfterEnv: [ ...base.projects[1].setupFilesAfterEnv, '@testing-library/jest-dom' ],
},
],
watchPathIgnorePatterns: [
...( base.watchPathIgnorePatterns ?? [] ),
resolve( __dirname, '__tests__/integration/mock-fs/.*' ),
],
};
8 changes: 1 addition & 7 deletions packages/plugin-pages/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const { resolve } = require( 'path' );

const base = require( '../../jest.config.base' );
const base = require( '../../jest.config.base' )( __dirname );
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
...base,
Expand All @@ -11,8 +9,4 @@ module.exports = {
setupFilesAfterEnv: [ ...base.projects[1].setupFilesAfterEnv, '@testing-library/jest-dom' ],
},
],
watchPathIgnorePatterns: [
...( base.watchPathIgnorePatterns ?? [] ),
resolve( __dirname, '__tests__/integration/mock-fs/.*' ),
],
};
8 changes: 1 addition & 7 deletions packages/plugintestbed/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const { resolve } = require( 'path' );

const base = require( '../../jest.config.base' );
const base = require( '../../jest.config.base' )( __dirname );
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
...base,
Expand All @@ -11,8 +9,4 @@ module.exports = {
setupFilesAfterEnv: [ ...base.projects[1].setupFilesAfterEnv, '@testing-library/jest-dom' ],
},
],
watchPathIgnorePatterns: [
...( base.watchPathIgnorePatterns ?? [] ),
resolve( __dirname, '__tests__/integration/mock-fs/.*' ),
],
};
8 changes: 1 addition & 7 deletions packages/pluginutils/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const { resolve } = require( 'path' );

const base = require( '../../jest.config.base' );
const base = require( '../../jest.config.base' )( __dirname );
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
...base,
Expand All @@ -14,8 +12,4 @@ module.exports = {
setupFilesAfterEnv: [ ...base.projects[1].setupFilesAfterEnv, '@testing-library/jest-dom' ],
},
],
watchPathIgnorePatterns: [
...( base.watchPathIgnorePatterns ?? [] ),
resolve( __dirname, '__tests__/integration/mock-fs/.*' ),
],
};
6 changes: 0 additions & 6 deletions tools/proto/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { resolve } = require( 'path' );

const base = require( '../../jest.config.base' );
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
Expand All @@ -11,8 +9,4 @@ module.exports = {
setupFilesAfterEnv: [ ...base.projects[1].setupFilesAfterEnv, '@testing-library/jest-dom' ],
},
],
watchPathIgnorePatterns: [
...( base.watchPathIgnorePatterns ?? [] ),
resolve( __dirname, '__tests__/integration/mock-fs/.*' ),
],
};

0 comments on commit bc588b2

Please sign in to comment.