فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A07): exercise Windows Edge offline app startup and three auth-overlay reloads
davoodmehraban89 committed
Oct 15, 2026 at 20:56 UTC
a77bedba8a9492c89e66e05c2a584910761cd566
1 file changed
+140
tests/a07-windows-offline-browser-smoke.cjs
new
+140
@@ -0,0 +1,140 @@
1
+// Windows Edge smoke of the built, self-hosted frontend on a disposable profile.
2
+// Intentionally does not touch any installed application's real IndexedDB.
3
+// The --host-resolver-rules option disallows external DNS while allowing loopback.
4
+'use strict';
5
+const assert = require('node:assert/strict');
6
+const fs = require('node:fs');
7
+const os = require('node:os');
8
+const path = require('node:path');
9
+const { spawn } = require('node:child_process');
10
+
11
+const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
12
+async function eventually(fn, timeoutMs = 25000, intervalMs = 400) {
13
+ const started = Date.now();
14
+ let lastError;
15
+ while (Date.now() - started < timeoutMs) {
16
+ try { const result = await fn(); if (result) return result; }
17
+ catch (e) { lastError = e; }
18
+ await sleep(intervalMs);
19
+ }
20
+ throw lastError || Error('Browser startup timed out');
21
+}
22
+async function getJSON(url) {
23
+ const res = await fetch(url, { signal: AbortSignal.timeout(2500) });
24
+ if (!res.ok) throw Error('HTTP ' + res.status);
25
+ return res.json();
26
+}
27
+async function loadChromeCDP(wsURL) {
28
+ const ws = new WebSocket(wsURL);
29
+ await new Promise((resolve, reject) => {
30
+ const timer = setTimeout(() => reject(Error('CDP websocket timeout')), 10000);
31
+ ws.addEventListener('open', () => { clearTimeout(timer); resolve(); }, { once: true });
32
+ ws.addEventListener('error', event => { clearTimeout(timer); reject(Error('CDP failed: ' + event.type)); }, { once: true });
33
+ });
34
+ let counter = 0;
35
+ const pending = new Map();
36
+ ws.addEventListener('message', event => {
37
+ const reply = JSON.parse(event.data);
38
+ const item = pending.get(reply.id);
39
+ if (!item) return;
40
+ clearTimeout(item.timer);
41
+ pending.delete(reply.id);
42
+ if (reply.error) item.reject(Error(JSON.stringify(reply.error)));
43
+ else item.resolve(reply.result);
44
+ });
45
+ const command = (method, params = {}) => new Promise((resolve, reject) => {
46
+ const id = ++counter;
47
+ const timer = setTimeout(() => {
48
+ pending.delete(id); reject(Error('CDP command timed out: ' + method));
49
+ }, 25000);
50
+ pending.set(id, { resolve, reject, timer });
51
+ ws.send(JSON.stringify({ id, method, params }));
52
+ });
53
+ const evaluate = async expression => {
54
+ const result = await command('Runtime.evaluate', {
55
+ expression, returnByValue: true, awaitPromise: true
56
+ });
57
+ if (result.exceptionDetails) throw Error(
58
+ 'Browser runtime error: ' + (result.exceptionDetails.text || 'Unknown')
59
+ );
60
+ return result.result.value;
61
+ };
62
+ await command('Page.enable');
63
+ await command('Runtime.enable');
64
+ return { command, evaluate, close: () => ws.close() };
65
+}
66
+
67
+(async () => {
68
+ assert.equal(process.platform, 'win32', 'Only run on a disposable Windows CI runner');
69
+ const edgePaths = [
70
+ 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe',
71
+ 'C:\\Program Files\\Microsoft\\Edge\\Application\\msedge.exe'
72
+ ];
73
+ const edgeBinary = edgePaths.find(fs.existsSync);
74
+ assert.ok(edgeBinary, 'Windows Edge headless executable missing');
75
+ const tempProfile = fs.mkdtempSync(path.join(os.tmpdir(), 'factoreasypro-smoke-'));
76
+ const server = spawn('cmd.exe',
77
+ ['/d', '/s', '/c', 'npm run preview -- --host 127.0.0.1 --port 4173 --strictPort'],
78
+ { stdio: 'ignore', windowsHide: true });
79
+ let edge;
80
+ let cdp;
81
+ try {
82
+ await eventually(async () => {
83
+ const response = await fetch('http://127.0.0.1:4173/', {
84
+ signal: AbortSignal.timeout(1500)
85
+ });
86
+ return response.ok;
87
+ });
88
+ edge = spawn(edgeBinary, [
89
+ '--headless=new', '--disable-gpu', '--no-first-run', '--no-default-browser-check',
90
+ '--disable-extensions', '--remote-debugging-port=9339',
91
+ '--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1',
92
+ '--user-data-dir=' + tempProfile, 'http://127.0.0.1:4173/'
93
+ ], { stdio: 'ignore', windowsHide: true });
94
+ const wsURL = await eventually(async () => {
95
+ const pages = await getJSON('http://127.0.0.1:9339/json');
96
+ return pages.find(x => x.type === 'page' &&
97
+ x.url.startsWith('http://127.0.0.1:4173'))?.webSocketDebuggerUrl;
98
+ });
99
+ cdp = await loadChromeCDP(wsURL);
100
+ const report = [];
101
+ for (let i = 0; i < 3; i++) {
102
+ if (i > 0) {
103
+ await cdp.command('Page.reload', { ignoreCache: true });
104
+ await sleep(900);
105
+ }
106
+ const state = await cdp.evaluate(`(async () => {
107
+ for (let j = 0; j < 180; j++) {
108
+ const hasAuth = !!document.getElementById('finoraAuthOverlay');
109
+ const loaded = !!window.FINORA;
110
+ if (hasAuth && loaded) {
111
+ return {
112
+ hasAuth, loaded, version: window.FINORA.version,
113
+ errors: document.querySelector('#faError')?.textContent || '',
114
+ browserExternalScripts: [...document.querySelectorAll('script[src],link[rel="stylesheet"][href]')]
115
+ .map(x => x.src || x.href)
116
+ .filter(x => /^https?:/.test(x) && !x.startsWith('http://127.0.0.1:4173'))
117
+ };
118
+ }
119
+ await new Promise(resolve => setTimeout(resolve, 100));
120
+ }
121
+ throw Error('Authentication overlay never appeared; startup may be stalled');
122
+ })()`);
123
+ assert.equal(state.hasAuth, true);
124
+ assert.equal(state.loaded, true);
125
+ assert.equal(state.errors, '');
126
+ assert.deepEqual(state.browserExternalScripts, []);
127
+ report.push({ attempt: i + 1, version: state.version, authOverlay: true,
128
+ externalScripts: state.browserExternalScripts.length });
129
+ }
130
+ console.log(JSON.stringify({ smoke: 'passed', profile: 'disposable',
131
+ browser: 'Windows Edge', offlineDNS: true, attempts: report }, null, 2));
132
+ } finally {
133
+ cdp?.close();
134
+ if (edge && !edge.killed) edge.kill();
135
+ if (server && !server.killed) server.kill();
136
+ await sleep(500);
137
+ try { fs.rmSync(tempProfile, { recursive: true, force: true, maxRetries: 5, retryDelay: 300 }); }
138
+ catch { /* The Windows runner cleans up the temporary profile. */ }
139
+ }
140
+})().catch(error => { console.error(error.stack || error); process.exitCode = 1; });