Skip to content

Commit d0197f1

Browse files
committed
fix(tests): slightly refactor the fixture sandbox in a way that makes pw-test e2e tests work
1 parent a7e1bb6 commit d0197f1

File tree

31 files changed

+145
-208
lines changed

31 files changed

+145
-208
lines changed

packages/cli/e2e/__tests__/fixtures/test-pwt-native/checkly.config.original.ts

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

packages/cli/e2e/__tests__/fixtures/test-pwt-native/package-lock.json

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

packages/cli/e2e/__tests__/fixtures/test-pwt-native/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "test-pwt-native",
33
"version": "0.0.1",
44
"devDependencies": {
5-
"@playwright/test": "1.53.1"
5+
"@playwright/test": "1.53.1",
6+
"jiti": "^2.6.1"
67
}
78
}
Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,67 @@
11
import path from 'node:path'
2-
import fs from 'node:fs'
32

4-
import config from 'config'
5-
import { describe, it, expect, afterEach, beforeAll } from 'vitest'
3+
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
64

7-
import { runChecklyCli } from '../run-checkly'
85
import { loadChecklyConfig } from '../../src/services/checkly-config-loader'
6+
import { FixtureSandbox } from '../../src/testing/fixture-sandbox'
97

10-
const FIXTURE_TEST_PWT_NATIVE = path.join(__dirname, 'fixtures', 'test-pwt-native')
8+
async function runTest (fixt: FixtureSandbox, args: string[]) {
9+
const result = await fixt.run('npx', [
10+
'checkly',
11+
'pw-test',
12+
...args,
13+
], {
14+
timeout: 120_000,
15+
})
16+
17+
if (result.exitCode !== 0) {
18+
// eslint-disable-next-line no-console
19+
console.error('stderr', result.stderr)
20+
// eslint-disable-next-line no-console
21+
console.error('stdout', result.stdout)
22+
}
23+
24+
expect(result.exitCode).toBe(0)
25+
26+
return result
27+
}
1128

1229
describe('pw-test', { timeout: 45000 }, () => {
13-
afterEach(() => {
14-
fs.copyFileSync(
15-
path.join(FIXTURE_TEST_PWT_NATIVE, 'checkly.config.original.ts'),
16-
path.join(FIXTURE_TEST_PWT_NATIVE, 'checkly.config.ts'),
17-
)
18-
})
30+
let fixt: FixtureSandbox
1931

2032
beforeAll(async () => {
21-
// Install fixture dependencies or they will not resolve correctly.
22-
const { execa } = await import('execa')
23-
await execa('npm', ['install'], { cwd: FIXTURE_TEST_PWT_NATIVE })
33+
fixt = await FixtureSandbox.create({
34+
source: path.join(__dirname, 'fixtures', 'test-pwt-native'),
35+
})
36+
})
37+
38+
afterAll(async () => {
39+
await fixt.destroy()
2440
})
2541

2642
it('Playwright test should run successfully', async () => {
27-
const result = await runChecklyCli({
28-
args: ['pw-test', '--', `--grep`, '@TAG-B'],
29-
apiKey: config.get('apiKey'),
30-
accountId: config.get('accountId'),
31-
directory: FIXTURE_TEST_PWT_NATIVE,
32-
timeout: 120000, // 2 minutes
33-
})
34-
if (result.status !== 0) {
35-
// eslint-disable-next-line no-console
36-
console.log(result)
37-
}
38-
expect(result.status).toBe(0)
43+
await runTest(fixt, [
44+
'--',
45+
'--grep',
46+
'@TAG-B',
47+
])
3948
}, 130000)
4049

4150
it('Should add a Playwright test to the config', async () => {
42-
const result = await runChecklyCli({
43-
args: ['pw-test', '--create-check', '--', `--grep`, '@TAG-B'],
44-
apiKey: config.get('apiKey'),
45-
accountId: config.get('accountId'),
46-
directory: FIXTURE_TEST_PWT_NATIVE,
47-
timeout: 120000, // 2 minutes
48-
})
49-
expect(result.status).toBe(0)
50-
const checklyConfig = await loadChecklyConfig(FIXTURE_TEST_PWT_NATIVE)
51+
await runTest(fixt, [
52+
'--create-check',
53+
'--',
54+
'--grep',
55+
'@TAG-B',
56+
])
57+
58+
const checklyConfig = await loadChecklyConfig(fixt.root)
59+
5160
expect(checklyConfig.config?.checks).toBeDefined()
5261
expect(checklyConfig.config?.checks?.playwrightConfigPath).toBe('./playwright.config.ts')
5362
expect(checklyConfig.config?.checks?.playwrightChecks).toBeDefined()
54-
expect(checklyConfig.config?.checks?.playwrightChecks.length).toBe(1)
55-
expect(checklyConfig.config?.checks?.playwrightChecks[0].name).toBe('Playwright Test: --grep @TAG-B')
56-
expect(checklyConfig.config?.checks?.playwrightChecks[0].testCommand).toBe('npx playwright test --grep @TAG-B')
63+
expect(checklyConfig.config?.checks?.playwrightChecks?.length).toBe(1)
64+
expect(checklyConfig.config?.checks?.playwrightChecks?.[0]?.name).toBe('Playwright Test: --grep @TAG-B')
65+
expect(checklyConfig.config?.checks?.playwrightChecks?.[0]?.testCommand).toBe('npx playwright test --grep @TAG-B')
5766
})
5867
})

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"prepare:dist": "tsc --build",
2323
"prepare": "npm run clean && npm run prepare:dist && npm run generate:rules",
2424
"test": "npm pack && vitest --run",
25-
"test:e2e": "npm run prepare && cross-env NODE_CONFIG_DIR=./e2e/config vitest -c ./vitest.config.e2e.mts",
25+
"test:e2e": "npm pack && cross-env NODE_CONFIG_DIR=./e2e/config vitest -c ./vitest.config.e2e.mts",
2626
"test:e2e:local": "cross-env CHECKLY_BASE_URL=http://localhost:3000 CHECKLY_ENV=local npm run test:e2e",
2727
"watch": "tsc --watch"
2828
},
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"name": "api-check-fixture",
33
"type": "module",
4-
"devDependencies": {
5-
"checkly": "file:./checkly.tgz"
6-
}
4+
"devDependencies": {}
75
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"name": "api-check-fixture",
33
"type": "module",
4-
"devDependencies": {
5-
"checkly": "file:./checkly.tgz"
6-
}
4+
"devDependencies": {}
75
}

packages/cli/src/constructs/__tests__/fixtures/playwright-check/test-cases/test-bundling/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version": "1.0.0",
44
"dependencies": {
55
"@playwright/test": "^1.55.1",
6-
"jiti": "^2.6.1",
7-
"checkly": "file:./checkly.tgz"
6+
"jiti": "^2.6.1"
87
}
98
}

packages/cli/src/constructs/__tests__/fixtures/playwright-check/test-cases/test-doubleCheck-default-ignored/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "playwright-check-fixture",
33
"devDependencies": {
44
"@playwright/test": "^1.55.1",
5-
"jiti": "^2.6.1",
6-
"checkly": "file:./checkly.tgz"
5+
"jiti": "^2.6.1"
76
}
87
}

packages/cli/src/constructs/__tests__/fixtures/playwright-check/test-cases/test-doubleCheck-not-allowed/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "playwright-check-fixture",
33
"devDependencies": {
44
"@playwright/test": "^1.55.1",
5-
"jiti": "^2.6.1",
6-
"checkly": "file:./checkly.tgz"
5+
"jiti": "^2.6.1"
76
}
87
}

0 commit comments

Comments
 (0)