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

Commit 840a66b

Browse files
mxschmittmmarkelov
andauthored
fix: checkDependencies if no package was found (#142)
* fix: checkDependencies if no pkg was found * Some fixes * Add some tests Co-authored-by: mmarkelov <maks-markel@mail.ru>
1 parent ccca35b commit 840a66b

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/PlaywrightEnvironment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const getBrowserPerProcess = async (
3131
// https://github.com/mmarkelov/jest-playwright/issues/42#issuecomment-589170220
3232
if (browserType !== CHROMIUM && launchBrowserApp && launchBrowserApp.args) {
3333
launchBrowserApp.args = launchBrowserApp.args.filter(
34-
(item) => item !== '--no-sandbox',
34+
(item: string) => item !== '--no-sandbox',
3535
)
3636
}
3737

src/utils.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ describe('checkDeviceEnv', () => {
153153
})
154154

155155
describe('checkDependencies', () => {
156+
it('should return null for empty dependencies', () => {
157+
const dep = checkDependencies({})
158+
expect(dep).toBe(null)
159+
})
160+
161+
it('should return null for dependencies without playwright packages', () => {
162+
const dep = checkDependencies({ test: '0.0.1' })
163+
expect(dep).toBe(null)
164+
})
165+
156166
it('should return right package object for single package', () => {
157167
const dep = checkDependencies({ 'playwright-chromium': '*' })
158168
expect(dep).toStrictEqual({ [CHROMIUM]: CHROMIUM })
@@ -215,6 +225,24 @@ describe('readPackage', () => {
215225
{ virtual: true },
216226
)
217227

228+
const playwright = await readPackage()
229+
expect(playwright).toStrictEqual({ [FIREFOX]: FIREFOX })
230+
})
231+
it('should return playwright-firefox when it is defined and empty dependencies are persistent', async () => {
232+
;((fs.exists as unknown) as jest.Mock).mockImplementationOnce(
233+
(_, cb: (exists: boolean) => void) => cb(true),
234+
)
235+
jest.mock(
236+
path.join(__dirname, '..', 'package.json'),
237+
() => ({
238+
dependencies: {},
239+
devDependencies: {
240+
'playwright-firefox': '*',
241+
},
242+
}),
243+
{ virtual: true },
244+
)
245+
218246
const playwright = await readPackage()
219247
expect(playwright).toStrictEqual({ [FIREFOX]: FIREFOX })
220248
})

src/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const checkDependencies = (
1616
dependencies: Record<string, string>,
1717
): Packages | typeof IMPORT_KIND_PLAYWRIGHT | null => {
1818
const packages: Packages = {}
19-
if (!dependencies) return null
19+
if (!dependencies || Object.keys(dependencies).length === 0) return null
2020
if (dependencies.playwright) return IMPORT_KIND_PLAYWRIGHT
2121
if (dependencies[`playwright-${CHROMIUM}`]) {
2222
packages[CHROMIUM] = CHROMIUM
@@ -27,6 +27,9 @@ export const checkDependencies = (
2727
if (dependencies[`playwright-${WEBKIT}`]) {
2828
packages[WEBKIT] = WEBKIT
2929
}
30+
if (Object.keys(packages).length === 0) {
31+
return null
32+
}
3033
return packages
3134
}
3235

@@ -85,7 +88,7 @@ export const readPackage = async (): Promise<
8588
const playwright =
8689
checkDependencies(packageConfig.dependencies) ||
8790
checkDependencies(packageConfig.devDependencies)
88-
if (!playwright || !Object.keys(playwright).length) {
91+
if (playwright === null) {
8992
throw new Error('None of playwright packages was not found in dependencies')
9093
}
9194
return playwright

0 commit comments

Comments
 (0)