Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PlaywrightEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const getBrowserPerProcess = async (
// https://github.com/mmarkelov/jest-playwright/issues/42#issuecomment-589170220
if (browserType !== CHROMIUM && launchBrowserApp && launchBrowserApp.args) {
launchBrowserApp.args = launchBrowserApp.args.filter(
(item) => item !== '--no-sandbox',
(item: string) => item !== '--no-sandbox',
)
}

Expand Down
28 changes: 28 additions & 0 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ describe('checkDeviceEnv', () => {
})

describe('checkDependencies', () => {
it('should return null for empty dependencies', () => {
const dep = checkDependencies({})
expect(dep).toBe(null)
})

it('should return null for dependencies without playwright packages', () => {
const dep = checkDependencies({ test: '0.0.1' })
expect(dep).toBe(null)
})

it('should return right package object for single package', () => {
const dep = checkDependencies({ 'playwright-chromium': '*' })
expect(dep).toStrictEqual({ [CHROMIUM]: CHROMIUM })
Expand Down Expand Up @@ -215,6 +225,24 @@ describe('readPackage', () => {
{ virtual: true },
)

const playwright = await readPackage()
expect(playwright).toStrictEqual({ [FIREFOX]: FIREFOX })
})
it('should return playwright-firefox when it is defined and empty dependencies are persistent', async () => {
;((fs.exists as unknown) as jest.Mock).mockImplementationOnce(
(_, cb: (exists: boolean) => void) => cb(true),
)
jest.mock(
path.join(__dirname, '..', 'package.json'),
() => ({
dependencies: {},
devDependencies: {
'playwright-firefox': '*',
},
}),
{ virtual: true },
)

const playwright = await readPackage()
expect(playwright).toStrictEqual({ [FIREFOX]: FIREFOX })
})
Expand Down
7 changes: 5 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const checkDependencies = (
dependencies: Record<string, string>,
): Packages | typeof IMPORT_KIND_PLAYWRIGHT | null => {
const packages: Packages = {}
if (!dependencies) return null
if (!dependencies || Object.keys(dependencies).length === 0) return null
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check on the packages variable instead of the dependencies variable. Since in my case, both are filled but only devDependencies does contain the playwright related packages.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mxschmitt yeah! That's true, but it will cover case when dependencies or devDependencies are defined, but empty. It should return null, and then we can check if they have some of playwright dependencies. So we check length of packages variable in the end. And in readPackage we can check result with null

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now 👍

if (dependencies.playwright) return IMPORT_KIND_PLAYWRIGHT
if (dependencies[`playwright-${CHROMIUM}`]) {
packages[CHROMIUM] = CHROMIUM
Expand All @@ -27,6 +27,9 @@ export const checkDependencies = (
if (dependencies[`playwright-${WEBKIT}`]) {
packages[WEBKIT] = WEBKIT
}
if (Object.keys(packages).length === 0) {
return null
}
return packages
}

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