ttmg-pack 0.4.0 → 0.4.3

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/__TEST__/tests/fixtures/check-project/non-unity/src/game.js +1 -0
  3. package/__TEST__/tests/fixtures/check-project/non-unity/src/game.json +3 -0
  4. package/__TEST__/tests/fixtures/check-project/subpackages-camel-case/src/game.js +1 -0
  5. package/__TEST__/tests/fixtures/check-project/subpackages-camel-case/src/game.json +4 -0
  6. package/__TEST__/tests/fixtures/check-project/unity-large-config-disabled/src/game.js +1 -0
  7. package/__TEST__/tests/fixtures/check-project/unity-large-config-disabled/src/game.json +4 -0
  8. package/__TEST__/tests/fixtures/check-project/unity-large-config-disabled/src/webgl-wasm-split.json +3 -0
  9. package/__TEST__/tests/fixtures/check-project/unity-large-config-enabled/src/game.js +1 -0
  10. package/__TEST__/tests/fixtures/check-project/unity-large-config-enabled/src/game.json +4 -0
  11. package/__TEST__/tests/fixtures/check-project/unity-large-config-enabled/src/webgl-wasm-split.json +3 -0
  12. package/__TEST__/tests/fixtures/check-project/unity-large-no-config/src/game.js +1 -0
  13. package/__TEST__/tests/fixtures/check-project/unity-large-no-config/src/game.json +4 -0
  14. package/__TEST__/tests/fixtures/check-project/unity-small/src/game.js +1 -0
  15. package/__TEST__/tests/fixtures/check-project/unity-small/src/game.json +4 -0
  16. package/__TEST__/tests/fixtures/game-cocos/game.json +3 -0
  17. package/__TEST__/tests/fixtures/game-invalid-json/game.json +1 -0
  18. package/__TEST__/tests/fixtures/game-no-config/game.js +1 -0
  19. package/__TEST__/tests/fixtures/game-no-engine/game.json +3 -0
  20. package/__TEST__/tests/fixtures/game-unity/game.json +15 -0
  21. package/__TEST__/tests/libs/checkProject.test.js +68 -0
  22. package/__TEST__/tests/runner-simple.js +120 -0
  23. package/__TEST__/tests/runner.js +102 -0
  24. package/__TEST__/tests/utils/Deferred.test.js +69 -0
  25. package/__TEST__/tests/utils/asyncPool.test.js +48 -0
  26. package/__TEST__/tests/utils/getCheckConfig.test.js +24 -0
  27. package/__TEST__/tests/utils/getGameEngine.test.js +32 -0
  28. package/__TEST__/tests/utils/getIndependentPackagesConfig.test.js +27 -0
  29. package/__TEST__/tests/utils/getMd5.test.js +31 -0
  30. package/__TEST__/tests/utils/getSubpackagesConfig.test.js +26 -0
  31. package/__TEST__/tests/utils/unity.test.js +30 -0
  32. package/dist/index.js +362 -100
  33. package/dist/index.js.map +1 -1
  34. package/dist/libs/buildPkgs/index.d.ts +2 -2
  35. package/dist/libs/checkPkgs/checkAPI.d.ts +2 -1
  36. package/dist/libs/checkPkgs/checkIndependentPackages.d.ts +4 -2
  37. package/dist/libs/checkPkgs/checkMainpackage.d.ts +4 -3
  38. package/dist/libs/checkPkgs/checkProject.d.ts +4 -3
  39. package/dist/libs/checkPkgs/checkSubpackages.d.ts +2 -1
  40. package/dist/libs/checkPkgs/index.d.ts +2 -2
  41. package/dist/libs/debugPkgs/index.d.ts +2 -2
  42. package/dist/typings/index.d.ts +7 -0
  43. package/dist/utils/i18n.d.ts +158 -0
  44. package/dist/utils/index.d.ts +2 -0
  45. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -379,4 +379,14 @@ for unity plugin
379
379
  ## 0.4.0
