Skip to content

Commit f6e060e

Browse files
committed
fix: support include field for bundling [sc-0]
1 parent 6e0c662 commit f6e060e

File tree

6 files changed

+39
-12
lines changed

6 files changed

+39
-12
lines changed

Diff for: packages/cli/src/commands/deploy.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export default class Deploy extends AuthCommand {
115115
verifyRuntimeDependencies,
116116
checklyConfigConstructs,
117117
playwrightConfigPath: checklyConfig.checks?.playwrightConfigPath,
118+
include: checklyConfig.checks?.include,
118119
playwrightChecks: checklyConfig.checks?.playwrightChecks,
119120
})
120121
const repoInfo = getGitInformation(project.repoUrl)
@@ -138,7 +139,7 @@ export default class Deploy extends AuthCommand {
138139
}
139140
const {
140141
relativePlaywrightConfigPath, browsers, key,
141-
} = await PlaywrightCheck.bundleProject(check.playwrightConfigPath)
142+
} = await PlaywrightCheck.bundleProject(check.playwrightConfigPath, check.include)
142143
check.codeBundlePath = key
143144
check.browsers = browsers
144145
check.playwrightConfigPath = relativePlaywrightConfigPath

Diff for: packages/cli/src/commands/test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export default class Test extends AuthCommand {
184184
verifyRuntimeDependencies,
185185
checklyConfigConstructs,
186186
playwrightConfigPath: checklyConfig.checks?.playwrightConfigPath,
187+
include: checklyConfig.checks?.include,
187188
playwrightChecks: checklyConfig.checks?.playwrightChecks,
188189
})
189190
const checks = Object.entries(project.data.check)
@@ -240,7 +241,7 @@ export default class Test extends AuthCommand {
240241
}
241242
const {
242243
relativePlaywrightConfigPath, browsers, key,
243-
} = await PlaywrightCheck.bundleProject(check.playwrightConfigPath)
244+
} = await PlaywrightCheck.bundleProject(check.playwrightConfigPath, check.include)
244245
check.codeBundlePath = key
245246
check.browsers = browsers
246247
check.playwrightConfigPath = relativePlaywrightConfigPath

Diff for: packages/cli/src/constructs/playwright-check.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface PlaywrightCheckProps extends CheckProps {
1515
pwProjects?: string|string[]
1616
pwTags?: string|string[]
1717
browsers?: string[]
18+
include?: string|string[]
1819
}
1920

