Skip to content

Commit b7a6221

Browse files
authored
fix: Playwright config in a subdirectory gets bundled using the wrong path (#1168)
* fix: use basePath relative paths in the generated PW bundle Otherwise some files get archived using the wrong wrong path, especially if the Playwright config is in a subdirectory. * chore: fix tests
1 parent f39f066 commit b7a6221

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

packages/cli/src/constructs/__tests__/playwright-check.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('PlaywrightCheck', () => {
2222
})
2323

2424
it('should synthesize groupName', async () => {
25+
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
2526
Session.project = new Project('project-id', {
2627
name: 'Test Project',
2728
repoUrl: 'https://github.com/checkly/checkly-cli',
@@ -49,6 +50,7 @@ describe('PlaywrightCheck', () => {
4950
})
5051

5152
it('should synthesize group', async () => {
53+
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
5254
Session.project = new Project('project-id', {
5355
name: 'Test Project',
5456
repoUrl: 'https://github.com/checkly/checkly-cli',
@@ -76,6 +78,7 @@ describe('PlaywrightCheck', () => {
7678
})
7779

7880
it('should synthesize groupId', async () => {
81+
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
7982
Session.project = new Project('project-id', {
8083
name: 'Test Project',
8184
repoUrl: 'https://github.com/checkly/checkly-cli',
@@ -104,6 +107,7 @@ describe('PlaywrightCheck', () => {
104107

105108
describe('validation', () => {
106109
it('should warn that groupName is deprecated', async () => {
110+
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
107111
Session.project = new Project('project-id', {
108112
name: 'Test Project',
109113
repoUrl: 'https://github.com/checkly/checkly-cli',
@@ -132,6 +136,7 @@ describe('PlaywrightCheck', () => {
132136
})
133137

134138
it('should error if groupName is not found', async () => {
139+
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
135140
Session.project = new Project('project-id', {
136141
name: 'Test Project',
137142
repoUrl: 'https://github.com/checkly/checkly-cli',
@@ -160,6 +165,7 @@ describe('PlaywrightCheck', () => {
160165
})
161166

162167
it('should error if both group and groupName are set', async () => {
168+
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
163169
Session.project = new Project('project-id', {
164170
name: 'Test Project',
165171
repoUrl: 'https://github.com/checkly/checkly-cli',
@@ -188,6 +194,7 @@ describe('PlaywrightCheck', () => {
188194
})
189195

190196
it('should error if both groupId and groupName are set', async () => {
197+
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
191198
Session.project = new Project('project-id', {
192199
name: 'Test Project',
193200
repoUrl: 'https://github.com/checkly/checkly-cli',
@@ -216,6 +223,7 @@ describe('PlaywrightCheck', () => {
216223
})
217224

218225
it('should error if retryStrategy is set', async () => {
226+
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
219227
Session.project = new Project('project-id', {
220228
name: 'Test Project',
221229
repoUrl: 'https://github.com/checkly/checkly-cli',
@@ -240,6 +248,7 @@ describe('PlaywrightCheck', () => {
240248
})
241249

242250
it('should error if doubleCheck is set', async () => {
251+
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
243252
Session.project = new Project('project-id', {
244253
name: 'Test Project',
245254
repoUrl: 'https://github.com/checkly/checkly-cli',
@@ -248,6 +257,7 @@ describe('PlaywrightCheck', () => {
248257
const check = new PlaywrightCheck('foo', {
249258
name: 'Test Check',
250259
playwrightConfigPath: path.resolve(__dirname, './fixtures/playwright-check/playwright.config.ts'),
260+
// @ts-expect-error Testing a property that isn't part of the type.
251261
doubleCheck: true,
252262
})
253263

@@ -265,6 +275,7 @@ describe('PlaywrightCheck', () => {
265275

266276
describe('defaults', () => {
267277
it('should ignore retryStrategy from session check defaults', () => {
278+
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
268279
Session.project = new Project('project-id', {
269280
name: 'Test Project',
270281
repoUrl: 'https://github.com/checkly/checkly-cli',
@@ -283,6 +294,7 @@ describe('PlaywrightCheck', () => {
283294
})
284295

285296
it('should ignore doubleCheck from session check defaults', () => {
297+
Session.basePath = path.resolve(__dirname, './fixtures/playwright-check')
286298
Session.project = new Project('project-id', {
287299
name: 'Test Project',
288300
repoUrl: 'https://github.com/checkly/checkly-cli',

packages/cli/src/services/util.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export async function bundlePlayWrightProject (
234234
outputFile,
235235
browsers: pwConfigParsed.getBrowsers(),
236236
playwrightVersion,
237-
relativePlaywrightConfigPath: path.relative(dir, filePath),
237+
relativePlaywrightConfigPath: Session.relativePosixPath(filePath),
238238
cacheHash,
239239
})
240240
})
@@ -286,24 +286,49 @@ export async function loadPlaywrightProjectFiles (
286286
const ignoredFiles = ['**/node_modules/**', '.git/**']
287287
const parser = new Parser({})
288288
const { files, errors } = await parser.getFilesAndDependencies(pwConfigParsed)
289-
const mode = 0o755 // Default mode for files in the archive
290289
if (errors.length) {
291290
throw new Error(`Error loading playwright project files: ${errors.map((e: string) => e).join(', ')}`)
292291
}
292+
const root = Session.basePath!
293+
const prefix = Session.relativePosixPath(dir)
294+
const entryDefaults = {
295+
mode: 0o755, // Default mode for files in the archive
296+
}
293297
for (const file of files) {
294-
const relativePath = path.relative(dir, file)
295-
archive.file(file, { name: relativePath, mode })
298+
archive.file(file, {
299+
...entryDefaults,
300+
name: Session.relativePosixPath(file),
301+
})
296302
}
297303
const lockFileDirName = path.dirname(lockFile)
298-
archive.file(lockFile, { name: path.basename(lockFile), mode })
299-
archive.file(path.join(lockFileDirName, 'package.json'), { name: 'package.json', mode })
304+
const packageJsonFile = path.join(lockFileDirName, 'package.json')
305+
archive.file(lockFile, {
306+
...entryDefaults,
307+
name: Session.relativePosixPath(lockFile),
308+
})
309+
archive.file(packageJsonFile, {
310+
...entryDefaults,
311+
name: Session.relativePosixPath(packageJsonFile),
312+
})
300313
// handle workspaces
301-
archive.glob('**/package.json', { cwd: path.join(dir, '/'), ignore: ignoredFiles }, { mode })
314+
archive.glob('**/package.json', {
315+
cwd: dir,
316+
ignore: ignoredFiles,
317+
}, {
318+
...entryDefaults,
319+
prefix,
320+
})
302321
for (const includePattern of include) {
303-
archive.glob(includePattern, { cwd: path.join(dir, '/') }, { mode })
322+
archive.glob(includePattern, { cwd: dir }, {
323+
...entryDefaults,
324+
prefix,
325+
})
304326
}
305327
for (const filePath of extraFiles) {
306-
archive.file(path.resolve(dir, filePath), { name: filePath, mode })
328+
archive.file(path.resolve(root, filePath), {
329+
...entryDefaults,
330+
name: Session.relativePosixPath(filePath),
331+
})
307332
}
308333
}
309334

0 commit comments

Comments
 (0)