Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(next): DEVXP-2630: run v0 tests #146

Merged
merged 11 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/build-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,24 @@ jobs:
node-version-file: 'next/.nvmrc'
cache: 'npm'

- name: Cache v0 dependencies
uses: actions/cache@v3
id: cache-v0
with:
path: node_modules
key: ${{ runner.os }}-npm-next-v0-${{ hashFiles('package-lock.json') }}

- name: Install v0 dependencies
if: steps.cache-v0.outputs.cache-hit != 'true'
run: npm install

- name: Cache PNPM dependencies
uses: actions/cache@v3
id: cache-next
with:
path: next/node_modules
key: ${{ runner.os }}-pnpm-next-${{ hashFiles('next/pnpm-lock.yaml') }}

- name: Install dependencies
if: steps.cache-next.outputs.cache-hit != 'true'
run: cd next && pnpm install
Expand All @@ -54,6 +66,12 @@ jobs:
with:
node-version-file: 'next/.nvmrc'

- name: Get cached v0 dependencies
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-npm-next-v0-${{ hashFiles('package-lock.json') }}

- name: Get cached PNPM dependencies
uses: actions/cache@v3
with:
Expand All @@ -65,3 +83,6 @@ jobs:

- name: Tests
run: cd next && pnpm test

- name: v0 Tests
run: cd next && pnpm run test:v0
1 change: 1 addition & 0 deletions next/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules
/dist
/json-schema-test-suite
/test/v0-test-results.json
4 changes: 3 additions & 1 deletion next/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import antfu from '@antfu/eslint-config'

export default antfu({})
export default antfu({
ignores: ['test/v0-baseline-test-results.json'],
})
3 changes: 3 additions & 0 deletions next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"test": "jest",
"test:watch": "jest --watchAll",
"test:file": "jest --runTestsByPath",
"test:v0-update-baseline": "jest --roots '<rootDir>/../src/tests' --json --outputFile=test/v0-baseline-test-results.json",
"test:v0-compare-results": "node test/v0_compare_test_results.js",
"test:v0": "jest --roots '<rootDir>/../src/tests' --json --outputFile=test/v0-test-results.json; pnpm run test:v0-compare-results",
"lint": "eslint --max-warnings 0 .",
"typecheck": "tsc --noEmit",
"check": "pnpm run lint && pnpm run typecheck",
Expand Down
1 change: 1 addition & 0 deletions next/test/v0-baseline-test-results.json

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions next/test/v0_compare_test_results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable no-console */

import fs from 'node:fs'
import process from 'node:process'

const BASELINE_FILE = './test/v0-baseline-test-results.json'
const CURRENT_FILE = './test/v0-test-results.json'

if (!fs.existsSync(BASELINE_FILE)) {
console.error('🚨 Baseline file not found. Run Jest and save it first!')
process.exit(1)
}

// Load test results
const baseline = JSON.parse(fs.readFileSync(BASELINE_FILE, 'utf8'))
const current = JSON.parse(fs.readFileSync(CURRENT_FILE, 'utf8'))

// Extract test statuses
function getTestStatus(results) {
const statusMap = new Map()
results.testResults.forEach((testFile) => {
testFile.assertionResults.forEach((test) => {
statusMap.set(test.fullName, test.status)
})
})
return statusMap
}

const baselineStatus = getTestStatus(baseline)
const currentStatus = getTestStatus(current)

let failed = false

baselineStatus.forEach((oldStatus, testName) => {
const newStatus = currentStatus.get(testName)

if (oldStatus === 'passed' && newStatus !== 'passed') {
console.error(`🚨 Regression: "${testName}" was passing but now fails!`)
failed = true
}

if (oldStatus === 'failed' && newStatus === 'passed') {
console.error(`🎉 Fixed: "${testName}" was failing but now passes.`)
failed = true
}
})

if (failed) {
console.error('❌ V0 test results changed unexpectedly.')
process.exit(1)
}
else {
console.log('✅ V0 test results match the expected state.')
}