Skip to content

Commit

Permalink
Fix up unused files for jest-unit (resolves #841)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Nov 21, 2024
1 parent a0c4f42 commit 4657618
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 26 deletions.
1 change: 0 additions & 1 deletion packages/knip/fixtures/plugins/jest/junitProperties.js

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions packages/knip/fixtures/plugins/jest3/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'jest';
13 changes: 13 additions & 0 deletions packages/knip/fixtures/plugins/jest3/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
testEnvironment: 'node',
reporters: [
'default',
[
'jest-junit',
{
outputDirectory: 'reports/junit',
outputName: 'junit.xml',
},
],
],
};
8 changes: 8 additions & 0 deletions packages/knip/fixtures/plugins/jest3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@fixtures/jest3",
"scripts": {},
"devDependencies": {
"jest": "*",
"jest-junit": "*"
}
}
21 changes: 11 additions & 10 deletions packages/knip/src/plugins/jest/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ export const getReportersDependencies = (config: JestInitialOptions, options: Pl
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);
if (testCasePropertiesFile) {
const fileName = getStringPropOrFallback(testCasePropertiesFile, 'junitProperties.js');
const dir = getStringPropOrFallback(testCasePropertiesDirectory, options.rootCwd);
jUnitReporterDeps.push(join(dir, fileName));
}

if (testSuitePropertiesFile) {
const fileName = getStringPropOrFallback(testSuitePropertiesFile, 'junitTestCaseProperties.js');
const dir = getStringPropOrFallback(testSuitePropertiesDirectory, options.rootCwd);
jUnitReporterDeps.push(join(dir, fileName));
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/knip/test/plugins/jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test('Find dependencies with the Jest plugin', async () => {
devDependencies: 1,
unlisted: 3,
unresolved: 9,
processed: 8,
total: 8,
processed: 7,
total: 7,
});
});
16 changes: 4 additions & 12 deletions packages/knip/test/plugins/jest2.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
import { test } from 'bun:test';
import assert from 'node:assert/strict';
import { main } from '../../src/index.js';
import { join, resolve } from '../../src/util/path.js';
import { resolve } from '../../src/util/path.js';
import baseArguments from '../helpers/baseArguments.js';
import baseCounters from '../helpers/baseCounters.js';

const cwd = resolve('fixtures/plugins/jest2');

test('Find dependencies with the Jest plugin', async () => {
test('Find dependencies with the Jest plugin (2)', async () => {
const { issues, counters } = await main({
...baseArguments,
cwd,
});

assert(issues.devDependencies['package.json']['jest']);

// Correctly identifies setup file in a non-root jest.config.js which uses
// <rootDir> to reference the root directory.
assert(!issues.files.has(join(cwd, 'project1/setupFiles/setup.js')));

// Correctly identifies a local `testEnvironment` file.
assert(!issues.files.has(join(cwd, 'jest.environment.js')));

assert.deepEqual(counters, {
...baseCounters,
files: 0,
devDependencies: 1,
unlisted: 0,
unresolved: 0,
processed: 7,
total: 7,
processed: 6,
total: 6,
});
});
21 changes: 21 additions & 0 deletions packages/knip/test/plugins/jest3.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test } from 'bun:test';
import assert from 'node:assert/strict';
import { main } from '../../src/index.js';
import { resolve } from '../../src/util/path.js';
import baseArguments from '../helpers/baseArguments.js';
import baseCounters from '../helpers/baseCounters.js';

const cwd = resolve('fixtures/plugins/jest3');

test('Find dependencies with the Jest plugin (3)', async () => {
const { counters } = await main({
...baseArguments,
cwd,
});

assert.deepEqual(counters, {
...baseCounters,
processed: 2,
total: 2,
});
});

0 comments on commit 4657618

Please sign in to comment.