Problem
When using the __mocks__/ directory along with vi.mock('path/to/file.ts'), the auto-loaded mock is still treated as an unused file (e.g. path/to/__mocks__/file.ts).
For this test:
import { getAppFactory } from '@/src/common/AppFactory/ts/getAppFactory';
vi.mock('@/src/common/AppFactory/ts/getAppFactory');
describe(() => {
...
});
I get this alert for the unused file:
{
"path": "src/common/AppFactory/ts/__mocks__/getAppFactory.ts",
"actions": [
{
"type": "delete-file",
"auto_fixable": false,
"description": "Delete this file",
"note": "File deletion may remove runtime functionality not visible to static analysis"
},
{
"type": "suppress-file",
"auto_fixable": false,
"description": "Suppress with a file-level comment at the top of the file",
"comment": "// fallow-ignore-file unused-file"
}
]
},
Proposed solution
I think the vitest plugin should be able to identify these vi.mock() side/auto-loaded mocks as used files.
Alternatives considered
For now, just ignoring all __mocks__/ directories.
Problem
When using the
__mocks__/directory along withvi.mock('path/to/file.ts'), the auto-loaded mock is still treated as an unused file (e.g.path/to/__mocks__/file.ts).For this test:
I get this alert for the unused file:
Proposed solution
I think the vitest plugin should be able to identify these
vi.mock()side/auto-loaded mocks as used files.Alternatives considered
For now, just ignoring all
__mocks__/directories.