380
380
 
381
381
  1. **优化 wasmFuncCount 校验逻辑**:当 game.json 中没有 wasmFuncCount 字段时直接返回 null,不进行校验,保证老用户不被干扰
382
- 2. **完善边界条件处理**:wasmFuncCount 为 0 时仍会进行正常校验
382
+ 2. **完善边界条件处理**:wasmFuncCount 为 0 时仍会进行正常校验
383
+
384
+ ## 0.4.1-0.4.2
385
+
386
+ 1. **所有 CheckResult 新增 `required` 字段**:用于区分校验项是否为必须通过项
387
+ - API 校验(`checkAPI`):`required: false`,表示为建议性校验
388
+ - 其他校验(config / size / performance):`required: true`,表示为强制性校验
389
+ 2. **类型定义更新**:`CheckSizeResult`、`CheckConfigResult`、`CheckPerfResult` 接口均新增 `required: boolean` 字段
390
+
391
+ ## 0.4.3
392
+ 1. 支持日志多语言
@@ -0,0 +1 @@
1
+ console.log('test');
@@ -0,0 +1,3 @@
1
+ {
2
+ "gameEngine": "cocos"
3
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "gameEngine": "cocos",
3
+ "subPackages": []
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "gameEngine": "unity",
3
+ "wasmFuncCount": 80000
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "gameEngine": "unity",
3
+ "wasmFuncCount": 80000
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "gameEngine": "unity",
3
+ "wasmFuncCount": 80000
4
+ }
@@ -0,0 +1 @@
1
+ console.log('test');
@@ -0,0 +1,4 @@
1
+ {
2
+ "gameEngine": "unity",
3
+ "wasmFuncCount": 79999
4
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "gameEngine": "cocos"
3
+ }
@@ -0,0 +1 @@
1
+ { invalid json }
@@ -0,0 +1 @@
1
+ console.log('test');
@@ -0,0 +1,3 @@
1
+ {
2
+ "name": "test game"
3
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "gameEngine": "unity",
3
+ "wasmFuncCount": 79999,
4
+ "subpackages": [
5
+ {
6
+ "name": "sub1",
7
+ "root": "subpackages/sub1"
8
+ },
9
+ {
10
+ "name": "sub2",
11
+ "root": "subpackages/sub2",
12
+ "independent": true
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,68 @@
1
+ const assert = require('assert');
2
+ const path = require('path');
3
+ const { checkGameJson, checkProjectSize } = require('../../../dist/libs/checkPkgs/checkProject');
4
+ const { createPackTranslator } = require('../../../dist/utils');
5
+
6
+ const t = createPackTranslator('en-US');
7
+ const fixturesPath = path.join(__dirname, '../fixtures/check-project');
8
+
9
+ describe('checkProject', function() {
10
+ describe('checkGameJson', function() {
11
+ it('should check game.json exists and passes', function() {
12
+ const result = checkGameJson({
13
+ entry: path.join(fixturesPath, 'non-unity/src'),
14
+ dev: { enable: true }
15
+ }, t);
16
+ assert.strictEqual(result.passed, true);
17
+ });
18
+
19
+ it('should return error when game.json is missing (dev mode)', function() {
20
+ const result = checkGameJson({
21
+ entry: path.join(fixturesPath, 'game-json-missing/src'),
22
+ dev: { enable: true }
23
+ }, t);
24
+ assert.strictEqual(result.passed, false);
25
+ assert.strictEqual(result.level, 'error');
26
+ });
27
+
28
+ it('should throw error when game.json is missing (non-dev mode)', function() {
29
+ assert.throws(() => {
30
+ checkGameJson({
31
+ entry: path.join(fixturesPath, 'game-json-missing/src'),
32
+ dev: { enable: false }
33
+ }, t);
34
+ }, /Cannot find game\.json/);
35
+ });
36
+
37
+ it('should check for subPackages (camelCase) and return error (dev mode)', function() {
38
+ const result = checkGameJson({
39
+ entry: path.join(fixturesPath, 'subpackages-camel-case/src'),
40
+ dev: { enable: true }
41
+ }, t);
42
+ assert.strictEqual(result.passed, false);
43
+ assert.strictEqual(result.level, 'error');
44
+ });
45
+
46
+ it('should check for subPackages (camelCase) and throw error (non-dev mode)', function() {
47
+ assert.throws(() => {
48
+ checkGameJson({
49
+ entry: path.join(fixturesPath, 'subpackages-camel-case/src'),
50
+ dev: { enable: false }
51
+ }, t);
52
+ }, /subPackages/);
53
+ });
54
+ });
55
+
56
+ describe('checkProjectSize', function() {
57
+ it('should check project size and pass within limit', function() {
58
+ const result = checkProjectSize({
59
+ entry: path.join(fixturesPath, 'non-unity/src'),
60
+ dev: { enable: true },
61
+ build: {
62
+ pkgSizeLimit: 100 * 1024 * 1024
63
+ }
64
+ }, t);
65
+ assert.strictEqual(result.passed, true);
66
+ });
67
+ });
68
+ });
@@ -0,0 +1,120 @@
1
+ const assert = require('assert');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ const { checkPkgs } = require('../../dist/index');
5
+
6
+ const tests = [];
7
+ const describeStack = [];
8
+ let currentDescribe = null;
9
+
10
+ function describe(name, fn) {
11
+ const suite = { name, tests: [], children: [] };
12
+ if (currentDescribe) {
13
+ currentDescribe.children.push(suite);
14
+ } else {
15
+ tests.push(suite);
16
+ }
17
+ describeStack.push(currentDescribe);
18
+ currentDescribe = suite;
19
+ try {
20
+ fn();
21
+ } finally {
22
+ currentDescribe = describeStack.pop();
23
+ }
24
+ }
25
+
26
+ function it(name, fn) {
27
+ if (!currentDescribe) {
28
+ throw new Error('it() must be called inside describe()');
29
+ }
30
+ currentDescribe.tests.push({ name, fn });
31
+ }
32
+
33
+ let passed = 0;
34
+ let failed = 0;
35
+
36
+ async function runSuite(suite, indent = 0) {
37
+ console.log(`${' '.repeat(indent)}${suite.name}`);
38
+ for (const test of suite.tests) {
39
+ try {
40
+ if (test.fn.constructor.name === 'AsyncFunction') {
41
+ await test.fn();
42
+ } else {
43
+ test.fn();
44
+ }
45
+ console.log(`${' '.repeat(indent + 1)}✓ ${test.name}`);
46
+ passed++;
47
+ } catch (error) {
48
+ console.log(`${' '.repeat(indent + 1)}✗ ${test.name}`);
49
+ console.log(`${' '.repeat(indent + 2)}${error.message}`);
50
+ if (error.stack) {
51
+ console.log(`${' '.repeat(indent + 2)}${error.stack.split('\n').slice(1).join('\n' + ' '.repeat(indent + 2))}`);
52
+ }
53
+ failed++;
54
+ }
55
+ }
56
+ for (const child of suite.children) {
57
+ await runSuite(child, indent + 1);
58
+ }
59
+ }
60
+
61
+ describe('checkPkgs Integration Tests', function() {
62
+ it('should run checkPkgs on unity-small test case', async function() {
63
+ const result = await checkPkgs({
64
+ entry: path.join(__dirname, '../wasm-test/unity-small/src'),
65
+ output: path.join(__dirname, '../output'),
66
+ dev: {
67
+ enable: true,
68
+ enableLog: false
69
+ },
70
+ build: {
71
+ enableOdr: false,
72
+ pkgSizeLimit: 30 * 1024 * 1024,
73
+ mainPkgSizeLimit: 1 * 1024 * 1024,
74
+ independentSubPkgSizeLimit: 4 * 1024 * 1024
75
+ }
76
+ });
77
+ assert(Array.isArray(result));
78
+ });
79
+
80
+ it('should run checkPkgs on unity-large-config-enabled test case', async function() {
81
+ const result = await checkPkgs({
82
+ entry: path.join(__dirname, '../wasm-test/unity-large-config-enabled/src'),
83
+ output: path.join(__dirname, '../output'),
84
+ dev: {
85
+ enable: true,
86
+ enableLog: false
87
+ },
88
+ build: {
89
+ enableOdr: false,
90
+ pkgSizeLimit: 30 * 1024 * 1024,
91
+ mainPkgSizeLimit: 1 * 1024 * 1024,
92
+ independentSubPkgSizeLimit: 4 * 1024 * 1024
93
+ }
94
+ });
95
+ assert(Array.isArray(result));
96
+ });
97
+ });
98
+
99
+ async function runTests() {
100
+ console.log('========================================');
101
+ console.log('Running unit tests');
102
+ console.log('========================================\n');
103
+
104
+ for (const suite of tests) {
105
+ await runSuite(suite);
106
+ }
107
+
108
+ console.log('\n========================================');
109
+ console.log('Test Summary:');
110
+ console.log(` Passed: ${passed}`);
111
+ console.log(` Failed: ${failed}`);
112
+ console.log('========================================');
113
+
114
+ process.exit(failed > 0 ? 1 : 0);
115
+ }
116
+
117
+ global.describe = describe;
118
+ global.it = it;
119
+
120
+ runTests();
@@ -0,0 +1,102 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const tests = [];
5
+ const describeStack = [];
6
+ let currentDescribe = null;
7
+
8
+ function describe(name, fn) {
9
+ const suite = { name, tests: [], children: [] };
10
+ if (currentDescribe) {
11
+ currentDescribe.children.push(suite);
12
+ } else {
13
+ tests.push(suite);
14
+ }
15
+ describeStack.push(currentDescribe);
16
+ currentDescribe = suite;
17
+ try {
18
+ fn();
19
+ } finally {
20
+ currentDescribe = describeStack.pop();
21
+ }
22
+ }
23
+
24
+ function it(name, fn) {
25
+ if (!currentDescribe) {
26
+ throw new Error('it() must be called inside describe()');
27
+ }
28
+ currentDescribe.tests.push({ name, fn });
29
+ }
30
+
31
+ let passed = 0;
32
+ let failed = 0;
33
+
34
+ async function runSuite(suite, indent = 0) {
35
+ console.log(`${' '.repeat(indent)}${suite.name}`);
36
+ for (const test of suite.tests) {
37
+ try {
38
+ if (test.fn.constructor.name === 'AsyncFunction') {
39
+ await test.fn();
40
+ } else {
41
+ test.fn();
42
+ }
43
+ console.log(`${' '.repeat(indent + 1)}✓ ${test.name}`);
44
+ passed++;
45
+ } catch (error) {
46
+ console.log(`${' '.repeat(indent + 1)}✗ ${test.name}`);
47
+ console.log(`${' '.repeat(indent + 2)}${error.message}`);
48
+ if (error.stack) {
49
+ console.log(`${' '.repeat(indent + 2)}${error.stack.split('\n').slice(1).join('\n' + ' '.repeat(indent + 2))}`);
50
+ }
51
+ failed++;
52
+ }
53
+ }
54
+ for (const child of suite.children) {
55
+ await runSuite(child, indent + 1);
56
+ }
57
+ }
58
+
59
+ async function runTests() {
60
+ console.log('========================================');
61
+ console.log('Running unit tests');
62
+ console.log('========================================\n');
63
+
64
+ const testFiles = [
65
+ 'utils/getMd5.test.js',
66
+ 'utils/Deferred.test.js',
67
+ 'utils/getGameEngine.test.js',
68
+ 'utils/getSubpackagesConfig.test.js',
69
+ 'utils/getIndependentPackagesConfig.test.js',
70
+ 'utils/asyncPool.test.js',
71
+ 'utils/unity.test.js',
72
+ 'utils/getCheckConfig.test.js',
73
+ 'libs/checkProject.test.js'
74
+ ];
75
+
76
+ for (const file of testFiles) {
77
+ const testPath = path.join(__dirname, file);
78
+ if (fs.existsSync(testPath)) {
79
+ console.log(`Loading tests from: ${file}`);
80
+ require(testPath);
81
+ }
82
+ }
83
+
84
+ console.log('\n');
85
+
86
+ for (const suite of tests) {
87
+ await runSuite(suite);
88
+ }
89
+
90
+ console.log('\n========================================');
91
+ console.log('Test Summary:');
92
+ console.log(` Passed: ${passed}`);
93
+ console.log(` Failed: ${failed}`);
94
+ console.log('========================================');
95
+
96
+ process.exit(failed > 0 ? 1 : 0);
97
+ }
98
+
99
+ global.describe = describe;
100
+ global.it = it;
101
+
102
+ runTests();
@@ -0,0 +1,69 @@
1
+ const assert = require('assert');
2
+ const { Deferred } = require('../../../dist/utils/Deferred');
3
+
4
+ describe('Deferred', function() {
5
+ it('should create a deferred object with promise', function() {
6
+ const deferred = new Deferred();
7
+ assert(deferred.promise instanceof Promise);
8
+ assert.strictEqual(typeof deferred.resolve, 'function');
9
+ assert.strictEqual(typeof deferred.reject, 'function');
10
+ });
11
+
12
+ it('should resolve successfully', async function() {
13
+ const deferred = new Deferred();
14
+ const testValue = 'success';
15
+
16
+ setTimeout(() => deferred.resolve(testValue), 10);
17
+
18
+ const result = await deferred.promise;
19
+ assert.strictEqual(result, testValue);
20
+ });
21
+
22
+ it('should reject with error', async function() {
23
+ const deferred = new Deferred();
24
+ const testError = new Error('test error');
25
+
26
+ setTimeout(() => deferred.reject(testError), 10);
27
+
28
+ try {
29
+ await deferred.promise;
30
+ assert.fail('Promise should have rejected');
31
+ } catch (error) {
32
+ assert.strictEqual(error, testError);
33
+ }
34
+ });
35
+
36
+ it('should support then method', async function() {
37
+ const deferred = new Deferred();
38
+ const testValue = 'test';
39
+
40
+ setTimeout(() => deferred.resolve(testValue), 10);
41
+
42
+ const result = await deferred.then(val => val.toUpperCase());
43
+ assert.strictEqual(result, 'TEST');
44
+ });
45
+
46
+ it('should support catch method', async function() {
47
+ const deferred = new Deferred();
48
+ const testError = new Error('catch me');
49
+
50
+ setTimeout(() => deferred.reject(testError), 10);
51
+
52
+ const caught = await deferred.catch(err => err.message);
53
+ assert.strictEqual(caught, 'catch me');
54
+ });
55
+
56
+ it('should handle resolve called multiple times', async function() {
57
+ const deferred = new Deferred();
58
+ let resolveCount = 0;
59
+
60
+ deferred.promise.then(() => resolveCount++);
61
+
62
+ deferred.resolve('first');
63
+ deferred.resolve('second');
64
+
65
+ await new Promise(resolve => setTimeout(resolve, 10));
66
+
67
+ assert.strictEqual(resolveCount, 1);
68
+ });
69
+ });
@@ -0,0 +1,48 @@
1
+ const assert = require('assert');
2
+ const { asyncPool } = require('../../../dist/utils/asyncPool');
3
+
4
+ describe('asyncPool', function() {
5
+ it('should execute all tasks with pool limit', async function() {
6
+ const tasks = [1, 2, 3, 4, 5];
7
+ const results = [];
8
+
9
+ const iteratorFn = async (item) => {
10
+ await new Promise(resolve => setTimeout(resolve, 10));
11
+ results.push(item);
12
+ return item * 2;
13
+ };
14
+
15
+ const finalResults = await asyncPool(2, tasks, iteratorFn);
16
+
17
+ assert.deepStrictEqual(finalResults, [2, 4, 6, 8, 10]);
18
+ assert.strictEqual(results.length, 5);
19
+ });
20
+
21
+ it('should handle empty array', async function() {
22
+ const results = await asyncPool(5, [], async () => {});
23
+ assert.deepStrictEqual(results, []);
24
+ });
25
+
26
+ it('should handle pool limit larger than array length', async function() {
27
+ const tasks = [1, 2, 3];
28
+ const iteratorFn = async (item) => item;
29
+
30
+ const results = await asyncPool(10, tasks, iteratorFn);
31
+ assert.deepStrictEqual(results, [1, 2, 3]);
32
+ });
33
+
34
+ it('should propagate errors', async function() {
35
+ const tasks = [1, 2, 3];
36
+ const iteratorFn = async (item) => {
37
+ if (item === 2) throw new Error('Test error');
38
+ return item;
39
+ };
40
+
41
+ try {
42
+ await asyncPool(2, tasks, iteratorFn);
43
+ assert.fail('Should have thrown an error');
44
+ } catch (error) {
45
+ assert.strictEqual(error.message, 'Test error');
46
+ }
47
+ });
48
+ });
@@ -0,0 +1,24 @@
1
+ const assert = require('assert');
2
+ const path = require('path');
3
+ const { getCheckConfig } = require('../../../dist/utils/getCheckConfig');
4
+ const { GAME_PKG_SIZE_LIMIT } = require('../../../dist/constants');
5
+
6
+ const fixturesPath = path.join(__dirname, '../fixtures');
7
+
8
+ describe('getCheckConfig', function() {
9
+ it('should return unity config for unity engine', function() {
10
+ const config = getCheckConfig({
11
+ entry: path.join(fixturesPath, 'game-unity')
12
+ });
13
+ assert.strictEqual(config.pkgSizeLimit, GAME_PKG_SIZE_LIMIT.unity.project);
14
+ });
15
+
16
+ it('should return default config for non-unity engine', function() {
17
+ const config = getCheckConfig({
18
+ entry: path.join(fixturesPath, 'game-cocos')
19
+ });
20
+ assert.strictEqual(config.pkgSizeLimit, 30 * 1024 * 1024);
21
+ assert.strictEqual(config.mainPkgSizeLimit, 4 * 1024 * 1024);
22
+ assert.strictEqual(config.independentSubPkgSizeLimit, 4 * 1024 * 1024);
23
+ });
24
+ });
@@ -0,0 +1,32 @@
1
+ const assert = require('assert');
2
+ const path = require('path');
3
+ const { getGameEngine } = require('../../../dist/utils/getGameEngine');
4
+
5
+ const fixturesPath = path.join(__dirname, '../fixtures');
6
+
7
+ describe('getGameEngine', function() {
8
+ it('should return unity when gameEngine is unity', function() {
9
+ const result = getGameEngine(path.join(fixturesPath, 'game-unity'));
10
+ assert.strictEqual(result, 'unity');
11
+ });
12
+
13
+ it('should return cocos when gameEngine is cocos', function() {
14
+ const result = getGameEngine(path.join(fixturesPath, 'game-cocos'));
15
+ assert.strictEqual(result, 'cocos');
16
+ });
17
+
18
+ it('should return unknown when game.json does not exist', function() {
19
+ const result = getGameEngine(path.join(fixturesPath, 'game-no-config'));
20
+ assert.strictEqual(result, 'unknown');
21
+ });
22
+
23
+ it('should return unknown when game.json has invalid JSON', function() {
24
+ const result = getGameEngine(path.join(fixturesPath, 'game-invalid-json'));
25
+ assert.strictEqual(result, 'unknown');
26
+ });
27
+
28
+ it('should return unknown when game.json does not have gameEngine field', function() {
29
+ const result = getGameEngine(path.join(fixturesPath, 'game-no-engine'));
30
+ assert.strictEqual(result, 'unknown');
31
+ });
32
+ });
@@ -0,0 +1,27 @@
1
+ const assert = require('assert');
2
+ const path = require('path');
3
+ const { getIndependentPackagesConfig } = require('../../../dist/utils/getIndependentPackagesConfig');
4
+
5
+ const fixturesPath = path.join(__dirname, '../fixtures');
6
+
7
+ describe('getIndependentPackagesConfig', function() {
8
+ it('should return independent subpackages', function() {
9
+ const result = getIndependentPackagesConfig(path.join(fixturesPath, 'game-unity'));
10
+ assert(Array.isArray(result));
11
+ assert.strictEqual(result.length, 1);
12
+ assert.strictEqual(result[0].name, 'sub2');
13
+ assert.strictEqual(result[0].independent, true);
14
+ });
15
+
16
+ it('should return empty array when game.json does not exist', function() {
17
+ const result = getIndependentPackagesConfig(path.join(fixturesPath, 'game-no-config'));
18
+ assert(Array.isArray(result));
19
+ assert.strictEqual(result.length, 0);
20
+ });
21
+
22
+ it('should return empty array when game.json has invalid JSON', function() {
23
+ const result = getIndependentPackagesConfig(path.join(fixturesPath, 'game-invalid-json'));
24
+ assert(Array.isArray(result));
25
+ assert.strictEqual(result.length, 0);
26
+ });
27
+ });
@@ -0,0 +1,31 @@
1
+ const assert = require('assert');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ const { getMd5 } = require('../../../dist/utils/getMd5');
5
+
6
+ describe('getMd5', function() {
7
+ it('should return correct MD5 hash for string input', function() {
8
+ const testStr = 'hello world';
9
+ const expected = '5eb63bbbe01eeed093cb22bb8f5acdc3';
10
+ const result = getMd5(testStr);
11
+ assert.strictEqual(result, expected);
12
+ });
13
+
14
+ it('should return consistent hash for same input', function() {
15
+ const testStr = 'test string';
16
+ const result1 = getMd5(testStr);
17
+ const result2 = getMd5(testStr);
18
+ assert.strictEqual(result1, result2);
19
+ });
20
+
21
+ it('should return different hash for different input', function() {
22
+ const result1 = getMd5('string1');
23
+ const result2 = getMd5('string2');
24
+ assert.notStrictEqual(result1, result2);
25
+ });
26
+
27
+ it('should handle empty string', function() {
28
+ const result = getMd5('');
29
+ assert.strictEqual(result, 'd41d8cd98f00b204e9800998ecf8427e');
30
+ });
31
+ });
@@ -0,0 +1,26 @@
1
+ const assert = require('assert');
2
+ const path = require('path');
3
+ const { getSubpackagesConfig } = require('../../../dist/utils/getSubpackagesConfig');
4
+
5
+ const fixturesPath = path.join(__dirname, '../fixtures');
6
+
7
+ describe('getSubpackagesConfig', function() {
8
+ it('should return non-independent subpackages', function() {
9
+ const result = getSubpackagesConfig(path.join(fixturesPath, 'game-unity'));
10
+ assert(Array.isArray(result));
11
+ assert.strictEqual(result.length, 1);
12
+ assert.strictEqual(result[0].name, 'sub1');
13
+ });
14
+
15
+ it('should return empty array when game.json does not exist', function() {
16
+ const result = getSubpackagesConfig(path.join(fixturesPath, 'game-no-config'));
17
+ assert(Array.isArray(result));
18
+ assert.strictEqual(result.length, 0);
19
+ });
20
+
21
+ it('should return empty array when game.json has invalid JSON', function() {
22
+ const result = getSubpackagesConfig(path.join(fixturesPath, 'game-invalid-json'));
23
+ assert(Array.isArray(result));
24
+ assert.strictEqual(result.length, 0);
25
+ });
26
+ });