Skip to content

Commit 10b6671

Browse files
committed
fix: update "advanced-js" CLI template to match the TS version
1 parent 3ef604b commit 10b6671

28 files changed

+367
-253
lines changed

examples/advanced-project-js/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ https://checklyhq.com website as a monitoring target.
88
3. Test -> Deploy: now you have your app monitored around the clock. All from your code base.
99

1010
```
11-
npm create checkly@latest -- --template advanced-project
11+
npm create checkly@latest -- --template advanced-project-js
1212
```
1313

1414
## Project Structure
@@ -17,15 +17,15 @@ This project has examples of all Checkly check types and showcases some advanced
1717

1818
- Running `npx checkly test` will look for `.check.js` files and `.spec.js` in `__checks__` directories and execute them in a dry run.
1919

20-
- Running `npx checkly deploy` will deploy your checks to Checkly, attach alert channels, and run them on a 10m schedule in the
20+
- Running `npx checkly deploy` will deploy your checks to Checkly, attach alert channels, and run them on a 10m schedule in the
2121
region `us-east-1` and `eu-west-1`
2222

2323
- An example GitHub Actions workflow is in the `.github/workflow.yml` file. It triggers all the checks in the project and deploys
2424
them if they pass.
2525

2626
## CLI Commands
2727

28-
Run the core CLI commands with `npx checkly <command>`
28+
Run the core CLI commands with `npx checkly <command>`
2929

3030
| Command | Action |
3131
|:---------------------|:-------------------------------------------------|
@@ -47,5 +47,5 @@ npm install --save-dev @playwright/[email protected]
4747

4848
## Questions?
4949

50-
Check [our CLI docs](https://www.checklyhq.com/docs/cli/), the [main Checkly docs](https://checklyhq.com/docs) or
50+
Check [our CLI docs](https://www.checklyhq.com/docs/cli/), the [main Checkly docs](https://checklyhq.com/docs) or
5151
join our [Slack community](https://checklyhq.com/slack).

examples/advanced-project-js/checkly.config.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { defineConfig } = require('checkly');
2-
const { RetryStrategyBuilder } = require('checkly/constructs');
1+
const { defineConfig } = require('checkly')
2+
const { AlertEscalationBuilder, RetryStrategyBuilder } = require('checkly/constructs')
33

44
/**
55
* See https://www.checklyhq.com/docs/cli/project-structure/
@@ -27,6 +27,8 @@ const config = defineConfig({
2727
runtimeId: '2025.04',
2828
/* Failed check runs will be retried before triggering alerts */
2929
retryStrategy: RetryStrategyBuilder.fixedStrategy({ baseBackoffSeconds: 60, maxRetries: 4, sameRegion: true }),
30+
/* All checks will have this alert escalation policy defined */
31+
alertEscalationPolicy: AlertEscalationBuilder.runBasedEscalation(1),
3032
/* A glob pattern that matches the Checks inside your repo, see https://www.checklyhq.com/docs/cli/using-check-test-match/ */
3133
checkMatch: '**/__checks__/**/*.check.js',
3234
/* Global configuration option for Playwright-powered checks. See https://www.checklyhq.com/docs/browser-checks/playwright-test/#global-configuration */
@@ -38,10 +40,10 @@ const config = defineConfig({
3840
}
3941
},
4042
browserChecks: {
41-
/* A glob pattern matches any Playwright .spec.js files and automagically creates a Browser Check. This way, you
42-
* can just write native Playwright code. See https://www.checklyhq.com/docs/cli/using-check-test-match/
43-
* */
44-
testMatch: '**/__checks__/**/*.spec.js',
43+
/* A glob pattern matches any Playwright .spec.ts files and automagically creates a Browser Check. This way, you
44+
* can just write native Playwright code. See https://www.checklyhq.com/docs/cli/using-check-test-match/
45+
* */
46+
testMatch: '**/__checks__/**/*.spec.ts',
4547
},
4648
},
4749
cli: {
@@ -52,6 +54,6 @@ const config = defineConfig({
5254
/* How many times to retry a failing test run when running `npx checkly test` or `npx checkly trigger` (max. 3) */
5355
retries: 0,
5456
},
55-
});
57+
})
5658

