Skip to content
Closed
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
6 changes: 3 additions & 3 deletions packages/cli/src/constructs/playwright-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,12 @@ export class PlaywrightCheck extends RuntimeCheck {
return `${testCommand} --config ${quotedPath}${projectArg}${tagArg}`
}

static async bundleProject (playwrightConfigPath: string, include: string[]) {
static async bundleProject (playwrightConfigPath: string, include: string[], installCommand?: string) {
let dir = ''
try {
const {
outputFile, browsers, relativePlaywrightConfigPath, cacheHash, playwrightVersion,
} = await bundlePlayWrightProject(playwrightConfigPath, include)
} = await bundlePlayWrightProject(playwrightConfigPath, include, installCommand)
dir = outputFile
const { data: { key } } = await PlaywrightCheck.uploadPlaywrightProject(dir)
return { key, browsers, relativePlaywrightConfigPath, cacheHash, playwrightVersion }
Expand Down Expand Up @@ -432,7 +432,7 @@ export class PlaywrightCheck extends RuntimeCheck {
cacheHash,
playwrightVersion,
relativePlaywrightConfigPath,
} = await PlaywrightCheck.bundleProject(this.playwrightConfigPath, this.include ?? [])
} = await PlaywrightCheck.bundleProject(this.playwrightConfigPath, this.include ?? [], this.installCommand)

const testCommand = PlaywrightCheck.buildTestCommand(
this.testCommand,
Expand Down
11 changes: 11 additions & 0 deletions packages/cli/src/services/__tests__/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ describe('util', () => {
await expect(fs.access(nodeModulesPath)).rejects.toThrow()
}, 30000)

it('should produce different cacheHash when installCommand is provided', async () => {
const fixtureDir = path.join(__dirname, 'fixtures', 'playwright-bundle-test')
const playwrightConfigPath = path.join(fixtureDir, 'playwright.config.ts')
Session.ignoreDirectoriesMatch = []

const resultWithout = await bundlePlayWrightProject(playwrightConfigPath, [])
const resultWith = await bundlePlayWrightProject(playwrightConfigPath, [], 'npm ci')

expect(resultWith.cacheHash).not.toEqual(resultWithout.cacheHash)
}, 30000)

it('should exclude node_modules with broad patterns despite include', async () => {
const fixtureDir = path.join(__dirname, 'fixtures', 'playwright-bundle-test')
const playwrightConfigPath = path.join(fixtureDir, 'playwright.config.ts')
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/services/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export function normalizeVersion (v?: string | undefined): string | undefined {
export async function bundlePlayWrightProject (
playwrightConfig: string,
include: string[],
installCommand?: string,
): Promise<{
outputFile: string
browsers: string[]
Expand Down Expand Up @@ -229,7 +230,7 @@ export async function bundlePlayWrightProject (
const playwrightVersion = getPlaywrightVersionFromPackage(dir)

const [cacheHash] = await Promise.all([
getCacheHash(lockfile),
getCacheHash(lockfile, installCommand),
loadPlaywrightProjectFiles(dir, pwConfigParsed, include, archive, lockfile),
])

Expand All @@ -251,10 +252,13 @@ export async function bundlePlayWrightProject (
})
}

export async function getCacheHash (lockFile: string): Promise<string> {
async function getCacheHash (lockFile: string, installCommand?: string): Promise<string> {
const fileBuffer = await readFile(lockFile)
const hash = createHash('sha256')
hash.update(fileBuffer)
if (installCommand) {
hash.update(installCommand)
}
return hash.digest('hex')
}

Expand Down