|
1 | | -import path from 'node:path'; |
| 1 | +import { basename, dirname, join } from 'node:path'; |
2 | 2 | import type { CommandModule } from 'src/core/command'; |
3 | 3 | import { NotFoundError } from 'src/core/errors'; |
4 | 4 | import { parseCommand } from 'src/core/parse'; |
@@ -79,7 +79,7 @@ vi.mock('node:fs', async (importOriginal) => { |
79 | 79 | export function unmockAllCommandModules() { |
80 | 80 | for (const [commandDir, commandNames] of mockCommandDirs.entries()) { |
81 | 81 | for (const commandName of commandNames) { |
82 | | - vi.doMock(path.join(commandDir, commandName), () => { |
| 82 | + vi.doMock(join(commandDir, commandName), () => { |
83 | 83 | const mod = { |
84 | 84 | handler: vi.fn(() => { |
85 | 85 | throw new NotFoundError(commandName, commandDir); |
@@ -111,8 +111,8 @@ export function mockCommandModule<T extends CommandModule | undefined>( |
111 | 111 | unmock: () => void; |
112 | 112 | } { |
113 | 113 | const formattedFilePath = formatFileName(commandPath); |
114 | | - const commandDir = path.dirname(commandPath); |
115 | | - const commandName = path.basename(commandPath); |
| 114 | + const commandDir = dirname(commandPath); |
| 115 | + const commandName = basename(commandPath); |
116 | 116 |
|
117 | 117 | // Keep track of the command directories and names that have been mocked |
118 | 118 | if (mockCommandDirs.has(commandDir)) { |
@@ -184,7 +184,7 @@ export function mockCommandStringModules<TCommandString extends string>( |
184 | 184 |
|
185 | 185 | // mock each command in the command string |
186 | 186 | for (const token of tokens) { |
187 | | - commandPath = path.join(commandPath, token); |
| 187 | + commandPath = join(commandPath, token); |
188 | 188 | const { mock, unmock } = mockCommandModule(commandPath, { |
189 | 189 | handler: vi.fn(({ next, data }) => next(data)), |
190 | 190 | }); |
|
0 commit comments