57-
module.exports = config;
59+
module.exports = config

examples/advanced-project-js/src/__checks__/api.check.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

examples/advanced-project-js/src/__checks__/home.check.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

examples/advanced-project-js/src/__checks__/homepage.spec.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

examples/advanced-project-js/src/__checks__/login.spec.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

examples/advanced-project-js/src/__checks__/multi-step-spacex.check.js

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const { join } = require('path')
2+
const { ApiCheck, AssertionBuilder } = require('checkly/constructs')
3+
const { syntheticGroup } = require('../utils/website-groups.check')
4+
5+
// API checks send an HTTP request to a URL endpoint and validate the response. Read more at:
6+
// https://www.checklyhq.com/docs/api-checks/
7+
8+
new ApiCheck('books-api-check-1', {
9+
name: 'Books API',
10+
degradedResponseTime: 10000, // milliseconds
11+
maxResponseTime: 20000,
12+
setupScript: {
13+
// API checks can run arbitrary JS/TS code before or after a check.
14+
entrypoint: join(__dirname, '../utils/setup.js')
15+
},
16+
group: syntheticGroup,
17+
request: {
18+
url: 'https://danube-web.shop/api/books',
19+
method: 'GET',
20+
followRedirects: true,
21+
skipSSL: false,
22+
assertions: [
23+
AssertionBuilder.statusCode().equals(200),
24+
AssertionBuilder.headers('content-type').equals('application/json; charset=utf-8'),
25+
AssertionBuilder.jsonBody('$[0].id').isNotNull(),
26+
AssertionBuilder.jsonBody('$[0].author').equals('Fric Eromm'),
27+
],
28+
},
29+
runParallel: true,
30+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { join } = require('path')
2+
const { BrowserCheck } = require('checkly/constructs')
3+
const { syntheticGroup } = require('../utils/website-groups.check')
4+
5+
// Configures two checks for our homepage in a single configuration file.
6+
// Most settings for these checks are defined in the check group,
7+
// in /utils/website-groups.check.ts
8+
9+
new BrowserCheck('browse-and-search-check', {
10+
name: 'Browse and Search',
11+
group: syntheticGroup,
12+
code: {
13+
entrypoint: join(__dirname, '03-browse-and-search.spec.js')
14+
},
15+
runParallel: true,
16+
})
17+
18+
new BrowserCheck('login-browser-check', {
19+
name: 'Login',
20+
group: syntheticGroup,
21+
code: {
22+
entrypoint: join(__dirname, '04-login.spec.js')
23+
},
24+
runParallel: true,
25+
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { test, expect } = require('@playwright/test')
2+
3+
// Source code for a browser check using Playwright Test. Find more Playwright information at
4+
// https://www.checklyhq.com/learn/playwright/
5+
6+
// This environment variable is set in the group configuration in /utils/website-groups.check.ts
7+
const searchString = process.env.authorName || 'Herman Moulson'
8+
9+
test('webshop homepage', async ({ page }) => {
10+
await page.goto('http://danube-web.shop/');
11+
await expect(page.getByRole('heading', { name: 'SPECIAL OFFER: 20% OFF BOOKS' })).toBeVisible();
12+
await page.locator('a').filter({ hasText: 'Fantasy' }).click();
13+
await expect(page.getByText('The Pickled Lynx')).toBeVisible();
14+
await page.getByRole('textbox').click();
15+
await page.getByRole('textbox').fill(searchString);
16+
await page.getByRole('button', { name: 'Search' }).click();
17+
await expect(page.getByText('Haben oder haben')).toBeVisible();
18+
})

0 commit comments

Comments
 (0)