Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/knip/fixtures/plugins/vitest8/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@fixtures/vitest8",
"devDependencies": {
"vitest": "*"
}
}
5 changes: 5 additions & 0 deletions packages/knip/fixtures/plugins/vitest8/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expect, test } from 'vitest';

test('Unit A', () => {
expect(true).toBe(!false);
});
Empty file.
20 changes: 20 additions & 0 deletions packages/knip/fixtures/plugins/vitest8/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
workspace: [
{
test: {
name: 'integration',
setupFiles: './vitest.integration.setup.mjs',
},
},
{
test: {
globalSetup: './vitest.unit.setup.ts',
name: 'unit',
},
},
],
},
});
14 changes: 13 additions & 1 deletion packages/knip/src/plugins/vitest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,19 @@ const findConfigDependencies = (localConfig: ViteConfig, options: PluginOptions)
const setupFiles = [testConfig.setupFiles ?? []].flat().map(specifier => ({ ...toDeferResolve(specifier), dir }));
const globalSetup = [testConfig.globalSetup ?? []].flat().map(specifier => ({ ...toDeferResolve(specifier), dir }));

return [...[...environments, ...reporters, ...coverage].map(id => toDependency(id)), ...setupFiles, ...globalSetup];
const workspaceDependencies: Input[] = [];
if (testConfig.workspace !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (const workspaceConfig of testConfig.workspace) {
workspaceDependencies.push(...findConfigDependencies(workspaceConfig, options));
}
}

return [
...[...environments, ...reporters, ...coverage].map(id => toDependency(id)),
...setupFiles,
...globalSetup,
...workspaceDependencies,
];
};

const getConfigs = async (localConfig: ViteConfigOrFn | VitestWorkspaceConfig) => {
Expand Down
26 changes: 26 additions & 0 deletions packages/knip/test/plugins/vitest8.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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/vitest8');

test('Find dependencies with Vitest plugin (8)', async () => {
const { counters, issues, report, rules } = await main({
...baseArguments,
cwd,
});

assert(issues.unresolved['vitest.config.ts']['./vitest.integration.setup.mjs']);
assert(issues.unresolved['vitest.config.ts']['./vitest.unit.setup.ts']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Happy to merge. If you could please touch those (empty) files there? Then this test file and the counters are tidy too 🍃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure that I understand the counters and issues returned by await main(). When i touch the files, the test fails because they're not unresolved then.

How exactly would touching the files make this test file and counters tidy?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I wasn't clear. With "tidy" I meant that the issue counters end up being zero (0). When the files are there (i.e. not unresolved), there are no issues left (only a number of processed/total files). Then we don't need to assert numbers for unresolved etc. which in my mind is "tidy".


assert.deepEqual(counters, {
...baseCounters,
unlisted: 0,
unresolved: 2,
processed: 3,
total: 3,
});
});
Loading