-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support resolving jest-junit file dependencies (#835)
- Loading branch information
Showing
11 changed files
with
86 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {} |
1 change: 1 addition & 0 deletions
1
packages/knip/fixtures/plugins/jest2/junitTestCaseProperties.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/knip/fixtures/plugins/jest2/project1/customProperties.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { PluginOptions } from '../../types/config.js'; | ||
import { dirname, isInternal, join, toAbsolute } from '../../util/path.js'; | ||
import { load } from '../../util/plugin.js'; | ||
import type { JestInitialOptions } from './types.js'; | ||
|
||
export const resolveExtensibleConfig = async (configFilePath: string) => { | ||
let config = await load(configFilePath); | ||
if (config?.preset) { | ||
const { preset } = config; | ||
if (isInternal(preset)) { | ||
const presetConfigPath = toAbsolute(preset, dirname(configFilePath)); | ||
const presetConfig = await resolveExtensibleConfig(presetConfigPath); | ||
config = Object.assign({}, presetConfig, config); | ||
} | ||
} | ||
return config; | ||
}; | ||
|
||
const getStringPropOrFallback = (prop: unknown, fallback: string): string => { | ||
return typeof prop === 'string' ? prop : fallback; | ||
}; | ||
|
||
export const getReportersDependencies = (config: JestInitialOptions, options: PluginOptions) => { | ||
// Resolve dependencies for jest-junit reporter config | ||
const jUnitReporterDeps: string[] = []; | ||
for (const reporter of config.reporters ?? []) { | ||
if (typeof reporter !== 'string' && reporter[0] === 'jest-junit') { | ||
const { | ||
testCasePropertiesFile, | ||
testCasePropertiesDirectory, | ||
testSuitePropertiesFile, | ||
testSuitePropertiesDirectory, | ||
} = reporter[1]; | ||
|
||
const testCaseFileName = getStringPropOrFallback(testCasePropertiesFile, 'junitProperties.js'); | ||
const testCaseDirectory = getStringPropOrFallback(testCasePropertiesDirectory, options.rootCwd); | ||
const testCaseFilePath = join(testCaseDirectory, testCaseFileName); | ||
|
||
const testSuiteFileName = getStringPropOrFallback(testSuitePropertiesFile, 'junitTestCaseProperties.js'); | ||
const testSuiteDirectory = getStringPropOrFallback(testSuitePropertiesDirectory, options.rootCwd); | ||
const testSuiteFilePath = join(testSuiteDirectory, testSuiteFileName); | ||
|
||
jUnitReporterDeps.push(testCaseFilePath); | ||
jUnitReporterDeps.push(testSuiteFilePath); | ||
} | ||
} | ||
|
||
const reporters = config.reporters | ||
? config.reporters | ||
.map(reporter => (typeof reporter === 'string' ? reporter : reporter[0])) | ||
.filter(reporter => !['default', 'github-actions', 'summary'].includes(reporter)) | ||
: []; | ||
|
||
return [...reporters, ...jUnitReporterDeps]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters