Skip to content

Commit 8ced5ef

Browse files
committed
chore(next): DEVXP-2630: run v0 tests
1 parent 8dc801b commit 8ced5ef

7 files changed

+75
-6
lines changed

.github/workflows/build-next.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ jobs:
6161
key: ${{ runner.os }}-pnpm-next-${{ hashFiles('next/pnpm-lock.yaml') }}
6262

6363
- name: Run lint and type checks
64-
run: cd next && pnpm check
64+
working-directory: next
65+
run: pnpm check
6566

6667
- name: Tests
67-
run: cd next && pnpm test
68+
working-directory: next
69+
run: pnpm test

next/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/node_modules
22
/dist
33
/json-schema-test-suite
4+
/test/v0-test-results.json

next/eslint.config.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import antfu from '@antfu/eslint-config'
22

3-
export default antfu({})
3+
export default antfu({
4+
ignores: ['test/v0-baseline-test-results.json'],
5+
})

next/jest.config.mjs

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ const config = {
4848
roots,
4949
moduleNameMapper,
5050
testPathIgnorePatterns,
51-
reporters: ['default', '<rootDir>/test/json-schema-test-suite/json-schema-test-suite-tracker.js'],
51+
reporters: [
52+
['github-actions', { silent: false }],
53+
'<rootDir>/test/json-schema-test-suite/json-schema-test-suite-tracker.js',
54+
'summary',
55+
],
5256
transformIgnorePatterns: ['<rootDir>/node_modules/json-schema-typed/'],
5357
}
5458

next/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@
2727
"node": ">=18.14.0"
2828
},
2929
"scripts": {
30-
"build": "tsup",
31-
"test": "jest",
30+
"build": "tsup --metafile",
31+
"test": "jest && pnpm run test:v0",
3232
"test:watch": "jest --watchAll",
3333
"test:file": "jest --runTestsByPath",
34+
"test:v0-update-baseline": "jest --roots '<rootDir>/../src/tests' --json --outputFile=test/v0-baseline-test-results.json",
35+
"test:v0-compare-results": "node test/v0_compare_test_results.js",
36+
"test:v0": "jest --roots '<rootDir>/../src/tests' --json --outputFile=test/v0-test-results.json; pnpm run test:v0-compare-results",
3437
"lint": "eslint --max-warnings 0 .",
3538
"typecheck": "tsc --noEmit",
3639
"check": "pnpm run lint && pnpm run typecheck",

next/test/v0-baseline-test-results.json

+1
Large diffs are not rendered by default.

next/test/v0_compare_test_results.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// const fs = require('node:fs')
2+
// const process = require('node:process')
3+
4+
import fs from 'node:fs'
5+
import process from 'node:process'
6+
7+
const BASELINE_FILE = './test/v0-baseline-test-results.json'
8+
const CURRENT_FILE = './test/v0-test-results.json'
9+
10+
if (!fs.existsSync(BASELINE_FILE)) {
11+
console.error('🚨 Baseline file not found. Run Jest and save it first!')
12+
process.exit(1)
13+
}
14+
15+
// Load test results
16+
const baseline = JSON.parse(fs.readFileSync(BASELINE_FILE, 'utf8'))
17+
const current = JSON.parse(fs.readFileSync(CURRENT_FILE, 'utf8'))
18+
19+
// Extract test statuses
20+
function getTestStatus(results) {
21+
const statusMap = new Map()
22+
results.testResults.forEach((testFile) => {
23+
testFile.assertionResults.forEach((test) => {
24+
statusMap.set(test.fullName, test.status)
25+
})
26+
})
27+
return statusMap
28+
}
29+
30+
const baselineStatus = getTestStatus(baseline)
31+
const currentStatus = getTestStatus(current)
32+
33+
let failed = false
34+
35+
baselineStatus.forEach((oldStatus, testName) => {
36+
const newStatus = currentStatus.get(testName)
37+
38+
if (oldStatus === 'passed' && newStatus !== 'passed') {
39+
console.error(`🚨 Regression: "${testName}" was passing but now fails!`)
40+
failed = true
41+
}
42+
43+
if (oldStatus === 'failed' && newStatus === 'passed') {
44+
console.error(`🎉 Fixed: "${testName}" was failing but now passes.`)
45+
failed = true
46+
}
47+
})
48+
49+
if (failed) {
50+
console.error('❌ V0 test results changed unexpectedly.')
51+
process.exit(1)
52+
}
53+
else {
54+
// eslint-disable-next-line no-console
55+
console.log('✅ V0 test results match the expected state.')
56+
}

0 commit comments

Comments
 (0)