biz-a-cli 2.3.65 → 2.3.67
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/bin/app.js +27 -5
- package/package.json +1 -1
- package/tests/app.test.js +160 -33
package/bin/app.js
CHANGED
|
@@ -5,7 +5,7 @@ import axios from "axios"
|
|
|
5
5
|
import fs from "fs"
|
|
6
6
|
import * as tar from "tar"
|
|
7
7
|
import { verify, sign, privateDecrypt, constants as cryptoConstants } from "node:crypto"
|
|
8
|
-
import { basename } from "node:path"
|
|
8
|
+
import path, { basename } from "node:path"
|
|
9
9
|
import { env } from "../envs/env.js"
|
|
10
10
|
import { prepareScript, encryptScript } from "./script.js"
|
|
11
11
|
import { spawn } from "node:child_process"
|
|
@@ -124,9 +124,32 @@ Object
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
async function runUnitTests() { //SCY BZ 4331
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
let jestCommand = ['--no-install', 'jest', '--json'];
|
|
128
|
+
let output = '';
|
|
129
|
+
|
|
130
|
+
const testDir = path.join(options.workingDir, "test");
|
|
131
|
+
const workDir = path.resolve(options.workingDir);
|
|
132
|
+
try {
|
|
133
|
+
process.chdir(testDir)
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (error.code === 'ENOENT') {
|
|
136
|
+
jestCommand.push('--passWithNoTests')
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const child = spawn('npx', jestCommand, { shell: true });
|
|
140
|
+
child.stderr.on('data', data => output += data?.toString())
|
|
141
|
+
child.on('close', async code => {
|
|
142
|
+
console.log('====================');
|
|
143
|
+
console.log(output);
|
|
144
|
+
console.log('====================');
|
|
145
|
+
let noTestsFound = output.includes('No tests found');
|
|
146
|
+
let missingJest = (output.includes('missing packages') && output.includes('jest'));
|
|
147
|
+
let passWithNoTests = jestCommand.includes('--passWithNoTests');
|
|
148
|
+
|
|
149
|
+
if ((code == 0) ||
|
|
150
|
+
((code == 1) && noTestsFound) ||
|
|
151
|
+
((code == 1) && missingJest && passWithNoTests)) {
|
|
152
|
+
process.chdir(workDir)
|
|
130
153
|
await addApp()
|
|
131
154
|
} else {
|
|
132
155
|
console.error('Biz-A Add aborted');
|
|
@@ -140,7 +163,6 @@ Object
|
|
|
140
163
|
base64 => 4 char = 3 bytes => can be encrypted. Smaller size compare to Hex
|
|
141
164
|
utf8 => 1 char = 1 - 4 bytes => can not be encrypted, encryption need precise bytes per Character. Smallest Size compare to Hex and base64
|
|
142
165
|
*/
|
|
143
|
-
process.chdir(options.workingDir)
|
|
144
166
|
try {
|
|
145
167
|
const bundlingStart = performance.now()
|
|
146
168
|
const rootFolder = './upload/'
|
package/package.json
CHANGED
package/tests/app.test.js
CHANGED
|
@@ -8,7 +8,10 @@ import { env } from "../envs/env.js"
|
|
|
8
8
|
|
|
9
9
|
describe('Biz-A Apps CLI', () => {
|
|
10
10
|
let originalOptions, originalCWD, axios, child_process;
|
|
11
|
+
|
|
12
|
+
const JEST_MESSAGE_TOTAL = 3;
|
|
11
13
|
let returnedCode = 0;
|
|
14
|
+
let jestMessage = '';
|
|
12
15
|
|
|
13
16
|
const logSpy = jest.spyOn(global.console, 'log').mockImplementation()
|
|
14
17
|
const errorSpy = jest.spyOn(global.console, 'error').mockImplementation()
|
|
@@ -41,12 +44,15 @@ describe('Biz-A Apps CLI', () => {
|
|
|
41
44
|
jest.unstable_mockModule('node:child_process', () => ({
|
|
42
45
|
spawn: jest.fn().mockReturnValue({
|
|
43
46
|
on: jest.fn((event, callback) => {
|
|
44
|
-
if (event === "close")
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
if (event === "close") callback(returnedCode)
|
|
48
|
+
}),
|
|
49
|
+
stderr: {
|
|
50
|
+
on: jest.fn((event, callback) => {
|
|
51
|
+
if (event === "data") callback(jestMessage)
|
|
52
|
+
})
|
|
53
|
+
}
|
|
48
54
|
})
|
|
49
|
-
}))
|
|
55
|
+
}))
|
|
50
56
|
child_process = (await import('node:child_process'));
|
|
51
57
|
})
|
|
52
58
|
|
|
@@ -242,8 +248,8 @@ describe('Biz-A Apps CLI', () => {
|
|
|
242
248
|
|
|
243
249
|
expect(postArgs[2]).toStrictEqual({ "headers": { "Content-Type": "text/plain" } })
|
|
244
250
|
|
|
245
|
-
expect(logSpy.mock.calls[0][0]).toContain(`Finished packing ${Object.keys(mockScripts).length} files into "./upload/${appName.toLowerCase()}.tgz"`)
|
|
246
|
-
expect(logSpy.mock.calls[1][0]).toContain(`Finished uploading "./upload/${appName.toLocaleLowerCase()}.tgz"`)
|
|
251
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 0][0]).toContain(`Finished packing ${Object.keys(mockScripts).length} files into "./upload/${appName.toLowerCase()}.tgz"`)
|
|
252
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 1][0]).toContain(`Finished uploading "./upload/${appName.toLocaleLowerCase()}.tgz"`)
|
|
247
253
|
|
|
248
254
|
// fs.rmSync(mockDataFolder + '/' + appName, {recursive: true, force: true})
|
|
249
255
|
})
|
|
@@ -303,12 +309,12 @@ describe('Biz-A Apps CLI', () => {
|
|
|
303
309
|
'Invalid script syntax',
|
|
304
310
|
{ act: 'get = function () {return {modelA: {}}' }, // missing close closure at the end',
|
|
305
311
|
() => {
|
|
306
|
-
expect(logSpy.mock.calls.length).toBe(5)
|
|
307
|
-
expect(logSpy.mock.calls[0][0]).toBe('===================\nA.JS\n===================')
|
|
308
|
-
expect(logSpy.mock.calls[1][0]).toBe('Running script with VM') // node sandbox (VN) error as console.log
|
|
309
|
-
expect(logSpy.mock.calls[2][0]).toStrictEqual('a.js:1:38: SyntaxError: Unexpected token: eof, expected: punc «}»')
|
|
310
|
-
expect(logSpy.mock.calls[3][0]).toStrictEqual('Running script with Import function')
|
|
311
|
-
expect(logSpy.mock.calls[4][0]).toStrictEqual('===================\nEOF A.JS\n===================')
|
|
312
|
+
expect(logSpy.mock.calls.length).toBe(JEST_MESSAGE_TOTAL + 5)
|
|
313
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 0][0]).toBe('===================\nA.JS\n===================')
|
|
314
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 1][0]).toBe('Running script with VM') // node sandbox (VN) error as console.log
|
|
315
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 2][0]).toStrictEqual('a.js:1:38: SyntaxError: Unexpected token: eof, expected: punc «}»')
|
|
316
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 3][0]).toStrictEqual('Running script with Import function')
|
|
317
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 4][0]).toStrictEqual('===================\nEOF A.JS\n===================')
|
|
312
318
|
|
|
313
319
|
expect(errorSpy.mock.calls.length).toBe(1)
|
|
314
320
|
expect(errorSpy.mock.calls[0][0]).toBe('a.js : SyntaxError: Unexpected end of input')
|
|
@@ -318,13 +324,13 @@ describe('Biz-A Apps CLI', () => {
|
|
|
318
324
|
'Failed to compile script with node sandbox and ES6 Import',
|
|
319
325
|
{ act: 'get = function () {return {modelA: {}}}\n modul.expor = get;\n' }, // wrong "module.export"
|
|
320
326
|
() => {
|
|
321
|
-
expect(logSpy.mock.calls.length).toBe(6)
|
|
322
|
-
expect(logSpy.mock.calls[0][0]).toBe('===================\nA.JS\n===================')
|
|
323
|
-
expect(logSpy.mock.calls[1][0]).toBe('Running script with VM') // node sandbox (VN) error as console.log
|
|
324
|
-
expect(logSpy.mock.calls[2][0]).toBe('Minify : \nget=function(){return{modelA:{}}};modul.expor=get;')
|
|
325
|
-
expect(logSpy.mock.calls[3][0]).toBe("a.js : ReferenceError: modul is not defined")
|
|
326
|
-
expect(logSpy.mock.calls[4][0]).toBe('Running script with Import function')
|
|
327
|
-
expect(logSpy.mock.calls[5][0]).toStrictEqual('===================\nEOF A.JS\n===================')
|
|
327
|
+
expect(logSpy.mock.calls.length).toBe(JEST_MESSAGE_TOTAL + 6)
|
|
328
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 0][0]).toBe('===================\nA.JS\n===================')
|
|
329
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 1][0]).toBe('Running script with VM') // node sandbox (VN) error as console.log
|
|
330
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 2][0]).toBe('Minify : \nget=function(){return{modelA:{}}};modul.expor=get;')
|
|
331
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 3][0]).toBe("a.js : ReferenceError: modul is not defined")
|
|
332
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 4][0]).toBe('Running script with Import function')
|
|
333
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 5][0]).toStrictEqual('===================\nEOF A.JS\n===================')
|
|
328
334
|
|
|
329
335
|
expect(errorSpy.mock.calls.length).toBe(1)
|
|
330
336
|
expect(errorSpy.mock.calls[0][0]).toStrictEqual('a.js : Error: Invalid data URI')// ES6 import error
|
|
@@ -334,12 +340,12 @@ describe('Biz-A Apps CLI', () => {
|
|
|
334
340
|
'Shall not allow empty script',
|
|
335
341
|
{ act: 'get = function () {}' }, // empty script
|
|
336
342
|
() => {
|
|
337
|
-
expect(logSpy.mock.calls.length).toBe(5)
|
|
338
|
-
expect(logSpy.mock.calls[0][0]).toBe('===================\nA.JS\n===================')
|
|
339
|
-
expect(logSpy.mock.calls[1][0]).toBe('Running script with VM') // node sandbox (VN) error as console.log
|
|
340
|
-
expect(logSpy.mock.calls[2][0]).toBe('Minify : \nget=function(){};')
|
|
341
|
-
expect(logSpy.mock.calls[3][0]).toBe('Running script with Import function')
|
|
342
|
-
expect(logSpy.mock.calls[4][0]).toStrictEqual('===================\nEOF A.JS\n===================')
|
|
343
|
+
expect(logSpy.mock.calls.length).toBe(JEST_MESSAGE_TOTAL + 5)
|
|
344
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 0][0]).toBe('===================\nA.JS\n===================')
|
|
345
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 1][0]).toBe('Running script with VM') // node sandbox (VN) error as console.log
|
|
346
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 2][0]).toBe('Minify : \nget=function(){};')
|
|
347
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 3][0]).toBe('Running script with Import function')
|
|
348
|
+
expect(logSpy.mock.calls[JEST_MESSAGE_TOTAL + 4][0]).toStrictEqual('===================\nEOF A.JS\n===================')
|
|
343
349
|
|
|
344
350
|
expect(errorSpy.mock.calls.length).toBe(1)
|
|
345
351
|
expect(errorSpy.mock.calls[0][0]).toStrictEqual('a.js : Failed to compile template script.\nPlease make sure the script is correct and not returning empty result')
|
|
@@ -359,7 +365,7 @@ describe('Biz-A Apps CLI', () => {
|
|
|
359
365
|
mockIssuerKeyResponse()
|
|
360
366
|
await runCommand('add', '-s', 'https://a.b.c', '-p', '1205', '-i', '2', '-d', mockDataFolder + '/' + expect.getState().currentTestName, "-v")
|
|
361
367
|
|
|
362
|
-
expect(logSpy.mock.calls.length).toBe(0)
|
|
368
|
+
expect(logSpy.mock.calls.length).toBe(JEST_MESSAGE_TOTAL + 0)
|
|
363
369
|
|
|
364
370
|
expect(errorSpy.mock.calls.length).toBe(1)
|
|
365
371
|
expect(errorSpy.mock.calls[0][0]).toBe('Nothing to upload. Please recheck your app folder.')
|
|
@@ -389,9 +395,7 @@ describe('Biz-A Apps CLI', () => {
|
|
|
389
395
|
expect(errorSpy.mock.calls[errorSpy.mock.calls.length - 1][0]).toBe('Unknown argument: Unknown Command')
|
|
390
396
|
})
|
|
391
397
|
|
|
392
|
-
|
|
393
|
-
returnedCode = 1;
|
|
394
|
-
|
|
398
|
+
describe('run Jest', () => { //SCY BZ 4331
|
|
395
399
|
const mockScripts = {
|
|
396
400
|
'a.js': {
|
|
397
401
|
act: 'get = function () {return {modelA: {}}}',
|
|
@@ -399,11 +403,134 @@ describe('Biz-A Apps CLI', () => {
|
|
|
399
403
|
}
|
|
400
404
|
}
|
|
401
405
|
const appName = 'compressStressTest1';
|
|
406
|
+
const fullTestPath = mockDataFolder + appName;
|
|
407
|
+
let jestArgs = ['--no-install', 'jest', '--json'];
|
|
408
|
+
let jestArgsWithPassNoTest = jestArgs.slice();
|
|
409
|
+
jestArgsWithPassNoTest.push('--passWithNoTests');
|
|
410
|
+
|
|
411
|
+
async function runJest() {
|
|
412
|
+
mockIssuerKeyResponse();
|
|
413
|
+
await runCommand('add', '-s', 'https://a.b.c', '-p', '1205', '-i', '2', '-d', fullTestPath)
|
|
414
|
+
}
|
|
402
415
|
|
|
403
|
-
|
|
404
|
-
|
|
416
|
+
function continueExpect(args) {
|
|
417
|
+
expect(child_process.spawn).toBeCalledWith("npx", args, { "shell": true });
|
|
418
|
+
expect(logSpy.mock.calls[logSpy.mock.calls.length - JEST_MESSAGE_TOTAL - 2][0]).toBe('====================');
|
|
419
|
+
expect(logSpy.mock.calls[logSpy.mock.calls.length - JEST_MESSAGE_TOTAL - 1][0]).toBe(jestMessage);
|
|
420
|
+
expect(logSpy.mock.calls[logSpy.mock.calls.length - JEST_MESSAGE_TOTAL][0]).toBe('====================');
|
|
421
|
+
expect(errorSpy.mock.calls.length).toBe(0);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function abortExpect(args) {
|
|
425
|
+
expect(child_process.spawn).toBeCalledWith("npx", args, { "shell": true });
|
|
426
|
+
expect(logSpy.mock.calls[logSpy.mock.calls.length - JEST_MESSAGE_TOTAL][0]).toBe('====================');
|
|
427
|
+
expect(logSpy.mock.calls[logSpy.mock.calls.length - JEST_MESSAGE_TOTAL + 1][0]).toBe(jestMessage);
|
|
428
|
+
expect(logSpy.mock.calls[logSpy.mock.calls.length - JEST_MESSAGE_TOTAL + 2][0]).toBe('====================');
|
|
429
|
+
expect(errorSpy.mock.calls[errorSpy.mock.calls.length - 1][0]).toBe('Biz-A Add aborted');
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
it('Shall continue add biz a template, jest found, folder test found, unit test found, unit test passed', async () => {
|
|
433
|
+
returnedCode = 0;
|
|
434
|
+
jestMessage = 'Passed';
|
|
435
|
+
|
|
436
|
+
mockValidTemplates(appName, mockScripts);
|
|
437
|
+
fs.mkdirSync(fullTestPath + '/test', { recursive: true })
|
|
438
|
+
fs.writeFileSync(fullTestPath + '/test/a.test.js', `it('dummy test', () => {
|
|
439
|
+
expect(true).toBe(true);
|
|
440
|
+
})`)
|
|
441
|
+
|
|
442
|
+
await runJest();
|
|
443
|
+
continueExpect(jestArgs);
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
it('Shall abort add biz a template, jest found, folder test found, unit test found, unit test failed', async () => {
|
|
447
|
+
returnedCode = 1;
|
|
448
|
+
jestMessage = 'FAIL';
|
|
449
|
+
|
|
450
|
+
mockValidTemplates(appName, mockScripts);
|
|
451
|
+
fs.mkdirSync(fullTestPath + '/test', { recursive: true })
|
|
452
|
+
fs.writeFileSync(fullTestPath + '/test/a.test.js', `it('dummy test', () => {
|
|
453
|
+
expect(true).toBe(false);
|
|
454
|
+
})`)
|
|
455
|
+
|
|
456
|
+
await runJest();
|
|
457
|
+
|
|
458
|
+
abortExpect(jestArgs);
|
|
459
|
+
})
|
|
405
460
|
|
|
406
|
-
|
|
461
|
+
it('Shall continue add biz a template, jest found, folder test found, no unit test', async () => {
|
|
462
|
+
returnedCode = 1;
|
|
463
|
+
jestMessage = 'No tests found';
|
|
464
|
+
|
|
465
|
+
mockValidTemplates(appName, mockScripts);
|
|
466
|
+
fs.mkdirSync(fullTestPath + '/test', { recursive: true })
|
|
467
|
+
|
|
468
|
+
await runJest();
|
|
469
|
+
|
|
470
|
+
continueExpect(jestArgs);
|
|
471
|
+
})
|
|
472
|
+
|
|
473
|
+
it('Shall continue add biz a template, jest found, no folder test', async () => {
|
|
474
|
+
returnedCode = 0;
|
|
475
|
+
jestMessage = 'No tests found';
|
|
476
|
+
|
|
477
|
+
mockValidTemplates(appName, mockScripts);
|
|
478
|
+
await runJest();
|
|
479
|
+
|
|
480
|
+
continueExpect(jestArgsWithPassNoTest);
|
|
481
|
+
})
|
|
482
|
+
|
|
483
|
+
it('Shall abort add biz a template, no jest found, folder test found, unit test found, unit test passed', async () => {
|
|
484
|
+
returnedCode = 1;
|
|
485
|
+
jestMessage = 'missing packages jest';
|
|
486
|
+
|
|
487
|
+
mockValidTemplates(appName, mockScripts);
|
|
488
|
+
fs.mkdirSync(fullTestPath + '/test', { recursive: true })
|
|
489
|
+
fs.writeFileSync(fullTestPath + '/test/a.test.js', `it('dummy test', () => {
|
|
490
|
+
expect(true).toBe(true);
|
|
491
|
+
})`)
|
|
492
|
+
|
|
493
|
+
await runJest();
|
|
494
|
+
|
|
495
|
+
abortExpect(jestArgs);
|
|
496
|
+
})
|
|
497
|
+
|
|
498
|
+
it('Shall abort add biz a template, no jest found, folder test found, unit test found, unit test failed', async () => {
|
|
499
|
+
returnedCode = 1;
|
|
500
|
+
jestMessage = 'missing packages jest';
|
|
501
|
+
|
|
502
|
+
mockValidTemplates(appName, mockScripts);
|
|
503
|
+
fs.mkdirSync(fullTestPath + '/test', { recursive: true })
|
|
504
|
+
fs.writeFileSync(fullTestPath + '/test/a.test.js', `it('dummy test', () => {
|
|
505
|
+
expect(true).toBe(false);
|
|
506
|
+
})`)
|
|
507
|
+
|
|
508
|
+
await runJest();
|
|
509
|
+
|
|
510
|
+
abortExpect(jestArgs);
|
|
511
|
+
})
|
|
512
|
+
|
|
513
|
+
it('Shall abort add biz a template, no jest found, folder test found, no unit test', async () => {
|
|
514
|
+
returnedCode = 1;
|
|
515
|
+
jestMessage = 'missing packages jest';
|
|
516
|
+
|
|
517
|
+
mockValidTemplates(appName, mockScripts);
|
|
518
|
+
fs.mkdirSync(fullTestPath + '/test', { recursive: true })
|
|
519
|
+
|
|
520
|
+
await runJest();
|
|
521
|
+
|
|
522
|
+
abortExpect(jestArgs);
|
|
523
|
+
})
|
|
524
|
+
|
|
525
|
+
it('Shall continue add biz a template, no jest found, no folder test', async () => {
|
|
526
|
+
returnedCode = 1;
|
|
527
|
+
jestMessage = 'missing packages jest';
|
|
528
|
+
|
|
529
|
+
mockValidTemplates(appName, mockScripts);
|
|
530
|
+
await runJest();
|
|
531
|
+
|
|
532
|
+
continueExpect(jestArgsWithPassNoTest);
|
|
533
|
+
})
|
|
407
534
|
})
|
|
408
535
|
})
|
|
409
536
|
|