forked from tw93/Pake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
1598 lines (1424 loc) · 50.6 KB
/
Copy pathindex.js
File metadata and controls
1598 lines (1424 loc) · 50.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
/**
* Unified Test Runner for Pake CLI
*
* This is a simplified, unified test runner that replaces the scattered
* test files with a single, easy-to-use interface.
*/
import { execSync, spawn } from "child_process";
import fs from "fs";
import path from "path";
import ora from "ora";
import config, { TIMEOUTS, TEST_URLS } from "./config.js";
class PakeTestRunner {
constructor() {
this.results = [];
this.tempFiles = [];
this.tempDirs = [];
}
async runAll(options = {}) {
const {
unit = true,
integration = true,
builder = true,
pakeCliTests = false,
e2e = false,
quick = false,
realBuild = false, // Add option for real build test
} = options;
console.log("Pake CLI Test Suite");
console.log("======================\n");
this.validateEnvironment();
// Clean up any leftover files from previous test runs
console.log("[Clean] Removing any leftover test artifacts...");
this.cleanupTempIcons();
let testCount = 0;
if (unit && !quick) {
console.log("Running CLI Health Checks...");
await this.runCliHealthChecks();
testCount++;
console.log("\nRunning Project Unit Tests (Vitest)...");
try {
execSync("npx vitest run", {
stdio: "inherit",
cwd: config.PROJECT_ROOT,
});
this.results.push({ name: "Vitest Unit Tests", passed: true });
testCount++;
} catch (e) {
console.log("[FAIL] Vitest unit tests failed");
this.results.push({
name: "Vitest Unit Tests",
passed: false,
error: e.message,
});
}
}
if (integration && !quick) {
console.log("\n[Integration] Running Integration Tests...");
await this.runIntegrationTests();
testCount++;
}
if (builder && !quick) {
console.log("\n[Build] Running Builder Tests...");
await this.runBuilderTests();
testCount++;
}
if (pakeCliTests) {
console.log("\n[Package] Running Pake-CLI GitHub Actions Tests...");
await this.runPakeCliTests();
testCount++;
}
if (e2e && !quick) {
console.log("\n[Run] Running End-to-End Tests...");
await this.runE2ETests();
testCount++;
console.log("\n[Network] Running Proxy Configuration Test...");
await this.runProxyTest();
testCount++;
}
if (builder && !quick) {
console.log("\n[Build] Running Local File Build Test...");
await this.runLocalFileTest();
testCount++;
}
if (realBuild && !quick) {
// On macOS, prefer multi-arch test as it's more likely to catch issues
if (process.platform === "darwin") {
console.log("\n[Build] Running Real Build Test (Multi-Arch)...");
await this.runMultiArchBuildTest();
testCount++;
} else {
console.log("\n[Build] Running Real Build Test...");
await this.runRealBuildTest();
testCount++;
}
}
this.cleanup();
this.displayFinalResults();
const passed = this.results.filter((r) => r.passed).length;
const total = this.results.length;
return passed === total;
}
validateEnvironment() {
console.log("Environment Validation:");
console.log("-----------------------");
// Check if CLI file exists
if (!fs.existsSync(config.CLI_PATH)) {
console.log("[FAIL] CLI file not found. Run: pnpm run cli:build");
process.exit(1);
}
console.log("[PASS] CLI file exists");
// Check if CLI is executable
try {
execSync(`node "${config.CLI_PATH}" --version`, {
encoding: "utf8",
timeout: 3000,
});
console.log("[PASS] CLI is executable");
} catch (error) {
console.log("[FAIL] CLI is not executable");
process.exit(1);
}
// Platform info
console.log(`[PASS] Platform: ${process.platform} (${process.arch})`);
console.log(`[PASS] Node.js: ${process.version}`);
const isCI = process.env.CI || process.env.GITHUB_ACTIONS;
console.log(`[INFO] CI Environment: ${isCI ? "Yes" : "No"}`);
console.log();
}
async runTest(name, testFn, timeout = TIMEOUTS.MEDIUM) {
const spinner = ora(`Running ${name}...`).start();
try {
const result = await Promise.race([
testFn(),
new Promise((_, reject) =>
setTimeout(() => reject(new Error("Test timeout")), timeout),
),
]);
if (result) {
spinner.succeed(`${name}: PASS`);
this.results.push({ name, passed: true });
} else {
spinner.fail(`${name}: FAIL`);
this.results.push({ name, passed: false });
}
} catch (error) {
spinner.fail(`${name}: ERROR - ${error.message.slice(0, 100)}...`);
this.results.push({
name,
passed: false,
error: error.message,
});
}
}
async runCliHealthChecks() {
// Version command test
await this.runTest(
"Version Command",
() => {
const output = execSync(`node "${config.CLI_PATH}" --version`, {
encoding: "utf8",
timeout: TIMEOUTS.QUICK,
});
return /^\d+\.\d+\.\d+/.test(output.trim());
},
TIMEOUTS.QUICK,
);
// Help command test
await this.runTest(
"Help Command",
() => {
const output = execSync(`node "${config.CLI_PATH}"`, {
encoding: "utf8",
timeout: TIMEOUTS.QUICK,
});
return output.includes("Usage: cli [url] [options]");
},
TIMEOUTS.QUICK,
);
// URL validation test
await this.runTest("URL Validation", () => {
try {
execSync(`node "${config.CLI_PATH}" "invalid-url" --name TestApp`, {
encoding: "utf8",
timeout: TIMEOUTS.QUICK,
});
return false; // Should have failed
} catch (error) {
return error.status !== 0;
}
});
// Number validation test
await this.runTest("Number Validation", () => {
try {
execSync(`node "${config.CLI_PATH}" https://example.com --width abc`, {
encoding: "utf8",
timeout: TIMEOUTS.QUICK,
});
return false; // Should throw error
} catch (error) {
return error.message.includes("Not a number");
}
});
// CLI response time test
await this.runTest("CLI Response Time", () => {
const start = Date.now();
execSync(`node "${config.CLI_PATH}" --version`, {
encoding: "utf8",
timeout: TIMEOUTS.QUICK,
});
const elapsed = Date.now() - start;
return elapsed < 5000;
});
// Weekly URL accessibility test
await this.runTest("Weekly URL Accessibility", () => {
try {
const testCommand = `node "${config.CLI_PATH}" ${TEST_URLS.WEEKLY} --name "URLTest" --debug`;
execSync(`echo "n" | timeout 5s ${testCommand} || true`, {
encoding: "utf8",
timeout: 8000,
});
return true; // If we get here, URL was parsed successfully
} catch (error) {
return (
!error.message.includes("Invalid URL") &&
!error.message.includes("invalid")
);
}
});
}
async runIntegrationTests() {
// Process spawning test
await this.runTest("CLI Process Spawning", () => {
return new Promise((resolve) => {
const child = spawn("node", [config.CLI_PATH, "--version"], {
stdio: ["pipe", "pipe", "pipe"],
});
let output = "";
child.stdout.on("data", (data) => {
output += data.toString();
});
child.on("close", (code) => {
resolve(code === 0 && /\d+\.\d+\.\d+/.test(output));
});
setTimeout(() => {
child.kill();
resolve(false);
}, TIMEOUTS.QUICK);
});
});
// File system permissions test
await this.runTest("File System Permissions", () => {
try {
const testFile = "test-write-permission.tmp";
fs.writeFileSync(testFile, "test");
this.trackTempFile(testFile);
const cliStats = fs.statSync(config.CLI_PATH);
return cliStats.isFile();
} catch {
return false;
}
});
// Dependency resolution test
await this.runTest("Dependency Resolution", () => {
try {
const packageJsonPath = path.join(config.PROJECT_ROOT, "package.json");
const packageJson = JSON.parse(
fs.readFileSync(packageJsonPath, "utf8"),
);
const essentialDeps = ["commander", "chalk", "fs-extra", "execa"];
return essentialDeps.every(
(dep) => packageJson.dependencies && packageJson.dependencies[dep],
);
} catch {
return false;
}
});
}
async runBuilderTests() {
// Platform detection test
await this.runTest("Platform Detection", () => {
const platform = process.platform;
const platformConfigs = {
darwin: { ext: ".dmg", multiArch: true },
win32: { ext: ".msi", multiArch: false },
linux: { ext: ".deb", multiArch: false },
};
const config = platformConfigs[platform];
return config && typeof config.ext === "string";
});
// Architecture detection test
await this.runTest("Architecture Detection", () => {
const currentArch = process.arch;
const macArch = currentArch === "arm64" ? "aarch64" : currentArch;
const linuxArch = currentArch === "x64" ? "amd64" : currentArch;
return typeof macArch === "string" && typeof linuxArch === "string";
});
// File naming pattern test
await this.runTest("File Naming Patterns", () => {
const testNames = ["Simple App", "App-With_Symbols", "CamelCaseApp"];
return testNames.every((name) => {
const processed = name.toLowerCase().replace(/\s+/g, "");
return processed.length > 0;
});
});
}
async runPakeCliTests() {
// Package installation test
await this.runTest(
"pake-cli Package Installation",
async () => {
try {
execSync("pnpm install pake-cli@latest", {
encoding: "utf8",
timeout: 60000,
cwd: "/tmp",
});
const pakeCliPath = "/tmp/node_modules/.bin/pake";
return fs.existsSync(pakeCliPath);
} catch (error) {
console.error("Package installation failed:", error.message);
return false;
}
},
TIMEOUTS.LONG,
);
// Version command test
await this.runTest("pake-cli Version Command", async () => {
try {
const version = execSync("npx pake --version", {
encoding: "utf8",
timeout: 10000,
});
return /^\d+\.\d+\.\d+/.test(version.trim());
} catch {
return false;
}
});
// Configuration validation test
await this.runTest("Configuration Validation", async () => {
try {
const validateConfig = (config) => {
const required = ["url", "name", "width", "height"];
const hasRequired = required.every((field) =>
config.hasOwnProperty(field),
);
const validTypes =
typeof config.url === "string" &&
typeof config.name === "string" &&
typeof config.width === "number" &&
typeof config.height === "number";
let validUrl = false;
try {
new URL(config.url);
validUrl = true;
} catch {}
const validName = config.name.length > 0;
return hasRequired && validTypes && validUrl && validName;
};
const testConfig = {
url: "https://github.com",
name: "github",
width: 1200,
height: 780,
};
return validateConfig(testConfig);
} catch {
return false;
}
});
}
async runE2ETests() {
// GitHub.com CLI build test
await this.runTest(
"GitHub.com CLI Build Test",
async () => {
return new Promise((resolve, reject) => {
const testName = "GitHubApp";
const command = `node "${config.CLI_PATH}" "https://github.com" --name "${testName}" --debug --width 1200 --height 780`;
const child = spawn(command, {
shell: true,
cwd: config.PROJECT_ROOT,
stdio: ["pipe", "pipe", "pipe"],
env: {
...process.env,
PAKE_E2E_TEST: "1",
PAKE_CREATE_APP: "1",
},
});
let buildStarted = false;
let configGenerated = false;
child.stdout.on("data", (data) => {
const output = data.toString();
if (
output.includes("Building app") ||
output.includes("Compiling") ||
output.includes("Installing package") ||
output.includes("Bundling")
) {
buildStarted = true;
}
if (
output.includes("GitHub") &&
(output.includes("config") || output.includes("name"))
) {
configGenerated = true;
}
});
child.stderr.on("data", (data) => {
const output = data.toString();
if (
output.includes("Building app") ||
output.includes("Compiling") ||
output.includes("Installing package") ||
output.includes("Bundling") ||
output.includes("Finished") ||
output.includes("Built application at:")
) {
buildStarted = true;
}
});
// Kill process after 60 seconds if build started
const timeout = setTimeout(() => {
child.kill("SIGTERM");
const appFile = path.join(config.PROJECT_ROOT, `${testName}.app`);
const dmgFile = path.join(config.PROJECT_ROOT, `${testName}.dmg`);
this.trackTempFile(appFile);
this.trackTempFile(dmgFile);
if (buildStarted) {
console.log(
`✓ GitHub.com CLI build started successfully (${testName})`,
);
resolve(true);
} else {
reject(
new Error("GitHub.com CLI build did not start within timeout"),
);
}
}, 60000);
child.on("close", () => {
clearTimeout(timeout);
const appFile = path.join(config.PROJECT_ROOT, `${testName}.app`);
const dmgFile = path.join(config.PROJECT_ROOT, `${testName}.dmg`);
this.trackTempFile(appFile);
this.trackTempFile(dmgFile);
if (buildStarted) {
resolve(true);
} else {
reject(
new Error("GitHub.com CLI build process ended before starting"),
);
}
});
child.on("error", (error) => {
reject(
new Error(`GitHub.com CLI build process error: ${error.message}`),
);
});
child.stdin.end();
});
},
70000, // 70 seconds timeout
);
// Configuration verification test
await this.runTest(
"Configuration File Verification",
async () => {
const pakeDir = path.join(config.PROJECT_ROOT, "src-tauri", ".pake");
return new Promise((resolve, reject) => {
const testName = "GitHubConfigTest";
const command = `node "${config.CLI_PATH}" "https://github.com" --name "${testName}" --debug --width 1200 --height 780`;
const child = spawn(command, {
shell: true,
cwd: config.PROJECT_ROOT,
stdio: ["pipe", "pipe", "pipe"],
env: {
...process.env,
PAKE_E2E_TEST: "1",
PAKE_CREATE_APP: "1",
},
});
const checkConfigFiles = () => {
if (fs.existsSync(pakeDir)) {
const configFile = path.join(pakeDir, "tauri.conf.json");
const pakeConfigFile = path.join(pakeDir, "pake.json");
if (fs.existsSync(configFile) && fs.existsSync(pakeConfigFile)) {
try {
const config = JSON.parse(
fs.readFileSync(configFile, "utf8"),
);
const pakeConfig = JSON.parse(
fs.readFileSync(pakeConfigFile, "utf8"),
);
if (
config.productName === testName &&
pakeConfig.windows[0].url === "https://github.com/"
) {
child.kill("SIGTERM");
this.trackTempDir(pakeDir);
console.log(
"✓ GitHub.com configuration files verified correctly",
);
resolve(true);
return true;
}
} catch (error) {
// Continue if config parsing fails
}
}
}
return false;
};
child.stdout.on("data", (data) => {
const output = data.toString();
if (
output.includes("Installing package") ||
output.includes("Building app")
) {
setTimeout(checkConfigFiles, 1000);
}
});
child.stderr.on("data", (data) => {
const output = data.toString();
if (
output.includes("Installing package") ||
output.includes("Building app") ||
output.includes("Package installed")
) {
setTimeout(checkConfigFiles, 1000);
}
});
// Timeout after 20 seconds
setTimeout(() => {
child.kill("SIGTERM");
this.trackTempDir(pakeDir);
reject(new Error("GitHub.com configuration verification timeout"));
}, 40000);
child.on("error", (error) => {
reject(
new Error(
`GitHub.com config verification error: ${error.message}`,
),
);
});
child.stdin.end();
});
},
45000,
);
}
async runProxyTest() {
await this.runTest("Proxy Configuration", async () => {
const command = `node "${config.CLI_PATH}" "https://google.com" --name "ProxyTest" --proxy-url "http://127.0.0.1:7890" --debug`;
// We just want to check if the command parses the proxy argument correctly
// It might fail to connect if no proxy is running, but that's expected
try {
execSync(`echo "n" | timeout 5s ${command} || true`, {
encoding: "utf8",
timeout: 8000,
});
return true;
} catch (error) {
// If it fails with "connection refused" or similar, it means it TRIED to use the proxy
return true;
}
});
}
async runLocalFileTest() {
await this.runTest("Local File Build Handling", async () => {
const testFile = path.join(config.PROJECT_ROOT, "test-local.html");
fs.writeFileSync(
testFile,
"<html><body><h1>Hello Pake</h1></body></html>",
);
this.trackTempFile(testFile);
try {
const command = `node "${config.CLI_PATH}" "${testFile}" --name "LocalApp" --debug`;
// We just verify it accepts the local file path
execSync(`echo "n" | timeout 5s ${command} || true`, {
encoding: "utf8",
timeout: 8000,
});
return true;
} catch (error) {
// Validation failure is what we want to catch (if it rejected local files)
return !error.message.includes("Invalid URL");
}
});
}
async runRealBuildTest() {
// Real build test that actually creates a complete app
await this.runTest(
"Complete GitHub.com App Build",
async () => {
return new Promise((resolve, reject) => {
const testName = "GitHubRealBuild";
// Platform-specific output files
const outputFiles = {
darwin: {
app: path.join(config.PROJECT_ROOT, `${testName}.app`),
installer: path.join(config.PROJECT_ROOT, `${testName}.dmg`),
bundleDir: path.join(
config.PROJECT_ROOT,
"src-tauri/target/release/bundle",
),
},
linux: {
app: path.join(
config.PROJECT_ROOT,
`src-tauri/target/release/pake`,
),
installer: path.join(
config.PROJECT_ROOT,
"src-tauri/target/release/bundle/deb",
),
bundleDir: path.join(
config.PROJECT_ROOT,
"src-tauri/target/release/bundle",
),
},
win32: {
app: path.join(
config.PROJECT_ROOT,
"src-tauri/target/x86_64-pc-windows-msvc/release/bundle/msi",
),
installer: path.join(
config.PROJECT_ROOT,
"src-tauri/target/x86_64-pc-windows-msvc/release/bundle/msi",
),
bundleDir: path.join(
config.PROJECT_ROOT,
"src-tauri/target/x86_64-pc-windows-msvc/release/bundle",
),
// Alternative directories to check
altDirs: [
path.join(
config.PROJECT_ROOT,
"src-tauri/target/release/bundle/msi",
),
path.join(
config.PROJECT_ROOT,
"src-tauri/target/x86_64-pc-windows-msvc/release/bundle/nsis",
),
path.join(
config.PROJECT_ROOT,
"src-tauri/target/release/bundle/nsis",
),
],
},
};
const platform = process.platform;
const expectedFiles = outputFiles[platform] || outputFiles.darwin;
console.log(
`[Integration] Starting real build test for GitHub.com...`,
);
console.log(`[Note] Platform: ${platform}`);
console.log(`[Note] Expected app directory: ${expectedFiles.app}`);
console.log(
`[Note] Expected installer directory: ${expectedFiles.installer}`,
);
if (expectedFiles.bundleDir) {
console.log(`[Note] Bundle directory: ${expectedFiles.bundleDir}`);
}
if (expectedFiles.altDirs) {
console.log(`[Note] Alternative directories to check:`);
expectedFiles.altDirs.forEach((dir, i) => {
console.log(` ${i + 1}. ${dir}`);
});
}
const command = `node "${config.CLI_PATH}" "https://github.com" --name "${testName}" --width 1200 --height 800 --hide-title-bar`;
const child = spawn(command, {
shell: true,
cwd: config.PROJECT_ROOT,
stdio: ["pipe", "pipe", "pipe"],
env: {
...process.env,
PAKE_CREATE_APP: "1",
},
});
let buildStarted = false;
let compilationStarted = false;
// Track progress without too much noise
child.stdout.on("data", (data) => {
const output = data.toString();
if (output.includes("Installing package")) {
console.log(" [Package] Installing dependencies...");
}
if (output.includes("Building app")) {
buildStarted = true;
console.log(" [Build] Build started...");
}
if (output.includes("Compiling")) {
compilationStarted = true;
console.log(" ⚙️ Compiling...");
}
if (output.includes("Bundling")) {
console.log(" [Package] Bundling...");
}
if (output.includes("Built application at:")) {
console.log(" [PASS] Build completed!");
}
});
let errorOutput = "";
child.stderr.on("data", (data) => {
const output = data.toString();
if (output.includes("Building app")) buildStarted = true;
if (output.includes("Compiling")) compilationStarted = true;
if (output.includes("Finished"))
console.log(" [PASS] Compilation finished!");
// Capture error output for debugging
if (
output.includes("error:") ||
output.includes("Error:") ||
output.includes("ERROR")
) {
errorOutput += output;
}
});
// Real timeout - 8 minutes for actual build
const timeout = setTimeout(() => {
console.log(
" [Check] Build timeout reached, checking for output files...",
);
const foundFiles = this.findBuildOutputFiles(testName, platform);
if (foundFiles.length > 0) {
console.log(
" [Success] Build completed successfully - found output files!",
);
foundFiles.forEach((file) => {
console.log(` [App] Found: ${file.path} (${file.type})`);
});
console.log(" [Success] Build artifacts tracked for cleanup");
child.kill("SIGTERM");
resolve(true);
} else {
console.log(
" [Warn] Build process completed but no output files found",
);
this.debugBuildDirectories();
child.kill("SIGTERM");
reject(
new Error("Real build test timeout - no output files found"),
);
}
}, 480000); // 8 minutes
child.on("close", (code) => {
clearTimeout(timeout);
console.log(
` [Status] Build process finished with exit code: ${code}`,
);
const foundFiles = this.findBuildOutputFiles(testName, platform);
if (foundFiles.length > 0) {
console.log(
" [Success] Real build test SUCCESS: Build file(s) generated!",
);
foundFiles.forEach((file) => {
console.log(` [App] ${file.type}: ${file.path}`);
try {
const stats = fs.statSync(file.path);
const size = (stats.size / 1024 / 1024).toFixed(1);
console.log(` Size: ${size}MB`);
} catch (error) {
console.log(` (Could not get file size)`);
}
});
console.log(" [Success] Build artifacts tracked for cleanup");
// Track files for cleanup
foundFiles.forEach((f) => this.trackTempFile(f.path));
resolve(true);
} else if (code === 0 && buildStarted && compilationStarted) {
console.log(
" [Warn] Build process completed but no output files found",
);
this.debugBuildDirectories();
resolve(false);
} else {
console.log(
` [FAIL] Build process failed with exit code: ${code}`,
);
if (buildStarted) {
console.log(
" [Status] Build was started but failed during execution",
);
if (errorOutput.trim()) {
console.log(" [Check] Error details:");
errorOutput.split("\n").forEach((line) => {
if (line.trim()) console.log(` ${line.trim()}`);
});
}
this.debugBuildDirectories();
} else {
console.log(
" [Status] Build failed before starting compilation",
);
if (errorOutput.trim()) {
console.log(" [Check] Error details:");
errorOutput.split("\n").forEach((line) => {
if (line.trim()) console.log(` ${line.trim()}`);
});
}
}
reject(new Error(`Real build test failed with code ${code}`));
}
});
child.on("error", (error) => {
clearTimeout(timeout);
reject(
new Error(`Real build test process error: ${error.message}`),
);
});
child.stdin.end();
});
},
500000, // 8+ minutes timeout
);
}
async runMultiArchBuildTest() {
// Multi-arch build test specifically for macOS
await this.runTest(
"Multi-Arch GitHub.com Build (Universal Binary)",
async () => {
return new Promise((resolve, reject) => {
const testName = "GitHubMultiArch";
const appFile = path.join(config.PROJECT_ROOT, `${testName}.app`);
const dmgFile = path.join(config.PROJECT_ROOT, `${testName}.dmg`);
console.log(
`[Integration] Starting multi-arch build test for GitHub.com...`,
);
console.log(`[Note] Expected output: ${appFile}`);
console.log(
`[Build] Building Universal Binary (Intel + Apple Silicon)`,
);
const command = `node "${config.CLI_PATH}" "https://github.com" --name "${testName}" --width 1200 --height 800 --hide-title-bar --multi-arch`;
const child = spawn(command, {
shell: true,
cwd: config.PROJECT_ROOT,
stdio: ["pipe", "pipe", "pipe"],
env: {
...process.env,
PAKE_CREATE_APP: "1",
HDIUTIL_QUIET: "1",
HDIUTIL_NO_AUTOOPEN: "1",
},
});
let buildStarted = false;
let compilationStarted = false;
// Track progress
child.stdout.on("data", (data) => {
const output = data.toString();
if (output.includes("Installing package")) {
console.log(" [Package] Installing dependencies...");
}
if (output.includes("Building app")) {
buildStarted = true;
console.log(" [Build] Multi-arch build started...");
}
if (output.includes("Compiling")) {
compilationStarted = true;
console.log(" ⚙️ Compiling for multiple architectures...");
}
if (
output.includes("universal-apple-darwin") ||
output.includes("Universal")
) {
console.log(" [Multi] Universal binary target detected");
}
if (output.includes("Bundling")) {
console.log(" [Package] Bundling universal binary...");
}
if (output.includes("Built application at:")) {
console.log(" [PASS] Multi-arch build completed!");
}
});
child.stderr.on("data", (data) => {
const output = data.toString();
if (output.includes("Building app")) buildStarted = true;
if (output.includes("Compiling")) compilationStarted = true;
if (output.includes("Finished"))
console.log(" [PASS] Multi-arch compilation finished!");
});
// Multi-arch builds take longer - 20 minutes timeout
const timeout = setTimeout(() => {
console.log(
" [Check] Multi-arch build timeout reached, checking for output files...",
);
const foundFiles = this.findBuildOutputFiles(testName, "darwin");
if (foundFiles.length > 0) {
console.log(
" [Success] Multi-arch build completed successfully!",
);