Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 545eb05

Browse files
(create-wdio): fix project name on Windows (#591)
1 parent 239bcc6 commit 545eb05

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

__mocks__/commander.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { vi } from 'vitest'
2+
import * as path from 'node:path'
23

34
const command: any = {}
45
command.name = vi.fn().mockReturnValue(command)
56
command.version = vi.fn().mockReturnValue(command)
67
command.usage = vi.fn().mockReturnValue(command)
78
command.arguments = vi.fn().mockReturnValue(command)
89
command.action = vi.fn((cb) => {
9-
cb('someProjectName')
10+
cb(`${path.sep}foo${path.sep}bar${path.sep}someProjectName`)
1011
return command
1112
})
1213
command.option = vi.fn().mockReturnValue(command)

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export async function createWebdriverIO(opts: ProgramOpts) {
7474
if (!hasPackageJson) {
7575
await fs.mkdir(root, { recursive: true })
7676
await fs.writeFile(path.resolve(root, 'package.json'), JSON.stringify({
77-
name: root.replace(/\/$/, '').split('/').pop(),
77+
name: root.substring(root.lastIndexOf(path.sep) + 1),
7878
type: 'module'
7979
}, null, 2))
8080
}

tests/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ test('does create a package.json to be used by the wdio config command when one
228228
expect(runProgram).toBeCalledTimes(2)
229229
expect(fs.mkdir).toBeCalledTimes(1)
230230
expect(fs.writeFile).toBeCalledTimes(1)
231+
expect(fs.writeFile).toBeCalledWith(
232+
expect.any(String),
233+
JSON.stringify({ name: 'someProjectName', type: 'module' }, null, 2),
234+
)
231235
})
232236

233237
test('installs the next version when the npmTag option is set to "next"', async () => {

0 commit comments

Comments
 (0)