Skip to content

Commit 35d68d7

Browse files
author
ci-bot
committed
clean orphan group tests on e2e build
1 parent 9ac96f2 commit 35d68d7

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
const testFolder = './apps/remix-ide-e2e/src/tests/'
2+
const fs = require('fs')
3+
const path = require('path')
4+
5+
/**
6+
* This script cleans up orphaned group test files.
7+
*
8+
* Group test files (e.g., editor_group1.test.ts) are automatically generated
9+
* from base test files (e.g., editor.test.ts) by buildGroupTests.js.
10+
*
11+
* When a base test file is deleted or renamed, its corresponding group test
12+
* files become orphaned and need to be removed. This script:
13+
*
14+
* 1. Scans all test files in the tests/ directory
15+
* 2. Identifies group test files by the pattern: *_group<N>.(test.ts|flaky.ts|pr.ts)
16+
* 3. Checks if the parent base test file exists
17+
* 4. Removes any orphaned group test files
18+
*
19+
* This script runs automatically as part of the build:e2e process to ensure
20+
* the test directory stays clean.
21+
*
22+
* Examples of group test files and their parents:
23+
* - editor_group1.test.ts → editor.test.ts
24+
* - terminal_group11.flaky.ts → terminal.test.ts
25+
* - matomo-consent_group2.pr.ts → matomo-consent.test.ts
26+
*/
27+
28+
let orphanedCount = 0
29+
let deletedCount = 0
30+
31+
console.log('🔍 Scanning for orphaned group test files...\n')
32+
33+
// Get all files in the test folder
34+
const allFiles = fs.readdirSync(testFolder)
35+
36+
// Separate base tests and group tests
37+
// Group tests can have patterns like:
38+
// - editor_group1.test.ts (standard)
39+
// - terminal_group11.flaky.ts (flaky tagged)
40+
// - matomo-consent_group2.pr.ts (PR tagged)
41+
const groupTestPattern = /_group\d+\.(test\.ts|flaky\.ts|pr\.ts)$/
42+
43+
const groupTests = allFiles.filter(file => groupTestPattern.test(file))
44+
const baseTests = allFiles.filter(file => file.endsWith('.test.ts') && !groupTestPattern.test(file))
45+
46+
console.log(`📊 Found ${baseTests.length} base test files`)
47+
console.log(`📊 Found ${groupTests.length} group test files\n`)
48+
49+
// Check each group test to see if its parent exists
50+
groupTests.forEach(groupFile => {
51+
// Extract the base filename from the group test
52+
// Examples:
53+
// editor_group1.test.ts -> editor.test.ts
54+
// dgit_local_group4.test.ts -> dgit_local.test.ts
55+
// terminal_group11.flaky.ts -> terminal.test.ts
56+
57+
let baseFileName = groupFile
58+
.replace(/_group\d+/, '') // Remove _groupN
59+
.replace(/\.(flaky|pr)/, '') // Remove .flaky or .pr tag
60+
61+
// Ensure it ends with .test.ts (but don't double up)
62+
if (!baseFileName.endsWith('.test.ts')) {
63+
baseFileName = baseFileName.replace(/\.ts$/, '.test.ts')
64+
}
65+
66+
// Check if the base test file exists
67+
if (!baseTests.includes(baseFileName)) {
68+
orphanedCount++
69+
const groupFilePath = path.join(testFolder, groupFile)
70+
71+
console.log(`❌ Orphaned: ${groupFile}`)
72+
console.log(` Missing parent: ${baseFileName}`)
73+
74+
try {
75+
// Read the file to verify it's a group test before deleting
76+
const content = fs.readFileSync(groupFilePath, 'utf8')
77+
const isGroupTest = content.includes('buildGroupTest') ||
78+
content.includes('import * as test from')
79+
80+
if (isGroupTest) {
81+
fs.unlinkSync(groupFilePath)
82+
deletedCount++
83+
console.log(` ✅ Deleted\n`)
84+
} else {
85+
console.log(` ⚠️ Skipped (not a generated group test)\n`)
86+
}
87+
} catch (error) {
88+
console.log(` ⚠️ Error: ${error.message}\n`)
89+
}
90+
}
91+
})
92+
93+
// Summary
94+
console.log('─'.repeat(50))
95+
console.log(`\n📋 Summary:`)
96+
console.log(` Orphaned group tests found: ${orphanedCount}`)
97+
console.log(` Files deleted: ${deletedCount}`)
98+
99+
if (deletedCount > 0) {
100+
console.log(`\n✨ Cleanup completed successfully!`)
101+
} else if (orphanedCount === 0) {
102+
console.log(`\n✅ No orphaned group tests found. Everything is clean!`)
103+
} else {
104+
console.log(`\n⚠️ Some orphaned files were not deleted (see warnings above)`)
105+
}
106+
107+
process.exit(0)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"publish:remixd": "yarn build remixd && cd ./dist/libs/remixd && yarn publish && yarn run bumpVersion:remixd",
5858
"publish:libs": "yarn run build:libs && lerna publish --skip-git && yarn run bumpVersion:libs",
5959
"publishDev:libs": "yarn run build:libs && lerna publish --npm-tag alpha --skip-git && yarn run bumpVersion:libs",
60-
"build:e2e": "node apps/remix-ide-e2e/src/buildGroupTests.js && tsc -p apps/remix-ide-e2e/tsconfig.e2e.json && node scripts/update-e2e-keywords.js",
60+
"build:e2e": "node apps/remix-ide-e2e/src/cleanupGroupTests.js && node apps/remix-ide-e2e/src/buildGroupTests.js && tsc -p apps/remix-ide-e2e/tsconfig.e2e.json && node scripts/update-e2e-keywords.js",
6161
"inject-e2e-config": "node scripts/inject-e2e-config.js dist/apps/remix-ide \"http://127.0.0.1:8080/assets/js/soljson\" \"http://127.0.0.1:8080/assets/js/soljson\" \"http://127.0.0.1:9090/\"",
6262
"build:desktop": "rm -rf apps/remixdesktop/build/remix-ide && mkdir -p apps/remixdesktop/build && NX_DESKTOP_FROM_DIST=true node --max-old-space-size=8192 ./node_modules/.bin/nx build remix-ide --configuration=desktop && cp -r dist/apps/remix-ide apps/remixdesktop/build/remix-ide",
6363
"build:desktopwin": "cross-env NX_DESKTOP_FROM_DIST=true bash -c \"rm -rf apps/remixdesktop/build/remix-ide && mkdir -p apps/remixdesktop/build && node --max-old-space-size=8192 ./node_modules/.bin/nx build remix-ide --configuration=desktop && cp -r dist/apps/remix-ide apps/remixdesktop/build/remix-ide\"",

0 commit comments

Comments
 (0)