Skip to content

Commit 6cb66c8

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

File tree

5 files changed

+65
-2
lines changed

5 files changed

+65
-2
lines changed

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/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828
},
2929
"scripts": {
3030
"build": "tsup",
31-
"test": "jest",
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)