jsgui3-server 0.0.138 → 0.0.140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +87 -0
- package/README.md +12 -0
- package/docs/GUIDE_TO_AGENTIC_WORKFLOWS_BY_GROK.md +19 -0
- package/docs/advanced-usage-examples.md +1360 -0
- package/docs/agent-development-guide.md +386 -0
- package/docs/api-reference.md +916 -0
- package/docs/broken-functionality-tracker.md +285 -0
- package/docs/bundling-system-deep-dive.md +525 -0
- package/docs/cli-reference.md +393 -0
- package/docs/comprehensive-documentation.md +1403 -0
- package/docs/configuration-reference.md +808 -0
- package/docs/controls-development.md +859 -0
- package/docs/documentation-review/CURRENT_REVIEW.md +95 -0
- package/docs/function-publishers-json-apis.md +847 -0
- package/docs/getting-started-with-json.md +518 -0
- package/docs/minification-compression-sourcemaps-status.md +482 -0
- package/docs/minification-compression-sourcemaps-test-results.md +205 -0
- package/docs/publishers-guide.md +313 -0
- package/docs/resources-guide.md +615 -0
- package/docs/serve-helpers.md +406 -0
- package/docs/simple-server-api-design.md +13 -0
- package/docs/system-architecture.md +275 -0
- package/docs/troubleshooting.md +698 -0
- package/examples/json/README.md +115 -0
- package/examples/json/basic-api/README.md +345 -0
- package/examples/json/basic-api/server.js +199 -0
- package/examples/json/simple-api/README.md +125 -0
- package/examples/json/simple-api/diagnostic-report.json +73 -0
- package/examples/json/simple-api/diagnostic-test.js +433 -0
- package/examples/json/simple-api/server-debug.md +58 -0
- package/examples/json/simple-api/server.js +91 -0
- package/examples/json/simple-api/test.js +215 -0
- package/http/responders/static/Static_Route_HTTP_Responder.js +1 -2
- package/package.json +19 -8
- package/publishers/helpers/assigners/static-compressed-response-buffers/Single_Control_Webpage_Server_Static_Compressed_Response_Buffers_Assigner.js +65 -12
- package/publishers/helpers/preparers/static/bundle/Static_Routes_Responses_Webpage_Bundle_Preparer.js +6 -1
- package/publishers/http-function-publisher.js +59 -38
- package/publishers/http-webpage-publisher.js +48 -1
- package/resources/processors/bundlers/js/esbuild/Advanced_JS_Bundler_Using_ESBuild.js +38 -146
- package/resources/processors/bundlers/js/esbuild/Core_JS_Non_Minifying_Bundler_Using_ESBuild.js +54 -5
- package/resources/processors/bundlers/js/esbuild/Core_JS_Single_File_Minifying_Bundler_Using_ESBuild.js +36 -4
- package/serve-factory.js +36 -9
- package/server.js +10 -4
- package/test-report.json +0 -0
- package/tests/README.md +250 -0
- package/tests/assigners.test.js +316 -0
- package/tests/bundlers.test.js +329 -0
- package/tests/configuration-validation.test.js +530 -0
- package/tests/content-analysis.test.js +641 -0
- package/tests/end-to-end.test.js +496 -0
- package/tests/error-handling.test.js +746 -0
- package/tests/performance.test.js +653 -0
- package/tests/publishers.test.js +395 -0
- package/tests/temp_invalid.js +7 -0
- package/tests/temp_invalid_utf8.js +1 -0
- package/tests/temp_malformed.js +10 -0
- package/tests/test-runner.js +261 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const { describe, it, beforeEach, afterEach } = require('mocha');
|
|
3
|
+
const fs = require('fs').promises;
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
// Import bundler classes
|
|
7
|
+
const Core_JS_Non_Minifying_Bundler_Using_ESBuild = require('../resources/processors/bundlers/js/esbuild/Core_JS_Non_Minifying_Bundler_Using_ESBuild');
|
|
8
|
+
const Core_JS_Single_File_Minifying_Bundler_Using_ESBuild = require('../resources/processors/bundlers/js/esbuild/Core_JS_Single_File_Minifying_Bundler_Using_ESBuild');
|
|
9
|
+
const Advanced_JS_Bundler_Using_ESBuild = require('../resources/processors/bundlers/js/esbuild/Advanced_JS_Bundler_Using_ESBuild');
|
|
10
|
+
|
|
11
|
+
describe('Bundler Component Isolation Tests', function() {
|
|
12
|
+
this.timeout(30000); // Increase timeout for bundling operations
|
|
13
|
+
|
|
14
|
+
let testJsFile;
|
|
15
|
+
let testJsContent;
|
|
16
|
+
|
|
17
|
+
beforeEach(async function() {
|
|
18
|
+
// Create a temporary test JS file
|
|
19
|
+
testJsContent = `
|
|
20
|
+
// Test JavaScript with CSS
|
|
21
|
+
const css = \`
|
|
22
|
+
.test-class {
|
|
23
|
+
color: red;
|
|
24
|
+
font-size: 14px;
|
|
25
|
+
}
|
|
26
|
+
\`;
|
|
27
|
+
|
|
28
|
+
// Add CSS to document
|
|
29
|
+
const style = document.createElement('style');
|
|
30
|
+
style.textContent = css;
|
|
31
|
+
document.head.appendChild(style);
|
|
32
|
+
|
|
33
|
+
// Test function
|
|
34
|
+
function testFunction() {
|
|
35
|
+
console.log('Hello from test function');
|
|
36
|
+
return 'test result';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Export for testing
|
|
40
|
+
module.exports = { testFunction };
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
testJsFile = path.join(__dirname, 'temp_test.js');
|
|
44
|
+
await fs.writeFile(testJsFile, testJsContent);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
afterEach(async function() {
|
|
48
|
+
// Clean up temporary file
|
|
49
|
+
try {
|
|
50
|
+
await fs.unlink(testJsFile);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
// Ignore if file doesn't exist
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('Core_JS_Non_Minifying_Bundler_Using_ESBuild', function() {
|
|
57
|
+
it('should bundle JavaScript without minification', async function() {
|
|
58
|
+
const bundler = new Core_JS_Non_Minifying_Bundler_Using_ESBuild();
|
|
59
|
+
|
|
60
|
+
const result = await bundler.bundle(testJsFile);
|
|
61
|
+
|
|
62
|
+
assert(Array.isArray(result), 'Result should be an array');
|
|
63
|
+
assert.strictEqual(result.length, 1, 'Should return one bundle');
|
|
64
|
+
|
|
65
|
+
const bundle = result[0];
|
|
66
|
+
assert(bundle._arr, 'Bundle should have _arr property');
|
|
67
|
+
assert.strictEqual(bundle._arr.length, 1, 'Bundle should contain one item');
|
|
68
|
+
|
|
69
|
+
const bundleItem = bundle._arr[0];
|
|
70
|
+
assert.strictEqual(bundleItem.type, 'JavaScript', 'Bundle item should be JavaScript type');
|
|
71
|
+
assert.strictEqual(bundleItem.extension, 'js', 'Bundle item should have js extension');
|
|
72
|
+
assert(bundleItem.text, 'Bundle item should have text content');
|
|
73
|
+
assert(bundleItem.text.length > 0, 'Bundle text should not be empty');
|
|
74
|
+
|
|
75
|
+
// Verify the bundled code contains our test content
|
|
76
|
+
assert(bundleItem.text.includes('testFunction'), 'Bundled code should contain testFunction');
|
|
77
|
+
assert(bundleItem.text.includes('Hello from test function'), 'Bundled code should contain test string');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should handle sourcemap configuration in debug mode', async function() {
|
|
81
|
+
const bundler = new Core_JS_Non_Minifying_Bundler_Using_ESBuild({
|
|
82
|
+
debug: true,
|
|
83
|
+
sourcemaps: { enabled: true, format: 'inline' }
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const result = await bundler.bundle(testJsFile);
|
|
87
|
+
const bundleItem = result[0]._arr[0];
|
|
88
|
+
|
|
89
|
+
// In debug mode with sourcemaps enabled, should include sourcemap
|
|
90
|
+
assert(bundleItem.text.includes('//# sourceMappingURL='), 'Debug bundle should include inline sourcemap');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should handle sourcemap configuration in production mode', async function() {
|
|
94
|
+
const bundler = new Core_JS_Non_Minifying_Bundler_Using_ESBuild({
|
|
95
|
+
debug: false,
|
|
96
|
+
sourcemaps: { enabled: false }
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const result = await bundler.bundle(testJsFile);
|
|
100
|
+
const bundleItem = result[0]._arr[0];
|
|
101
|
+
|
|
102
|
+
// In production mode with sourcemaps disabled, should not include sourcemap
|
|
103
|
+
assert(!bundleItem.text.includes('//# sourceMappingURL='), 'Production bundle should not include sourcemap');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('should bundle JavaScript string directly', async function() {
|
|
107
|
+
const bundler = new Core_JS_Non_Minifying_Bundler_Using_ESBuild();
|
|
108
|
+
|
|
109
|
+
const jsString = `
|
|
110
|
+
function directTest() {
|
|
111
|
+
return 'direct result';
|
|
112
|
+
}
|
|
113
|
+
console.log('Direct bundle test');
|
|
114
|
+
`;
|
|
115
|
+
|
|
116
|
+
const result = await bundler.bundle_js_string(jsString);
|
|
117
|
+
|
|
118
|
+
assert(Array.isArray(result), 'Result should be an array');
|
|
119
|
+
const bundle = result[0];
|
|
120
|
+
const bundleItem = bundle._arr[0];
|
|
121
|
+
|
|
122
|
+
assert.strictEqual(bundleItem.type, 'JavaScript');
|
|
123
|
+
assert(bundleItem.text.includes('directTest'), 'Should contain the direct test function');
|
|
124
|
+
assert(bundleItem.text.includes('Direct bundle test'), 'Should contain the test log');
|
|
125
|
+
// Verify the function is actually executable
|
|
126
|
+
const testFunction = new Function(bundleItem.text + '; return directTest;')();
|
|
127
|
+
assert.strictEqual(testFunction(), 'direct result', 'Bundled function should be executable');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('Core_JS_Single_File_Minifying_Bundler_Using_ESBuild', function() {
|
|
132
|
+
it('should minify JavaScript with default settings', async function() {
|
|
133
|
+
const bundler = new Core_JS_Single_File_Minifying_Bundler_Using_ESBuild();
|
|
134
|
+
|
|
135
|
+
const result = await bundler.bundle(testJsContent);
|
|
136
|
+
|
|
137
|
+
assert(Array.isArray(result), 'Result should be an array');
|
|
138
|
+
assert.strictEqual(result.length, 1, 'Should return one bundle');
|
|
139
|
+
|
|
140
|
+
const bundle = result[0];
|
|
141
|
+
const bundleItem = bundle._arr[0];
|
|
142
|
+
|
|
143
|
+
assert.strictEqual(bundleItem.type, 'JavaScript');
|
|
144
|
+
assert.strictEqual(bundleItem.extension, 'js');
|
|
145
|
+
|
|
146
|
+
// Verify minification occurred (should be much shorter)
|
|
147
|
+
assert(bundleItem.text.length < testJsContent.length,
|
|
148
|
+
'Minified code should be shorter than original');
|
|
149
|
+
|
|
150
|
+
// Verify functionality is preserved (contains key identifiers)
|
|
151
|
+
assert(bundleItem.text.includes('testFunction'), 'Should contain testFunction after minification');
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should handle different minification levels', async function() {
|
|
155
|
+
// Test conservative minification
|
|
156
|
+
const conservativeBundler = new Core_JS_Single_File_Minifying_Bundler_Using_ESBuild({
|
|
157
|
+
minify: { level: 'conservative' }
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const conservativeResult = await conservativeBundler.bundle(testJsContent);
|
|
161
|
+
const conservativeText = conservativeResult[0]._arr[0].text;
|
|
162
|
+
|
|
163
|
+
// Test normal minification
|
|
164
|
+
const normalBundler = new Core_JS_Single_File_Minifying_Bundler_Using_ESBuild({
|
|
165
|
+
minify: { level: 'normal' }
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const normalResult = await normalBundler.bundle(testJsContent);
|
|
169
|
+
const normalText = normalResult[0]._arr[0].text;
|
|
170
|
+
|
|
171
|
+
// Test aggressive minification
|
|
172
|
+
const aggressiveBundler = new Core_JS_Single_File_Minifying_Bundler_Using_ESBuild({
|
|
173
|
+
minify: { level: 'aggressive' }
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const aggressiveResult = await aggressiveBundler.bundle(testJsContent);
|
|
177
|
+
const aggressiveText = aggressiveResult[0]._arr[0].text;
|
|
178
|
+
|
|
179
|
+
// All should be valid and contain the function
|
|
180
|
+
assert(conservativeText.includes('testFunction'), 'Conservative minification should preserve function');
|
|
181
|
+
assert(normalText.includes('testFunction'), 'Normal minification should preserve function');
|
|
182
|
+
assert(aggressiveText.includes('testFunction'), 'Aggressive minification should preserve function');
|
|
183
|
+
|
|
184
|
+
// Verify different levels produce different results (at least some difference)
|
|
185
|
+
const texts = [conservativeText, normalText, aggressiveText];
|
|
186
|
+
const uniqueTexts = new Set(texts);
|
|
187
|
+
assert(uniqueTexts.size >= 2, 'Different minification levels should produce different outputs');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('should disable minification when configured', async function() {
|
|
191
|
+
const bundler = new Core_JS_Single_File_Minifying_Bundler_Using_ESBuild({
|
|
192
|
+
minify: { enabled: false }
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const result = await bundler.bundle(testJsContent);
|
|
196
|
+
const bundleItem = result[0]._arr[0];
|
|
197
|
+
|
|
198
|
+
// When minification is disabled, should return the original content structure
|
|
199
|
+
// (though ESBuild still does some processing like bundling)
|
|
200
|
+
assert(bundleItem.text.includes('testFunction'), 'Should contain testFunction');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('should handle custom minification options', async function() {
|
|
204
|
+
const bundler = new Core_JS_Single_File_Minifying_Bundler_Using_ESBuild({
|
|
205
|
+
minify: {
|
|
206
|
+
level: 'normal',
|
|
207
|
+
options: {
|
|
208
|
+
mangle: false, // Disable variable name mangling
|
|
209
|
+
compress: { sequences: false }
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const result = await bundler.bundle(testJsContent);
|
|
215
|
+
const bundleItem = result[0]._arr[0];
|
|
216
|
+
|
|
217
|
+
// With mangle: false, should preserve variable names
|
|
218
|
+
assert(bundleItem.text.includes('testFunction'), 'Should preserve function name when mangling disabled');
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
describe('Advanced_JS_Bundler_Using_ESBuild', function() {
|
|
223
|
+
it('should perform advanced bundling with CSS extraction', async function() {
|
|
224
|
+
const bundler = new Advanced_JS_Bundler_Using_ESBuild();
|
|
225
|
+
|
|
226
|
+
const result = await bundler.bundle(testJsFile);
|
|
227
|
+
|
|
228
|
+
assert(Array.isArray(result), 'Result should be an array');
|
|
229
|
+
assert.strictEqual(result.length, 1, 'Should return one bundle');
|
|
230
|
+
|
|
231
|
+
const bundle = result[0];
|
|
232
|
+
assert(bundle._arr, 'Bundle should have _arr property');
|
|
233
|
+
assert.strictEqual(bundle._arr.length, 2, 'Bundle should contain JS and CSS items');
|
|
234
|
+
|
|
235
|
+
// Find JS and CSS items
|
|
236
|
+
const jsItem = bundle._arr.find(item => item.type === 'JavaScript');
|
|
237
|
+
const cssItem = bundle._arr.find(item => item.type === 'CSS');
|
|
238
|
+
|
|
239
|
+
assert(jsItem, 'Should contain JavaScript item');
|
|
240
|
+
assert(cssItem, 'Should contain CSS item');
|
|
241
|
+
|
|
242
|
+
assert.strictEqual(jsItem.extension, 'js');
|
|
243
|
+
assert.strictEqual(cssItem.extension, 'css');
|
|
244
|
+
|
|
245
|
+
// Verify CSS was extracted
|
|
246
|
+
assert(cssItem.text.includes('.test-class'), 'CSS should contain the test class');
|
|
247
|
+
assert(cssItem.text.includes('color: red'), 'CSS should contain the color property');
|
|
248
|
+
|
|
249
|
+
// Verify JS no longer contains CSS
|
|
250
|
+
assert(!jsItem.text.includes('.test-class'), 'JS should not contain CSS after extraction');
|
|
251
|
+
assert(jsItem.text.includes('testFunction'), 'JS should still contain the test function');
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('should handle debug mode with sourcemaps', async function() {
|
|
255
|
+
const bundler = new Advanced_JS_Bundler_Using_ESBuild({
|
|
256
|
+
debug: true,
|
|
257
|
+
bundler: {
|
|
258
|
+
sourcemaps: { enabled: true, format: 'inline' }
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const result = await bundler.bundle(testJsFile);
|
|
263
|
+
const jsItem = result[0]._arr.find(item => item.type === 'JavaScript');
|
|
264
|
+
|
|
265
|
+
// In debug mode, should include sourcemaps
|
|
266
|
+
assert(jsItem.text.includes('//# sourceMappingURL='), 'Debug mode should include inline sourcemaps');
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('should handle production mode with minification', async function() {
|
|
270
|
+
const bundler = new Advanced_JS_Bundler_Using_ESBuild({
|
|
271
|
+
debug: false,
|
|
272
|
+
bundler: {
|
|
273
|
+
minify: { enabled: true, level: 'normal' }
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
const result = await bundler.bundle(testJsFile);
|
|
278
|
+
const jsItem = result[0]._arr.find(item => item.type === 'JavaScript');
|
|
279
|
+
|
|
280
|
+
// In production mode, should be minified
|
|
281
|
+
assert(jsItem.text.length < testJsContent.length, 'Production JS should be minified');
|
|
282
|
+
assert(jsItem.text.includes('testFunction'), 'Should still contain function after minification');
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('should pass configuration to sub-bundlers', async function() {
|
|
286
|
+
const bundler = new Advanced_JS_Bundler_Using_ESBuild({
|
|
287
|
+
debug: true,
|
|
288
|
+
bundler: {
|
|
289
|
+
minify: { level: 'aggressive' },
|
|
290
|
+
sourcemaps: { enabled: true, format: 'inline' }
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// Verify configuration is stored
|
|
295
|
+
assert.deepStrictEqual(bundler.bundler_config.minify, { level: 'aggressive' });
|
|
296
|
+
assert.deepStrictEqual(bundler.bundler_config.sourcemaps, { enabled: true, format: 'inline' });
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
describe('Error Handling', function() {
|
|
301
|
+
it('should handle invalid JavaScript gracefully', async function() {
|
|
302
|
+
const bundler = new Core_JS_Non_Minifying_Bundler_Using_ESBuild();
|
|
303
|
+
|
|
304
|
+
const invalidJs = `
|
|
305
|
+
function test() {
|
|
306
|
+
// Missing closing brace
|
|
307
|
+
console.log('invalid syntax'
|
|
308
|
+
`;
|
|
309
|
+
|
|
310
|
+
try {
|
|
311
|
+
await bundler.bundle_js_string(invalidJs);
|
|
312
|
+
assert.fail('Should have thrown an error for invalid JavaScript');
|
|
313
|
+
} catch (error) {
|
|
314
|
+
assert(error, 'Should throw an error for invalid JavaScript');
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('should handle non-existent files', async function() {
|
|
319
|
+
const bundler = new Core_JS_Non_Minifying_Bundler_Using_ESBuild();
|
|
320
|
+
|
|
321
|
+
try {
|
|
322
|
+
await bundler.bundle('/non/existent/file.js');
|
|
323
|
+
assert.fail('Should have thrown an error for non-existent file');
|
|
324
|
+
} catch (error) {
|
|
325
|
+
assert(error, 'Should throw an error for non-existent file');
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
});
|