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

Commit 7ea9e86

Browse files
(create-wdio): fix issues with executing wdio config, add support for bunx (#586)
1 parent 1092522 commit 7ea9e86

3 files changed

Lines changed: 43 additions & 8 deletions

File tree

src/constants.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ export const INSTALL_COMMAND: Record<PM, string> = {
6464
bun: 'install'
6565
} as const
6666

67+
export const EXECUTER: Record<PM, string> = {
68+
npm: 'npx',
69+
pnpm: 'pnpm',
70+
yarn: 'yarn',
71+
bun: 'bunx'
72+
} as const
73+
74+
export const EXECUTE_COMMAND: Record<PM, string> = {
75+
npm: '',
76+
pnpm: 'exec',
77+
yarn: 'exec',
78+
bun: ''
79+
} as const
80+
6781
export const DEV_FLAG: Record<PM, string> = {
6882
npm: '--save-dev',
6983
pnpm: '--save-dev',

src/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { resolve } from 'import-meta-resolve'
1010
import { runProgram, getPackageVersion } from './utils.js'
1111
import {
1212
ASCII_ROBOT, PROGRAM_TITLE, UNSUPPORTED_NODE_VERSION, DEFAULT_NPM_TAG,
13-
INSTALL_COMMAND, DEV_FLAG, PMs
13+
INSTALL_COMMAND, DEV_FLAG, PMs, EXECUTER,EXECUTE_COMMAND
1414
} from './constants.js'
1515
import type { ProgramOpts } from './types'
1616
import { execSync } from 'node:child_process'
@@ -62,9 +62,11 @@ export async function createWebdriverIO(opts: ProgramOpts) {
6262
* find package manager that was used to create project
6363
*/
6464
const pm = PMs.find((pm) => (
65-
// for pnpm check for "~/Library/pnpm/store/v3/..."
65+
// for pnpm check "~/Library/pnpm/store/v3/..."
66+
// for NPM check "~/.npm/npx/..."
67+
// for Yarn check "~/.yarn/bin/create-wdio"
68+
// for Bun check "~/.bun/bin/create-wdio"
6669
process.argv[1].includes(`${path.sep}${pm}${path.sep}`) ||
67-
// for NPM and Yarn check for "~/.npm/npx/..." or "~/.yarn/bin/create-wdio"
6870
process.argv[1].includes(`${path.sep}.${pm}${path.sep}`)
6971
)) || 'npm'
7072

@@ -92,11 +94,12 @@ export async function createWebdriverIO(opts: ProgramOpts) {
9294
console.log(chalk.green.bold('✔ Success!'))
9395
}
9496

95-
return runProgram(pm === 'npm' ? 'npx' : pm, [
96-
`${pm === 'npm' ? '' : 'run '}${WDIO_COMMAND}`,
97+
return runProgram(EXECUTER[pm], [
98+
EXECUTE_COMMAND[pm],
99+
WDIO_COMMAND,
97100
'config',
98101
...(opts.yes ? ['--yes'] : [])
99-
], { cwd: root })
102+
].filter(i => !!i), { cwd: root })
100103
}
101104

102105
async function isCLIInstalled(path: string) {

tests/index.test.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ test('createWebdriverIO with Yarn', async () => {
8080
)
8181
expect(runProgram).toBeCalledWith(
8282
'yarn',
83-
['run wdio', 'config'],
83+
['exec', 'wdio', 'config'],
8484
expect.any(Object)
8585
)
8686
expect(runProgram).toBeCalledTimes(2)
@@ -116,7 +116,25 @@ test('createWebdriverIO with pnpm', async () => {
116116
)
117117
expect(runProgram).toBeCalledWith(
118118
'pnpm',
119-
['run wdio', 'config'],
119+
['exec', 'wdio', 'config'],
120+
expect.any(Object)
121+
)
122+
expect(runProgram).toBeCalledTimes(2)
123+
expect(fs.mkdir).toBeCalledTimes(0)
124+
expect(fs.writeFile).toBeCalledTimes(0)
125+
})
126+
127+
test('createWebdriverIO with bun', async () => {
128+
process.argv = ['', '~/.bun/bin/create-wdio']
129+
await createWebdriverIO({ npmTag: 'latest' } as ProgramOpts)
130+
expect(runProgram).toBeCalledWith(
131+
'bun',
132+
['install', '@wdio/cli@latest'],
133+
expect.any(Object)
134+
)
135+
expect(runProgram).toBeCalledWith(
136+
'bunx',
137+
['wdio', 'config'],
120138
expect.any(Object)
121139
)
122140
expect(runProgram).toBeCalledTimes(2)

0 commit comments

Comments
 (0)