2021
export class PlaywrightCheck extends Check {
@@ -25,6 +26,7 @@ export class PlaywrightCheck extends Check {
2526
pwTags: string[]
2627
codeBundlePath?: string
2728
browsers?: string[]
29+
include: string[]
2830
constructor (logicalId: string, props: PlaywrightCheckProps) {
2931
super(logicalId, props)
3032
this.codeBundlePath = props.codeBundlePath
@@ -36,6 +38,9 @@ export class PlaywrightCheck extends Check {
3638
this.pwTags = props.pwTags
3739
? (Array.isArray(props.pwTags) ? props.pwTags : [props.pwTags])
3840
: []
41+
this.include = props.include
42+
? (Array.isArray(props.include) ? props.include : [props.include])
43+
: []
3944
this.testCommand = props.testCommand ?? 'npx playwright test'
4045
if (!fs.existsSync(props.playwrightConfigPath)) {
4146
throw new ValidationError(`Playwright config doesnt exist ${props.playwrightConfigPath}`)
@@ -54,10 +59,12 @@ export class PlaywrightCheck extends Check {
5459
return `${testCommand} --config ${playwrightConfigPath}${playwrightProject?.length ? ' --project ' + playwrightProject.map(project => `"${project}"`).join(' ') : ''}${playwrightTag?.length ? ' --grep="' + playwrightTag.join('|') + '"' : ''}`
5560
}
5661

57-
static async bundleProject (playwrightConfigPath: string) {
62+
static async bundleProject (playwrightConfigPath: string, include: string[]) {
5863
let dir = ''
5964
try {
60-
const { outputFile, browsers, relativePlaywrightConfigPath } = await bundlePlayWrightProject(playwrightConfigPath)
65+
const {
66+
outputFile, browsers, relativePlaywrightConfigPath,
67+
} = await bundlePlayWrightProject(playwrightConfigPath, include)
6168
dir = outputFile
6269
const { data: { key } } = await uploadPlaywrightProject(dir)
6370
return { key, browsers, relativePlaywrightConfigPath }

Diff for: packages/cli/src/services/checkly-config-loader.ts

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export type ChecklyConfig = {
7070
* Playwright config path to be used during bundling and playwright config parsing
7171
*/
7272
playwrightConfigPath?: string,
73+
74+
/**
75+
* Extra files to be included into the playwright bundle
76+
*/
77+
include?: string | string[],
7378
/**
7479
* List of playwright checks that use the defined playwright config path
7580
*/

Diff for: packages/cli/src/services/project-parser.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type ProjectParseOpts = {
3232
verifyRuntimeDependencies?: boolean,
3333
checklyConfigConstructs?: Construct[],
3434
playwrightConfigPath?: string
35+
include?: string | string[],
3536
playwrightChecks?: PlaywrightSlimmedProp[]
3637
}
3738

@@ -55,6 +56,7 @@ export async function parseProject (opts: ProjectParseOpts): Promise<Project> {
5556
verifyRuntimeDependencies,
5657
checklyConfigConstructs,
5758
playwrightConfigPath,
59+
include,
5860
playwrightChecks,
5961
} = opts
6062
const project = new Project(projectLogicalId, {
@@ -72,13 +74,16 @@ export async function parseProject (opts: ProjectParseOpts): Promise<Project> {
7274
Session.defaultRuntimeId = defaultRuntimeId
7375
Session.verifyRuntimeDependencies = verifyRuntimeDependencies ?? true
7476

77+
const includeWrapped = include
78+
? (Array.isArray(include) ? include : [include])
79+
: []
7580
// TODO: Do we really need all of the ** globs, or could we just put node_modules?
7681
const ignoreDirectories = ['**/node_modules/**', '**/.git/**', ...ignoreDirectoriesMatch]
7782
await Promise.all([
7883
loadAllCheckFiles(directory, checkMatch, ignoreDirectories),
7984
loadAllBrowserChecks(directory, browserCheckMatch, ignoreDirectories, project),
8085
loadAllMultiStepChecks(directory, multiStepCheckMatch, ignoreDirectories, project),
81-
loadPlaywrightChecks(playwrightChecks, playwrightConfigPath),
86+
loadPlaywrightChecks(playwrightChecks, playwrightConfigPath, includeWrapped),
8287
])
8388

8489
// private-location must be processed after all checks and groups are loaded.
@@ -87,16 +92,18 @@ export async function parseProject (opts: ProjectParseOpts): Promise<Project> {
8792
return project
8893
}
8994

90-
async function loadPlaywrightChecks (playwrightChecks?: PlaywrightSlimmedProp[], playwrightConfigPath?: string) {
95+
async function loadPlaywrightChecks (
96+
playwrightChecks?: PlaywrightSlimmedProp[], playwrightConfigPath?: string, include?: string[]) {
9197
if (!playwrightConfigPath) {
9298
return
9399
}
100+
94101
if (playwrightChecks?.length) {
95102
for (const playwrightCheckProps of playwrightChecks) {
96103
// TODO: Don't upload for each check
97104
const {
98105
key, browsers, relativePlaywrightConfigPath,
99-
} = await PlaywrightCheck.bundleProject(playwrightConfigPath)
106+
} = await PlaywrightCheck.bundleProject(playwrightConfigPath, include ?? [])
100107
const playwrightCheck = new PlaywrightCheck(playwrightCheckProps.name, {
101108
...playwrightCheckProps,
102109
codeBundlePath: key,
@@ -107,7 +114,7 @@ async function loadPlaywrightChecks (playwrightChecks?: PlaywrightSlimmedProp[],
107114
} else {
108115
const {
109116
key, browsers, relativePlaywrightConfigPath,
110-
} = await PlaywrightCheck.bundleProject(playwrightConfigPath)
117+
} = await PlaywrightCheck.bundleProject(playwrightConfigPath, include ?? [])
111118
const playwrightCheck = new PlaywrightCheck(path.basename(playwrightConfigPath), {
112119
name: path.basename(playwrightConfigPath),
113120
codeBundlePath: key,

Diff for: packages/cli/src/services/util.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export function assignProxy (baseURL: string, axiosConfig: CreateAxiosDefaults)
231231
return axiosConfig
232232
}
233233

234-
export async function bundlePlayWrightProject (playwrightConfig: string):
234+
export async function bundlePlayWrightProject (playwrightConfig: string, include: string[]):
235235
Promise<{outputFile: string, browsers: string[], relativePlaywrightConfigPath: string}> {
236236
const dir = path.resolve(path.dirname(playwrightConfig))
237237
const filePath = path.resolve(dir, playwrightConfig)
@@ -249,7 +249,7 @@ Promise<{outputFile: string, browsers: string[], relativePlaywrightConfigPath: s
249249
},
250250
})
251251
archive.pipe(output)
252-
await loadPlaywrightProjectFiles(dir, pwtConfig, archive)
252+
await loadPlaywrightProjectFiles(dir, pwtConfig, include, archive)
253253
archive.file(playwrightConfig, { name: path.basename(playwrightConfig) })
254254
await archive.finalize()
255255
return new Promise((resolve, reject) => {
@@ -263,8 +263,10 @@ Promise<{outputFile: string, browsers: string[], relativePlaywrightConfigPath: s
263263
})
264264
}
265265

266-
export async function loadPlaywrightProjectFiles (dir: string, playwrightConfig: any, archive: Archiver) {
267-
const ignoredFiles: string[] = ['**/node_modules/**', '.git/**']
266+
export async function loadPlaywrightProjectFiles (
267+
dir: string, playwrightConfig: any, include: string[], archive: Archiver,
268+
) {
269+
const ignoredFiles = ['**/node_modules/**', '.git/**']
268270
const testFiles = getPlaywrightTestFiles(playwrightConfig)
269271
try {
270272
const gitignore = await fs.readFile(path.join(dir, '.gitignore'), { encoding: 'utf-8' })
@@ -276,7 +278,11 @@ export async function loadPlaywrightProjectFiles (dir: string, playwrightConfig:
276278
const relativePath = path.relative(dir, file)
277279
archive.file(file, { name: relativePath })
278280
}
281+
// TODO: This code below should be a single glob
279282
archive.glob('**/package*.json', { cwd: path.join(dir, '/'), ignore: ignoredFiles })
283+
for (const includePattern of include) {
284+
archive.glob(includePattern, { cwd: path.join(dir, '/'), ignore: ignoredFiles })
285+
}
280286
}
281287

282288
export function getPlaywrightTestFiles (playwrightConfig: any): (string | RegExp)[] {

0 commit comments

Comments
 (0)