Skip to content

Commit

Permalink
(create-wdio): fix project name on Windows (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinheitzman authored Dec 6, 2023
1 parent 239bcc6 commit 545eb05
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion __mocks__/commander.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { vi } from 'vitest'
import * as path from 'node:path'

const command: any = {}
command.name = vi.fn().mockReturnValue(command)
command.version = vi.fn().mockReturnValue(command)
command.usage = vi.fn().mockReturnValue(command)
command.arguments = vi.fn().mockReturnValue(command)
command.action = vi.fn((cb) => {
cb('someProjectName')
cb(`${path.sep}foo${path.sep}bar${path.sep}someProjectName`)
return command
})
command.option = vi.fn().mockReturnValue(command)
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export async function createWebdriverIO(opts: ProgramOpts) {
if (!hasPackageJson) {
await fs.mkdir(root, { recursive: true })
await fs.writeFile(path.resolve(root, 'package.json'), JSON.stringify({
name: root.replace(/\/$/, '').split('/').pop(),
name: root.substring(root.lastIndexOf(path.sep) + 1),
type: 'module'
}, null, 2))
}
Expand Down
4 changes: 4 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ test('does create a package.json to be used by the wdio config command when one
expect(runProgram).toBeCalledTimes(2)
expect(fs.mkdir).toBeCalledTimes(1)
expect(fs.writeFile).toBeCalledTimes(1)
expect(fs.writeFile).toBeCalledWith(
expect.any(String),
JSON.stringify({ name: 'someProjectName', type: 'module' }, null, 2),
)
})

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

0 comments on commit 545eb05

Please sign in to comment.