Skip to content

Commit 3424a5b

Browse files
Fixes for Mocha plugin (#1089)
1 parent eba5ebf commit 3424a5b

File tree

7 files changed

+28
-11
lines changed

7 files changed

+28
-11
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"extension": ["ts"],
3-
"require": "ts-node/register"
2+
"spec": ["**/*.test.ts"],
3+
"require": ["ts-node/register", "hooks.ts"]
44
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
extension:
2-
- ts
3-
require: ts-node/register
1+
spec:
2+
- "**/*.test.ts"
3+
require:
4+
- ts-node/register
5+
- hooks.ts
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import 'mocha';
2+
3+
describe('Tests', () => {});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const mochaHooks = {
2+
beforeAll: () => {},
3+
};
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
22
"name": "@fixtures/mocha",
33
"mocha": {
4-
"extension": ["ts"],
5-
"require": "ts-node/register"
4+
"spec": ["**/*.test.ts"],
5+
"require": ["ts-node/register", "hooks.ts"]
6+
},
7+
"devDependencies": {
8+
"@types/mocha": "*",
9+
"mocha": "*",
10+
"ts-node": "*"
611
}
712
}

packages/knip/src/plugins/mocha/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { IsPluginEnabled, Plugin, ResolveConfig } from '../../types/config.js';
2-
import { toEntry } from '../../util/input.js';
2+
import { type Input, toDeferResolve, toEntry } from '../../util/input.js';
33
import { hasDependency } from '../../util/plugin.js';
44
import type { MochaConfig } from './types.js';
55

@@ -18,7 +18,11 @@ const entry = ['**/test/*.{js,cjs,mjs}'];
1818
const resolveConfig: ResolveConfig<MochaConfig> = localConfig => {
1919
const entryPatterns = localConfig.spec ? [localConfig.spec].flat() : entry;
2020
const require = localConfig.require ? [localConfig.require].flat() : [];
21-
return [...entryPatterns, ...require].map(id => toEntry(id));
21+
22+
const inputs: Input[] = [];
23+
inputs.push(...entryPatterns.map(id => toEntry(id)));
24+
inputs.push(...require.map(id => toDeferResolve(id)));
25+
return inputs;
2226
};
2327

2428
const args = {

packages/knip/test/plugins/mocha.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test('Find dependencies with the Mocha plugin', async () => {
1515

1616
assert.deepEqual(counters, {
1717
...baseCounters,
18-
processed: 0,
19-
total: 0,
18+
processed: 2,
19+
total: 2,
2020
});
2121
});

0 commit comments

Comments
 (0)