22// SPDX-License-Identifier: GPL-3.0-only
33// Copyright (c) 2026 Marcus Krueger
44
5- const fs = require ( 'fs' ) ;
6- const path = require ( ' path' ) ;
7- const { copyDirectory, main } = require ( ' ./setup.js' ) ;
5+ const fs = require ( "node:fs" ) ;
6+ const path = require ( "node: path" ) ;
7+ const { copyDirectory, main } = require ( " ./setup.js" ) ;
88
99function runTests ( ) {
10- console . log ( ' 🧪 Running CodeForge package tests...\n' ) ;
10+ console . log ( " 🧪 Running CodeForge package tests...\n" ) ;
1111
12- // Test 1: copyDirectory function exists
13- console . log ( '✓ Test 1: copyDirectory function exists' ) ;
14-
15- // Test 2: main function exists
16- console . log ( '✓ Test 2: main function exists' ) ;
12+ // Test 1: copyDirectory function exists
13+ console . log ( "✓ Test 1: copyDirectory function exists" ) ;
1714
18- // Test 3: Check required files exist
19- const requiredFiles = [
20- 'package.json' ,
21- 'setup.js' ,
22- 'README.md' ,
23- '.devcontainer/devcontainer.json' ,
24- '.devcontainer/scripts/setup.sh' ,
25- '.devcontainer/config/defaults/settings.json'
26- ] ;
15+ // Test 2: main function exists
16+ console . log ( "✓ Test 2: main function exists" ) ;
2717
28- let allFilesExist = true ;
29- requiredFiles . forEach ( file => {
30- if ( fs . existsSync ( path . join ( __dirname , file ) ) ) {
31- console . log ( `✓ Test 3. ${ requiredFiles . indexOf ( file ) + 1 } : ${ file } exists` ) ;
32- } else {
33- console . log ( `❌ Test 3. ${ requiredFiles . indexOf ( file ) + 1 } : ${ file } missing` ) ;
34- allFilesExist = false ;
35- }
36- } ) ;
18+ // Test 3: Check required files exist
19+ const requiredFiles = [
20+ "package.json" ,
21+ "setup.js" ,
22+ "README.md" ,
23+ ".devcontainer/devcontainer.json" ,
24+ ".devcontainer/scripts/setup.sh" ,
25+ ".devcontainer/config/defaults/settings.json" ,
26+ ] ;
3727
38- // Test 4: Package.json has correct structure
39- const packageJson = JSON . parse ( fs . readFileSync ( path . join ( __dirname , 'package.json' ) , 'utf8' ) ) ;
40- const requiredFields = [ 'name' , 'version' , 'bin' , 'files' ] ;
41- let packageValid = true ;
28+ let allFilesExist = true ;
29+ requiredFiles . forEach ( ( file ) => {
30+ if ( fs . existsSync ( path . join ( __dirname , file ) ) ) {
31+ console . log (
32+ `✓ Test 3.${ requiredFiles . indexOf ( file ) + 1 } : ${ file } exists` ,
33+ ) ;
34+ } else {
35+ console . log (
36+ `❌ Test 3.${ requiredFiles . indexOf ( file ) + 1 } : ${ file } missing` ,
37+ ) ;
38+ allFilesExist = false ;
39+ }
40+ } ) ;
4241
43- requiredFields . forEach ( field => {
44- if ( packageJson [ field ] ) {
45- console . log ( `✓ Test 4.${ requiredFields . indexOf ( field ) + 1 } : package.json has ${ field } ` ) ;
46- } else {
47- console . log ( `❌ Test 4.${ requiredFields . indexOf ( field ) + 1 } : package.json missing ${ field } ` ) ;
48- packageValid = false ;
49- }
50- } ) ;
42+ // Test 4: Package.json has correct structure
43+ const packageJson = JSON . parse (
44+ fs . readFileSync ( path . join ( __dirname , "package.json" ) , "utf8" ) ,
45+ ) ;
46+ const requiredFields = [ "name" , "version" , "bin" , "files" ] ;
47+ let packageValid = true ;
5148
52- // Test 5: Setup script is executable
53- let setupExecutable = true ;
54- const setupStat = fs . statSync ( path . join ( __dirname , 'setup.js' ) ) ;
55- if ( setupStat . mode & parseInt ( '111' , 8 ) ) {
56- console . log ( '✓ Test 5: setup.js is executable' ) ;
57- } else {
58- console . log ( '❌ Test 5: setup.js is not executable' ) ;
59- setupExecutable = false ;
60- }
49+ requiredFields . forEach ( ( field ) => {
50+ if ( packageJson [ field ] ) {
51+ console . log (
52+ `✓ Test 4.${ requiredFields . indexOf ( field ) + 1 } : package.json has ${ field } ` ,
53+ ) ;
54+ } else {
55+ console . log (
56+ `❌ Test 4.${ requiredFields . indexOf ( field ) + 1 } : package.json missing ${ field } ` ,
57+ ) ;
58+ packageValid = false ;
59+ }
60+ } ) ;
6161
62- // Summary
63- console . log ( '\n📊 Test Results:' ) ;
64- if ( allFilesExist && packageValid && setupExecutable ) {
65- console . log ( '🎉 All tests passed! Package is ready for distribution.' ) ;
66- process . exit ( 0 ) ;
67- } else {
68- console . log ( '❌ Some tests failed. Check the errors above.' ) ;
69- process . exit ( 1 ) ;
70- }
62+ // Test 5: Setup script is executable
63+ let setupExecutable = true ;
64+ const setupStat = fs . statSync ( path . join ( __dirname , "setup.js" ) ) ;
65+ if ( setupStat . mode & 0o111 ) {
66+ console . log ( "✓ Test 5: setup.js is executable" ) ;
67+ } else {
68+ console . log ( "❌ Test 5: setup.js is not executable" ) ;
69+ setupExecutable = false ;
70+ }
71+
72+ // Summary
73+ console . log ( "\n📊 Test Results:" ) ;
74+ if ( allFilesExist && packageValid && setupExecutable ) {
75+ console . log ( "🎉 All tests passed! Package is ready for distribution." ) ;
76+ process . exit ( 0 ) ;
77+ } else {
78+ console . log ( "❌ Some tests failed. Check the errors above." ) ;
79+ process . exit ( 1 ) ;
80+ }
7181}
7282
7383if ( require . main === module ) {
74- runTests ( ) ;
75- }
84+ runTests ( ) ;
85+ }
0 commit comments