Skip to content

Commit 1495da4

Browse files
committed
replace copy-tests with post-set-playground script
Remove duplicate test files from problem directories and add a post-set-playground.js script that copies tests from solution directories to the playground on demand.
1 parent 88272d5 commit 1495da4

File tree

12 files changed

+45
-642
lines changed

12 files changed

+45
-642
lines changed

epicshop/copy-tests.js

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

epicshop/post-set-playground.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
4+
const srcDir = process.env.EPICSHOP_PLAYGROUND_SRC_DIR
5+
const destDir = process.env.EPICSHOP_PLAYGROUND_DEST_DIR
6+
7+
if (!srcDir || !destDir) {
8+
console.log('⚠️ Missing required environment variables')
9+
process.exit(0)
10+
}
11+
12+
// Find the corresponding solution directory for the source
13+
// If source is a problem dir, find the matching solution dir
14+
// If source is already a solution dir, use it directly
15+
const srcDirName = path.basename(srcDir)
16+
let solutionDir = srcDir
17+
18+
if (srcDirName.includes('.problem.')) {
19+
solutionDir = srcDir.replace('.problem.', '.solution.')
20+
} else if (!srcDirName.includes('.solution.')) {
21+
// Not a problem or solution dir, nothing to do
22+
process.exit(0)
23+
}
24+
25+
if (!fs.existsSync(solutionDir)) {
26+
console.log(`⚠️ No solution directory found: ${solutionDir}`)
27+
process.exit(0)
28+
}
29+
30+
// Copy test files from solution to playground
31+
const testFiles = fs
32+
.readdirSync(solutionDir)
33+
.filter((f) => f.endsWith('.test.ts'))
34+
35+
for (const testFile of testFiles) {
36+
const src = path.join(solutionDir, testFile)
37+
const dest = path.join(destDir, testFile)
38+
39+
fs.copyFileSync(src, dest)
40+
console.log(`✅ Copied ${testFile} from solution to playground`)
41+
}
42+
43+
if (testFiles.length > 0) {
44+
console.log(`\n📋 Copied ${testFiles.length} test file(s) to playground`)
45+
}

exercises/01.classes/01.problem.class-basics/index.test.ts

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

exercises/01.classes/02.problem.constructors/index.test.ts

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

exercises/02.access-modifiers/01.problem.public-private/index.test.ts

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

exercises/02.access-modifiers/02.problem.protected/index.test.ts

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

0 commit comments

Comments
 (0)