Skip to content

Commit

Permalink
feat: support arrays of glob patterns (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnolet authored Dec 27, 2023
1 parent f9280cf commit e80c498
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default class Deploy extends AuthCommand {
PrivateLocationGroupAssignment.__checklyType,
].some(t => t === type)) {
// Don't report changes to alert channel subscriptions or private location assignments.
// User's don't create these directly, so it's more intuitive to consider it as part of the check.
// Users don't create these directly, so it's more intuitive to consider it as part of the check.
continue
}
const construct = project.data[type as keyof ProjectData][logicalId]
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/constructs/check-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ type BrowserCheckConfig = CheckConfigDefaults & {
/**
* Glob pattern to include multiple files, i.e. all `.spec.ts` files
*/
testMatch: string,
testMatch: string | string[],
}

type MultiStepCheckConfig = CheckConfigDefaults & {
/**
* Glob pattern to include multiple files, i.e. all `.spec.ts` files
*/
testMatch: string,
testMatch: string | string[],
}

export interface CheckGroupProps {
Expand Down Expand Up @@ -191,7 +191,7 @@ export class CheckGroup extends Construct {
this.__addPrivateLocationGroupAssignments()
}

private __addChecks (fileAbsolutePath: string, testMatch: string) {
private __addChecks (fileAbsolutePath: string, testMatch: string|string[]) {
const parent = path.dirname(fileAbsolutePath)
const matched = glob.sync(testMatch, { nodir: true, cwd: parent })
for (const match of matched) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { test } from '@playwright/test'
test('nested', async () => {
// Go to https://example.com/
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable no-new */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { BrowserCheck } = require('../../../../../../constructs')

new BrowserCheck('nested', {
name: 'nested',
runtimeId: '2022.10',
locations: ['eu-central-1'],
frequency: 10,
environmentVariables: [],
alertChannels: [],
code: {
content: 'console.log(1)',
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { test } from '@playwright/test'
test('check 1', async () => {
// Go to https://example.com/
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable no-new */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { BrowserCheck } = require('../../../../../constructs')

new BrowserCheck('check1', {
name: 'check1',
runtimeId: '2022.10',
locations: ['eu-central-1'],
frequency: 10,
environmentVariables: [],
alertChannels: [],
code: {
content: 'console.log(1)',
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { test } from '@playwright/test'
test('check 2', async () => {
// Go to https://example.com/
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable no-new */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { BrowserCheck } = require('../../../../../constructs')

new BrowserCheck('check2', {
name: 'check3',
runtimeId: '2022.10',
locations: ['eu-central-1'],
frequency: 10,
environmentVariables: [],
alertChannels: [],
code: {
content: 'console.log(1)',
},
})
25 changes: 25 additions & 0 deletions packages/cli/src/services/__tests__/project-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,31 @@ describe('parseProject()', () => {
})
})

it('should parse a project with multiple glob patterns and deduplicate overlapping patterns', async () => {
const globProjectPath = path.join(__dirname, 'project-parser-fixtures', 'multiple-glob-patterns-project')
const project = await parseProject({
directory: globProjectPath,
projectLogicalId: 'glob-project-id',
projectName: 'glob project',
availableRuntimes: runtimes,
checkMatch: ['**/__checks1__/*.check.js', '**/__checks2__/*.check.js', '**/__nested-checks__/*.check.js'],
browserCheckMatch: ['**/__checks1__/*.spec.js', '**/__checks2__/*.spec.js', '**/__nested-checks__/*.spec.js'],
})
expect(project.synthesize()).toMatchObject({
project: {
logicalId: 'glob-project-id',
},
resources: [
{ type: 'check', logicalId: 'nested' },
{ type: 'check', logicalId: 'check1' },
{ type: 'check', logicalId: 'check2' },
{ type: 'check', logicalId: '__checks1__/__nested-checks__/nested.spec.js' },
{ type: 'check', logicalId: '__checks1__/check1.spec.js' },
{ type: 'check', logicalId: '__checks2__/check2.spec.js' },
],
})
})

it('should throw error for empty browser-check script', async () => {
try {
const projectPath = path.join(__dirname, 'project-parser-fixtures', 'empty-script-project')
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/services/checkly-config-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type ChecklyConfig = {
/**
* Glob pattern where the CLI looks for files containing Check constructs, i.e. all `.checks.ts` files
*/
checkMatch?: string,
checkMatch?: string | string[],
/**
* List of glob patterns with directories to ignore.
*/
Expand All @@ -48,7 +48,7 @@ export type ChecklyConfig = {
/**
* Glob pattern where the CLI looks for Playwright test files, i.e. all `.spec.ts` files
*/
testMatch?: string,
testMatch?: string | string[],
},
},
/**
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/services/project-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type ProjectParseOpts = {
projectLogicalId: string,
projectName: string,
repoUrl?: string,
checkMatch?: string,
browserCheckMatch?: string,
checkMatch?: string | string[],
browserCheckMatch?: string | string[],
ignoreDirectoriesMatch?: string[],
checkDefaults?: CheckConfigDefaults,
browserCheckDefaults?: CheckConfigDefaults,
Expand Down Expand Up @@ -69,7 +69,7 @@ export async function parseProject (opts: ProjectParseOpts): Promise<Project> {

async function loadAllCheckFiles (
directory: string,
checkFilePattern: string,
checkFilePattern: string | string[],
ignorePattern: string[],
): Promise<void> {
const checkFiles = await findFilesWithPattern(directory, checkFilePattern, ignorePattern)
Expand All @@ -94,7 +94,7 @@ async function loadAllCheckFiles (

async function loadAllBrowserChecks (
directory: string,
browserCheckFilePattern: string | undefined,
browserCheckFilePattern: string | string[] | undefined,
ignorePattern: string[],
project: Project,
): Promise<void> {
Expand Down Expand Up @@ -186,7 +186,7 @@ async function loadAllPrivateLocationsSlugNames (

async function findFilesWithPattern (
directory: string,
pattern: string,
pattern: string | string[],
ignorePattern: string[],
): Promise<string[]> {
// The files are sorted to make sure that the processing order is deterministic.
Expand Down

0 comments on commit e80c498

Please sign in to comment.