diff --git a/jest.config.base.js b/jest.config.base.js index 58c0d1a6..7562f94a 100644 --- a/jest.config.base.js +++ b/jest.config.base.js @@ -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: '/tsconfig.spec.json', + tsconfig: `/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: [ '/__tests__/mock-fs/' ], -}; + watchPathIgnorePatterns: [ '/.*/__tests__/mock-fs/.*/docs' ], + modulePathIgnorePatterns: [ '/.*/__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: [ `/packages/${package}/src/**/*.spec${anyExt}` ], }, - testMatch: [ `/src/**/*.spec${anyExt}` ], - }, - { - ...baseConfig, - displayName: { - name: 'integration', - color: 'green', + { + ...base, + displayName: { + name: 'integration', + color: 'green', + }, + testMatch: [ `/packages/${package}/__tests__/integration/**/*.spec${anyExt}` ], }, - testMatch: [ `/__tests__/integration/**/*.spec${anyExt}` ], - }, - ], - collectCoverageFrom: [ - 'src/**', - `!**/*.spec${anyExt}`, - ], + ], + collectCoverageFrom: [ + 'packages/*/src/**', + `!**/*.spec${anyExt}`, + ], + }; }; +module.exports.anyExt = anyExt; diff --git a/jest.config.js b/jest.config.js index c73a02e0..4d55ba0d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -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' ] @@ -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 ) diff --git a/packages/plugin-code-blocks/jest.config.js b/packages/plugin-code-blocks/jest.config.js index 351dbe41..941a346c 100644 --- a/packages/plugin-code-blocks/jest.config.js +++ b/packages/plugin-code-blocks/jest.config.js @@ -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, @@ -11,8 +9,4 @@ module.exports = { setupFilesAfterEnv: [ ...base.projects[1].setupFilesAfterEnv, '@testing-library/jest-dom' ], }, ], - watchPathIgnorePatterns: [ - ...( base.watchPathIgnorePatterns ?? [] ), - resolve( __dirname, '__tests__/integration/mock-fs/.*' ), - ], }; diff --git a/packages/plugin-code-blocks/src/models/reflections/code-block-reflection.ts b/packages/plugin-code-blocks/src/models/reflections/code-block-reflection.ts deleted file mode 100644 index 76739efd..00000000 --- a/packages/plugin-code-blocks/src/models/reflections/code-block-reflection.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { DeclarationReflection } from 'typedoc'; - -import { ECodeBlockReflectionKind } from './reflection-kind'; - -export class CodeBlockReflection extends DeclarationReflection { - public constructor( - name: string, - private readonly file: string, - private readonly code: string, - private readonly startLine: number, - private readonly endLine: number, - ){ - super( name, ECodeBlockReflectionKind.CODE_BLOCK as any ); - } -} diff --git a/packages/plugin-code-blocks/src/models/reflections/index.ts b/packages/plugin-code-blocks/src/models/reflections/index.ts deleted file mode 100644 index a3ff786a..00000000 --- a/packages/plugin-code-blocks/src/models/reflections/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './code-block-reflection'; -export * from './reflection-kind'; diff --git a/packages/plugin-code-blocks/src/models/reflections/reflection-kind.ts b/packages/plugin-code-blocks/src/models/reflections/reflection-kind.ts deleted file mode 100644 index 86a452ef..00000000 --- a/packages/plugin-code-blocks/src/models/reflections/reflection-kind.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { ReflectionKind } from 'typedoc'; - -import { reflectionKindUtils } from '@knodes/typedoc-pluginutils'; - -// eslint-disable-next-line @typescript-eslint/no-var-requires -- Get name from package -const ns = require( '../../../package.json' ).name; -/** - * Extends the {@link ReflectionKind} to add custom Page, Menu & Any kinds. - */ -export enum ECodeBlockReflectionKind { - CODE_BLOCK = reflectionKindUtils.addReflectionKind( ns, 'CodeBlock' ), -} -( ECodeBlockReflectionKind as unknown as ReflectionKind ); diff --git a/packages/plugin-monorepo-readmes/jest.config.js b/packages/plugin-monorepo-readmes/jest.config.js index 351dbe41..941a346c 100644 --- a/packages/plugin-monorepo-readmes/jest.config.js +++ b/packages/plugin-monorepo-readmes/jest.config.js @@ -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, @@ -11,8 +9,4 @@ module.exports = { setupFilesAfterEnv: [ ...base.projects[1].setupFilesAfterEnv, '@testing-library/jest-dom' ], }, ], - watchPathIgnorePatterns: [ - ...( base.watchPathIgnorePatterns ?? [] ), - resolve( __dirname, '__tests__/integration/mock-fs/.*' ), - ], }; diff --git a/packages/plugin-pages/jest.config.js b/packages/plugin-pages/jest.config.js index 351dbe41..941a346c 100644 --- a/packages/plugin-pages/jest.config.js +++ b/packages/plugin-pages/jest.config.js @@ -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, @@ -11,8 +9,4 @@ module.exports = { setupFilesAfterEnv: [ ...base.projects[1].setupFilesAfterEnv, '@testing-library/jest-dom' ], }, ], - watchPathIgnorePatterns: [ - ...( base.watchPathIgnorePatterns ?? [] ), - resolve( __dirname, '__tests__/integration/mock-fs/.*' ), - ], }; diff --git a/packages/plugintestbed/jest.config.js b/packages/plugintestbed/jest.config.js index 351dbe41..941a346c 100644 --- a/packages/plugintestbed/jest.config.js +++ b/packages/plugintestbed/jest.config.js @@ -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, @@ -11,8 +9,4 @@ module.exports = { setupFilesAfterEnv: [ ...base.projects[1].setupFilesAfterEnv, '@testing-library/jest-dom' ], }, ], - watchPathIgnorePatterns: [ - ...( base.watchPathIgnorePatterns ?? [] ), - resolve( __dirname, '__tests__/integration/mock-fs/.*' ), - ], }; diff --git a/packages/pluginutils/jest.config.js b/packages/pluginutils/jest.config.js index 60b5353b..06be5622 100644 --- a/packages/pluginutils/jest.config.js +++ b/packages/pluginutils/jest.config.js @@ -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, @@ -14,8 +12,4 @@ module.exports = { setupFilesAfterEnv: [ ...base.projects[1].setupFilesAfterEnv, '@testing-library/jest-dom' ], }, ], - watchPathIgnorePatterns: [ - ...( base.watchPathIgnorePatterns ?? [] ), - resolve( __dirname, '__tests__/integration/mock-fs/.*' ), - ], }; diff --git a/tools/proto/jest.config.js b/tools/proto/jest.config.js index 351dbe41..791b2bfa 100644 --- a/tools/proto/jest.config.js +++ b/tools/proto/jest.config.js @@ -1,5 +1,3 @@ -const { resolve } = require( 'path' ); - const base = require( '../../jest.config.base' ); /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ module.exports = { @@ -11,8 +9,4 @@ module.exports = { setupFilesAfterEnv: [ ...base.projects[1].setupFilesAfterEnv, '@testing-library/jest-dom' ], }, ], - watchPathIgnorePatterns: [ - ...( base.watchPathIgnorePatterns ?? [] ), - resolve( __dirname, '__tests__/integration/mock-fs/.*' ), - ], };