titanpl 6.0.0 → 7.0.0
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/package.json +2 -6
- package/packages/cli/index.js +25 -11
- package/packages/cli/package.json +4 -4
- package/packages/cli/src/commands/build-ext.js +157 -0
- package/packages/cli/src/commands/build.js +12 -0
- package/packages/cli/src/commands/create.js +160 -0
- package/packages/cli/src/commands/init.js +5 -11
- package/packages/cli/src/commands/run-ext.js +104 -0
- package/{titanpl-sdk → packages/core-source}/LICENSE +1 -1
- package/packages/core-source/README.md +128 -0
- package/packages/core-source/V8_SERIALIZATION.md +125 -0
- package/packages/core-source/configure.js +50 -0
- package/packages/core-source/globals.d.ts +2238 -0
- package/packages/core-source/index.d.ts +515 -0
- package/packages/core-source/index.js +639 -0
- package/packages/core-source/jsconfig.json +12 -0
- package/packages/core-source/mkctx.config.json +7 -0
- package/packages/core-source/native/Cargo.lock +1559 -0
- package/packages/core-source/native/Cargo.toml +30 -0
- package/packages/core-source/native/src/crypto_impl.rs +139 -0
- package/packages/core-source/native/src/lib.rs +702 -0
- package/packages/core-source/native/src/storage_impl.rs +73 -0
- package/packages/core-source/native/src/v8_impl.rs +93 -0
- package/packages/core-source/package-lock.json +1464 -0
- package/packages/core-source/package.json +53 -0
- package/packages/core-source/tests/buffer.test.js +78 -0
- package/packages/core-source/tests/cookies.test.js +117 -0
- package/packages/core-source/tests/crypto.test.js +142 -0
- package/packages/core-source/tests/fs.test.js +176 -0
- package/packages/core-source/tests/ls.test.js +149 -0
- package/packages/core-source/tests/net.test.js +84 -0
- package/packages/core-source/tests/os.test.js +81 -0
- package/packages/core-source/tests/path.test.js +102 -0
- package/packages/core-source/tests/response.test.js +146 -0
- package/packages/core-source/tests/session.test.js +110 -0
- package/packages/core-source/tests/setup.js +325 -0
- package/packages/core-source/tests/time.test.js +57 -0
- package/packages/core-source/tests/url.test.js +82 -0
- package/packages/core-source/titan-ext.d.ts +2 -0
- package/packages/core-source/titan.json +9 -0
- package/packages/core-source/vitest.config.js +8 -0
- package/packages/engine-darwin-arm64/README.md +0 -2
- package/packages/engine-darwin-arm64/package.json +1 -1
- package/packages/engine-linux-x64/README.md +0 -2
- package/packages/engine-linux-x64/package.json +1 -1
- package/packages/engine-win32-x64/README.md +0 -1
- package/packages/engine-win32-x64/bin/titan-server.exe +0 -0
- package/packages/engine-win32-x64/package.json +1 -1
- package/packages/native/README.md +0 -1
- package/packages/native/index.d.ts +25 -4
- package/packages/native/index.js +7 -0
- package/packages/native/package.json +2 -2
- package/packages/native/t.native.d.ts +167 -2
- package/packages/packet/index.js +103 -94
- package/packages/packet/package.json +1 -1
- package/packages/route/package.json +1 -1
- package/packages/sdk/index.js +2 -0
- package/packages/sdk/package.json +18 -0
- package/packages/sdk/test/index.js +120 -0
- package/templates/common/_tanfig.json +19 -13
- package/templates/extension/index.d.ts +26 -22
- package/templates/extension/index.js +15 -15
- package/templates/extension/native/Cargo.toml +5 -3
- package/templates/extension/native/src/lib.rs +2 -3
- package/templates/extension/package.json +10 -20
- package/templates/extension/titan.json +5 -16
- package/templates/extension/utils/registerExtension.js +44 -0
- package/templates/js/package.json +8 -8
- package/templates/rust-js/package.json +5 -5
- package/templates/rust-ts/package.json +5 -5
- package/templates/ts/package.json +8 -8
- package/packages/packet/node_modules/typescript/LICENSE.txt +0 -55
- package/packages/packet/node_modules/typescript/README.md +0 -50
- package/packages/packet/node_modules/typescript/SECURITY.md +0 -41
- package/packages/packet/node_modules/typescript/ThirdPartyNoticeText.txt +0 -193
- package/packages/packet/node_modules/typescript/bin/tsc +0 -2
- package/packages/packet/node_modules/typescript/bin/tsserver +0 -2
- package/packages/packet/node_modules/typescript/lib/_tsc.js +0 -133818
- package/packages/packet/node_modules/typescript/lib/_tsserver.js +0 -659
- package/packages/packet/node_modules/typescript/lib/_typingsInstaller.js +0 -222
- package/packages/packet/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/de/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/es/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/it/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/lib.d.ts +0 -22
- package/packages/packet/node_modules/typescript/lib/lib.decorators.d.ts +0 -384
- package/packages/packet/node_modules/typescript/lib/lib.decorators.legacy.d.ts +0 -22
- package/packages/packet/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +0 -41
- package/packages/packet/node_modules/typescript/lib/lib.dom.d.ts +0 -39429
- package/packages/packet/node_modules/typescript/lib/lib.dom.iterable.d.ts +0 -571
- package/packages/packet/node_modules/typescript/lib/lib.es2015.collection.d.ts +0 -147
- package/packages/packet/node_modules/typescript/lib/lib.es2015.core.d.ts +0 -597
- package/packages/packet/node_modules/typescript/lib/lib.es2015.d.ts +0 -28
- package/packages/packet/node_modules/typescript/lib/lib.es2015.generator.d.ts +0 -77
- package/packages/packet/node_modules/typescript/lib/lib.es2015.iterable.d.ts +0 -605
- package/packages/packet/node_modules/typescript/lib/lib.es2015.promise.d.ts +0 -81
- package/packages/packet/node_modules/typescript/lib/lib.es2015.proxy.d.ts +0 -128
- package/packages/packet/node_modules/typescript/lib/lib.es2015.reflect.d.ts +0 -144
- package/packages/packet/node_modules/typescript/lib/lib.es2015.symbol.d.ts +0 -46
- package/packages/packet/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +0 -326
- package/packages/packet/node_modules/typescript/lib/lib.es2016.array.include.d.ts +0 -116
- package/packages/packet/node_modules/typescript/lib/lib.es2016.d.ts +0 -21
- package/packages/packet/node_modules/typescript/lib/lib.es2016.full.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.es2016.intl.d.ts +0 -31
- package/packages/packet/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +0 -21
- package/packages/packet/node_modules/typescript/lib/lib.es2017.d.ts +0 -26
- package/packages/packet/node_modules/typescript/lib/lib.es2017.date.d.ts +0 -31
- package/packages/packet/node_modules/typescript/lib/lib.es2017.full.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.es2017.intl.d.ts +0 -44
- package/packages/packet/node_modules/typescript/lib/lib.es2017.object.d.ts +0 -49
- package/packages/packet/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +0 -135
- package/packages/packet/node_modules/typescript/lib/lib.es2017.string.d.ts +0 -45
- package/packages/packet/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +0 -53
- package/packages/packet/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +0 -77
- package/packages/packet/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +0 -53
- package/packages/packet/node_modules/typescript/lib/lib.es2018.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2018.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2018.intl.d.ts +0 -83
- package/packages/packet/node_modules/typescript/lib/lib.es2018.promise.d.ts +0 -30
- package/packages/packet/node_modules/typescript/lib/lib.es2018.regexp.d.ts +0 -37
- package/packages/packet/node_modules/typescript/lib/lib.es2019.array.d.ts +0 -79
- package/packages/packet/node_modules/typescript/lib/lib.es2019.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2019.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2019.intl.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.es2019.object.d.ts +0 -33
- package/packages/packet/node_modules/typescript/lib/lib.es2019.string.d.ts +0 -37
- package/packages/packet/node_modules/typescript/lib/lib.es2019.symbol.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2020.bigint.d.ts +0 -765
- package/packages/packet/node_modules/typescript/lib/lib.es2020.d.ts +0 -27
- package/packages/packet/node_modules/typescript/lib/lib.es2020.date.d.ts +0 -42
- package/packages/packet/node_modules/typescript/lib/lib.es2020.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2020.intl.d.ts +0 -474
- package/packages/packet/node_modules/typescript/lib/lib.es2020.number.d.ts +0 -28
- package/packages/packet/node_modules/typescript/lib/lib.es2020.promise.d.ts +0 -47
- package/packages/packet/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +0 -99
- package/packages/packet/node_modules/typescript/lib/lib.es2020.string.d.ts +0 -44
- package/packages/packet/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +0 -41
- package/packages/packet/node_modules/typescript/lib/lib.es2021.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.es2021.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2021.intl.d.ts +0 -166
- package/packages/packet/node_modules/typescript/lib/lib.es2021.promise.d.ts +0 -48
- package/packages/packet/node_modules/typescript/lib/lib.es2021.string.d.ts +0 -33
- package/packages/packet/node_modules/typescript/lib/lib.es2021.weakref.d.ts +0 -78
- package/packages/packet/node_modules/typescript/lib/lib.es2022.array.d.ts +0 -121
- package/packages/packet/node_modules/typescript/lib/lib.es2022.d.ts +0 -25
- package/packages/packet/node_modules/typescript/lib/lib.es2022.error.d.ts +0 -75
- package/packages/packet/node_modules/typescript/lib/lib.es2022.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2022.intl.d.ts +0 -145
- package/packages/packet/node_modules/typescript/lib/lib.es2022.object.d.ts +0 -26
- package/packages/packet/node_modules/typescript/lib/lib.es2022.regexp.d.ts +0 -39
- package/packages/packet/node_modules/typescript/lib/lib.es2022.string.d.ts +0 -25
- package/packages/packet/node_modules/typescript/lib/lib.es2023.array.d.ts +0 -924
- package/packages/packet/node_modules/typescript/lib/lib.es2023.collection.d.ts +0 -21
- package/packages/packet/node_modules/typescript/lib/lib.es2023.d.ts +0 -22
- package/packages/packet/node_modules/typescript/lib/lib.es2023.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2023.intl.d.ts +0 -56
- package/packages/packet/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +0 -65
- package/packages/packet/node_modules/typescript/lib/lib.es2024.collection.d.ts +0 -29
- package/packages/packet/node_modules/typescript/lib/lib.es2024.d.ts +0 -26
- package/packages/packet/node_modules/typescript/lib/lib.es2024.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2024.object.d.ts +0 -29
- package/packages/packet/node_modules/typescript/lib/lib.es2024.promise.d.ts +0 -35
- package/packages/packet/node_modules/typescript/lib/lib.es2024.regexp.d.ts +0 -25
- package/packages/packet/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +0 -68
- package/packages/packet/node_modules/typescript/lib/lib.es2024.string.d.ts +0 -29
- package/packages/packet/node_modules/typescript/lib/lib.es5.d.ts +0 -4601
- package/packages/packet/node_modules/typescript/lib/lib.es6.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.esnext.array.d.ts +0 -35
- package/packages/packet/node_modules/typescript/lib/lib.esnext.collection.d.ts +0 -96
- package/packages/packet/node_modules/typescript/lib/lib.esnext.d.ts +0 -29
- package/packages/packet/node_modules/typescript/lib/lib.esnext.decorators.d.ts +0 -28
- package/packages/packet/node_modules/typescript/lib/lib.esnext.disposable.d.ts +0 -193
- package/packages/packet/node_modules/typescript/lib/lib.esnext.error.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.esnext.float16.d.ts +0 -445
- package/packages/packet/node_modules/typescript/lib/lib.esnext.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.esnext.intl.d.ts +0 -21
- package/packages/packet/node_modules/typescript/lib/lib.esnext.iterator.d.ts +0 -148
- package/packages/packet/node_modules/typescript/lib/lib.esnext.promise.d.ts +0 -34
- package/packages/packet/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +0 -25
- package/packages/packet/node_modules/typescript/lib/lib.scripthost.d.ts +0 -322
- package/packages/packet/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +0 -41
- package/packages/packet/node_modules/typescript/lib/lib.webworker.d.ts +0 -13150
- package/packages/packet/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.webworker.iterable.d.ts +0 -340
- package/packages/packet/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/tsc.js +0 -8
- package/packages/packet/node_modules/typescript/lib/tsserver.js +0 -8
- package/packages/packet/node_modules/typescript/lib/tsserverlibrary.d.ts +0 -17
- package/packages/packet/node_modules/typescript/lib/tsserverlibrary.js +0 -21
- package/packages/packet/node_modules/typescript/lib/typesMap.json +0 -497
- package/packages/packet/node_modules/typescript/lib/typescript.d.ts +0 -11437
- package/packages/packet/node_modules/typescript/lib/typescript.js +0 -200276
- package/packages/packet/node_modules/typescript/lib/typingsInstaller.js +0 -8
- package/packages/packet/node_modules/typescript/lib/watchGuard.js +0 -53
- package/packages/packet/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/package.json +0 -120
- package/titanpl-sdk/README.md +0 -111
- package/titanpl-sdk/assets/titanpl-sdk.png +0 -0
- package/titanpl-sdk/bin/run.js +0 -274
- package/titanpl-sdk/index.js +0 -5
- package/titanpl-sdk/package-lock.json +0 -28
- package/titanpl-sdk/package.json +0 -40
- package/titanpl-sdk/templates/app/actions/hello.js +0 -5
- package/titanpl-sdk/templates/app/app.js +0 -7
- package/titanpl-sdk/templates/jsconfig.json +0 -19
- package/titanpl-sdk/templates/server/Cargo.toml +0 -52
- package/titanpl-sdk/templates/server/src/action_management.rs +0 -175
- package/titanpl-sdk/templates/server/src/errors.rs +0 -12
- package/titanpl-sdk/templates/server/src/extensions/builtin.rs +0 -1060
- package/titanpl-sdk/templates/server/src/extensions/external.rs +0 -338
- package/titanpl-sdk/templates/server/src/extensions/mod.rs +0 -580
- package/titanpl-sdk/templates/server/src/extensions/titan_core.js +0 -249
- package/titanpl-sdk/templates/server/src/fast_path.rs +0 -719
- package/titanpl-sdk/templates/server/src/main.rs +0 -607
- package/titanpl-sdk/templates/server/src/runtime.rs +0 -284
- package/titanpl-sdk/templates/server/src/utils.rs +0 -33
- package/titanpl-sdk/templates/titan/bundle.js +0 -259
- package/titanpl-sdk/templates/titan/dev.js +0 -390
- package/titanpl-sdk/templates/titan/error-box.js +0 -277
- package/titanpl-sdk/templates/titan/titan.js +0 -129
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tests/ls.test.js
|
|
3
|
+
*
|
|
4
|
+
* Tests for the ls (Local Storage) module
|
|
5
|
+
* Uses emulated natives with in-memory Map
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
8
|
+
import { ls } from '../index.js';
|
|
9
|
+
|
|
10
|
+
describe('ls (Local Storage)', () => {
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
ls.clear()
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('set() and get()', () => {
|
|
16
|
+
it('should store and retrieve string', () => {
|
|
17
|
+
ls.set('key1', 'value1');
|
|
18
|
+
|
|
19
|
+
expect(ls.get('key1')).toBe('value1');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should convert numbers to string', () => {
|
|
23
|
+
ls.set('number', 42);
|
|
24
|
+
|
|
25
|
+
expect(ls.get('number')).toBe('42');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should return empty for non-existing key', () => {
|
|
29
|
+
expect(ls.get('nonexistent')).toBe('');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should overwrite existing values', () => {
|
|
33
|
+
ls.set('key', 'original');
|
|
34
|
+
ls.set('key', 'updated');
|
|
35
|
+
|
|
36
|
+
expect(ls.get('key')).toBe('updated');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should handle JSON values', () => {
|
|
40
|
+
const data = { name: 'Test', items: [1, 2, 3] };
|
|
41
|
+
ls.set('json', JSON.stringify(data));
|
|
42
|
+
|
|
43
|
+
expect(JSON.parse(ls.get('json'))).toEqual(data);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('remove()', () => {
|
|
48
|
+
it('should remove existing key', () => {
|
|
49
|
+
ls.set('toRemove', 'value');
|
|
50
|
+
ls.remove('toRemove');
|
|
51
|
+
|
|
52
|
+
expect(ls.get('toRemove')).toBe('');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should not fail when removing non-existing key', () => {
|
|
56
|
+
expect(() => ls.remove('nonexistent')).not.toThrow();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('clear()', () => {
|
|
61
|
+
it('should remove all values', () => {
|
|
62
|
+
ls.set('key1', 'value1');
|
|
63
|
+
ls.set('key2', 'value2');
|
|
64
|
+
ls.set('key3', 'value3');
|
|
65
|
+
|
|
66
|
+
ls.clear();
|
|
67
|
+
|
|
68
|
+
expect(ls.get('key1')).toBe('');
|
|
69
|
+
expect(ls.get('key2')).toBe('');
|
|
70
|
+
expect(ls.get('key3')).toBe('');
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('keys()', () => {
|
|
75
|
+
it('should return list of keys', () => {
|
|
76
|
+
ls.set('a', '1');
|
|
77
|
+
ls.set('b', '2');
|
|
78
|
+
ls.set('c', '3');
|
|
79
|
+
|
|
80
|
+
const keys = ls.keys();
|
|
81
|
+
|
|
82
|
+
expect(keys).toContain('a');
|
|
83
|
+
expect(keys).toContain('b');
|
|
84
|
+
expect(keys).toContain('c');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should return empty array when no keys', () => {
|
|
88
|
+
const keys = ls.keys();
|
|
89
|
+
|
|
90
|
+
expect(keys).toEqual([]);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('setObject() and getObject()', () => {
|
|
95
|
+
it('should store and retrieve objects via JSON when serialize is not available', () => {
|
|
96
|
+
const data = {
|
|
97
|
+
name: 'Test',
|
|
98
|
+
count: 42,
|
|
99
|
+
items: ['a', 'b', 'c'],
|
|
100
|
+
nested: { x: 1, y: 2 }
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
ls.setObject('complex', data);
|
|
104
|
+
const result = ls.getObject('complex');
|
|
105
|
+
|
|
106
|
+
// If result is null, V8 serialization is not available
|
|
107
|
+
// This is expected in environments outside Titan runtime
|
|
108
|
+
if (result === null) {
|
|
109
|
+
// Verify at least set/get works with manual JSON
|
|
110
|
+
ls.set('complex-json', JSON.stringify(data));
|
|
111
|
+
const jsonResult = JSON.parse(ls.get('complex-json'));
|
|
112
|
+
expect(jsonResult).toEqual(data);
|
|
113
|
+
} else {
|
|
114
|
+
expect(result).toEqual(data);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should handle arrays via JSON when serialize is not available', () => {
|
|
119
|
+
const arr = [1, 2, 3, 'four', { five: 5 }];
|
|
120
|
+
|
|
121
|
+
ls.setObject('array', arr);
|
|
122
|
+
const result = ls.getObject('array');
|
|
123
|
+
|
|
124
|
+
if (result === null) {
|
|
125
|
+
ls.set('array-json', JSON.stringify(arr));
|
|
126
|
+
const jsonResult = JSON.parse(ls.get('array-json'));
|
|
127
|
+
expect(jsonResult).toEqual(arr);
|
|
128
|
+
} else {
|
|
129
|
+
expect(result).toEqual(arr);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('should return null for non-existing key', () => {
|
|
134
|
+
expect(ls.getObject('nonexistent')).toBeNull();
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('serialize() and deserialize()', () => {
|
|
139
|
+
it('should serialize and deserialize correctly', () => {
|
|
140
|
+
const data = { test: true, value: 123 };
|
|
141
|
+
|
|
142
|
+
const serialized = ls.serialize(data);
|
|
143
|
+
expect(serialized).toBeInstanceOf(Uint8Array);
|
|
144
|
+
|
|
145
|
+
const deserialized = ls.deserialize(serialized);
|
|
146
|
+
expect(deserialized).toEqual(data);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tests/net.test.js
|
|
3
|
+
*
|
|
4
|
+
* Tests for the net module
|
|
5
|
+
* Uses emulated natives
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect } from 'vitest';
|
|
8
|
+
import { net } from '../index.js';
|
|
9
|
+
|
|
10
|
+
describe('net', () => {
|
|
11
|
+
describe('ip()', () => {
|
|
12
|
+
it('should return valid IP address', () => {
|
|
13
|
+
const ip = net.ip();
|
|
14
|
+
|
|
15
|
+
expect(typeof ip).toBe('string');
|
|
16
|
+
// Should be IPv4 format or localhost
|
|
17
|
+
expect(ip).toMatch(/^(\d{1,3}\.){3}\d{1,3}$/);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('resolveDNS()', () => {
|
|
22
|
+
it('should return array of IPs', () => {
|
|
23
|
+
const ips = net.resolveDNS('localhost');
|
|
24
|
+
|
|
25
|
+
expect(Array.isArray(ips)).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should return empty array for invalid hostname', () => {
|
|
29
|
+
const ips = net.resolveDNS('');
|
|
30
|
+
|
|
31
|
+
expect(Array.isArray(ips)).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Tests for the proc module
|
|
38
|
+
*/
|
|
39
|
+
import { proc } from '../index.js';
|
|
40
|
+
|
|
41
|
+
describe('proc', () => {
|
|
42
|
+
describe('info()', () => {
|
|
43
|
+
it('should return process info', () => {
|
|
44
|
+
const info = proc.info();
|
|
45
|
+
|
|
46
|
+
expect(info).toHaveProperty('pid');
|
|
47
|
+
expect(typeof info.pid).toBe('number');
|
|
48
|
+
expect(info.pid).toBeGreaterThan(0);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('pid()', () => {
|
|
53
|
+
it('should return process PID', () => {
|
|
54
|
+
const pid = proc.pid();
|
|
55
|
+
|
|
56
|
+
expect(typeof pid).toBe('number');
|
|
57
|
+
expect(pid).toBeGreaterThan(0);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('list()', () => {
|
|
62
|
+
it('should return array (possibly empty in tests)', () => {
|
|
63
|
+
const processes = proc.list();
|
|
64
|
+
|
|
65
|
+
expect(Array.isArray(processes)).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('run()', () => {
|
|
70
|
+
it('should return object (disabled in tests)', () => {
|
|
71
|
+
const result = proc.run('echo', ['hello']);
|
|
72
|
+
|
|
73
|
+
expect(typeof result).toBe('object');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('kill()', () => {
|
|
78
|
+
it('should return false (disabled in tests)', () => {
|
|
79
|
+
const result = proc.kill(99999);
|
|
80
|
+
|
|
81
|
+
expect(result).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tests/os.test.js
|
|
3
|
+
*
|
|
4
|
+
* Tests for the os module
|
|
5
|
+
* Uses emulated natives wrapping Node.js os
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect } from 'vitest';
|
|
8
|
+
import { os } from '../index.js';
|
|
9
|
+
|
|
10
|
+
describe('os', () => {
|
|
11
|
+
describe('info()', () => {
|
|
12
|
+
it('should return object with system info', () => {
|
|
13
|
+
const info = os.info();
|
|
14
|
+
|
|
15
|
+
expect(info).toHaveProperty('platform');
|
|
16
|
+
expect(info).toHaveProperty('cpus');
|
|
17
|
+
expect(info).toHaveProperty('totalMemory');
|
|
18
|
+
expect(info).toHaveProperty('freeMemory');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should have valid values', () => {
|
|
22
|
+
const info = os.info();
|
|
23
|
+
|
|
24
|
+
expect(typeof info.platform).toBe('string');
|
|
25
|
+
expect(info.cpus).toBeGreaterThan(0);
|
|
26
|
+
expect(info.totalMemory).toBeGreaterThan(0);
|
|
27
|
+
expect(info.freeMemory).toBeGreaterThanOrEqual(0);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('platform()', () => {
|
|
32
|
+
it('should return valid platform', () => {
|
|
33
|
+
const platform = os.platform();
|
|
34
|
+
|
|
35
|
+
expect(['linux', 'darwin', 'win32', 'freebsd', 'openbsd']).toContain(platform);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('cpus()', () => {
|
|
40
|
+
it('should return number of CPUs', () => {
|
|
41
|
+
const cpus = os.cpus();
|
|
42
|
+
|
|
43
|
+
expect(typeof cpus).toBe('number');
|
|
44
|
+
expect(cpus).toBeGreaterThan(0);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('totalMemory()', () => {
|
|
49
|
+
it('should return total memory in bytes', () => {
|
|
50
|
+
const total = os.totalMemory();
|
|
51
|
+
|
|
52
|
+
expect(typeof total).toBe('number');
|
|
53
|
+
expect(total).toBeGreaterThan(0);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('freeMemory()', () => {
|
|
58
|
+
it('should return free memory in bytes', () => {
|
|
59
|
+
const free = os.freeMemory();
|
|
60
|
+
|
|
61
|
+
expect(typeof free).toBe('number');
|
|
62
|
+
expect(free).toBeGreaterThanOrEqual(0);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('free memory should be less than or equal to total', () => {
|
|
66
|
+
const total = os.totalMemory();
|
|
67
|
+
const free = os.freeMemory();
|
|
68
|
+
|
|
69
|
+
expect(free).toBeLessThanOrEqual(total);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('tmpdir()', () => {
|
|
74
|
+
it('should return temp directory', () => {
|
|
75
|
+
const tmp = os.tmpdir();
|
|
76
|
+
|
|
77
|
+
expect(typeof tmp).toBe('string');
|
|
78
|
+
expect(tmp.length).toBeGreaterThan(0);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tests/path.test.js
|
|
3
|
+
*
|
|
4
|
+
* Tests for the path module
|
|
5
|
+
* Pure JS API - no mocks required
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect } from 'vitest';
|
|
8
|
+
import { path } from '../index.js';
|
|
9
|
+
|
|
10
|
+
describe('path', () => {
|
|
11
|
+
describe('join()', () => {
|
|
12
|
+
it('should join path segments', () => {
|
|
13
|
+
expect(path.join('a', 'b', 'c')).toBe('a/b/c');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should normalize duplicate separators', () => {
|
|
17
|
+
expect(path.join('a/', '/b/', '/c')).toBe('a/b/c');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should convert backslashes to forward slashes', () => {
|
|
21
|
+
expect(path.join('a\\b', 'c\\d')).toBe('a/b/c/d');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should filter falsy values', () => {
|
|
25
|
+
expect(path.join('a', null, 'b', undefined, 'c')).toBe('a/b/c');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should handle single segment', () => {
|
|
29
|
+
expect(path.join('single')).toBe('single');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should handle absolute paths', () => {
|
|
33
|
+
expect(path.join('/root', 'sub', 'file.txt')).toBe('/root/sub/file.txt');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('dirname()', () => {
|
|
38
|
+
it('should return parent directory', () => {
|
|
39
|
+
expect(path.dirname('/home/user/file.txt')).toBe('/home/user');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should return "." for file without directory', () => {
|
|
43
|
+
expect(path.dirname('file.txt')).toBe('.');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should handle paths with multiple levels', () => {
|
|
47
|
+
expect(path.dirname('a/b/c/d.js')).toBe('a/b/c');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('basename()', () => {
|
|
52
|
+
it('should return filename', () => {
|
|
53
|
+
expect(path.basename('/home/user/file.txt')).toBe('file.txt');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should return name for simple path', () => {
|
|
57
|
+
expect(path.basename('file.txt')).toBe('file.txt');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should handle directories', () => {
|
|
61
|
+
expect(path.basename('/home/user/')).toBe('');
|
|
62
|
+
expect(path.basename('/home/user')).toBe('user');
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('extname()', () => {
|
|
67
|
+
it('should return extension with dot', () => {
|
|
68
|
+
expect(path.extname('file.txt')).toBe('.txt');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should return last extension', () => {
|
|
72
|
+
expect(path.extname('archive.tar.gz')).toBe('.gz');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should return empty if no extension', () => {
|
|
76
|
+
expect(path.extname('noextension')).toBe('');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should handle hidden files', () => {
|
|
80
|
+
expect(path.extname('.gitignore')).toBe('');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should handle full paths', () => {
|
|
84
|
+
expect(path.extname('/path/to/file.json')).toBe('.json');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('resolve()', () => {
|
|
89
|
+
it('should return absolute paths unchanged', () => {
|
|
90
|
+
expect(path.resolve('/absolute/path')).toBe('/absolute/path');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should join multiple segments', () => {
|
|
94
|
+
const result = path.resolve('a', 'b', 'c');
|
|
95
|
+
expect(result).toContain('a/b/c');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should handle Windows paths', () => {
|
|
99
|
+
expect(path.resolve('C:/Users/test')).toBe('C:/Users/test');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tests/response.test.js
|
|
3
|
+
*
|
|
4
|
+
* Tests for the response module
|
|
5
|
+
* Pure JS API - no mocks required
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect } from 'vitest';
|
|
8
|
+
import { response } from '../index.js';
|
|
9
|
+
|
|
10
|
+
describe('response', () => {
|
|
11
|
+
describe('response()', () => {
|
|
12
|
+
it('should create basic response', () => {
|
|
13
|
+
const res = response({ status: 200, body: 'OK' });
|
|
14
|
+
|
|
15
|
+
expect(res._isResponse).toBe(true);
|
|
16
|
+
expect(res.status).toBe(200);
|
|
17
|
+
expect(res.body).toBe('OK');
|
|
18
|
+
expect(res.headers).toEqual({});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should use default values', () => {
|
|
22
|
+
const res = response({});
|
|
23
|
+
|
|
24
|
+
expect(res.status).toBe(200);
|
|
25
|
+
expect(res.body).toBe('');
|
|
26
|
+
expect(res.headers).toEqual({});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should include custom headers', () => {
|
|
30
|
+
const res = response({
|
|
31
|
+
status: 201,
|
|
32
|
+
headers: { 'X-Custom': 'value' },
|
|
33
|
+
body: 'Created'
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(res.headers['X-Custom']).toBe('value');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('response.json()', () => {
|
|
41
|
+
it('should create JSON response', () => {
|
|
42
|
+
const res = response.json({ message: 'Hello', count: 42 });
|
|
43
|
+
|
|
44
|
+
expect(res._isResponse).toBe(true);
|
|
45
|
+
expect(res.status).toBe(200);
|
|
46
|
+
expect(res.headers['Content-Type']).toBe('application/json');
|
|
47
|
+
expect(res.body).toBe('{"message":"Hello","count":42}');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should allow custom status', () => {
|
|
51
|
+
const res = response.json({ error: 'Not found' }, { status: 404 });
|
|
52
|
+
|
|
53
|
+
expect(res.status).toBe(404);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should serialize arrays', () => {
|
|
57
|
+
const res = response.json([1, 2, 3]);
|
|
58
|
+
|
|
59
|
+
expect(res.body).toBe('[1,2,3]');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should handle complex objects', () => {
|
|
63
|
+
const data = {
|
|
64
|
+
users: [{ id: 1, name: 'John' }],
|
|
65
|
+
meta: { total: 1 }
|
|
66
|
+
};
|
|
67
|
+
const res = response.json(data);
|
|
68
|
+
|
|
69
|
+
expect(JSON.parse(res.body)).toEqual(data);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('response.text()', () => {
|
|
74
|
+
it('should create plain text response', () => {
|
|
75
|
+
const res = response.text('Hello World');
|
|
76
|
+
|
|
77
|
+
expect(res._isResponse).toBe(true);
|
|
78
|
+
expect(res.body).toBe('Hello World');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should convert numbers to string', () => {
|
|
82
|
+
const res = response.text(42);
|
|
83
|
+
|
|
84
|
+
expect(res.body).toBe('42');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('response.html()', () => {
|
|
89
|
+
it('should create HTML response', () => {
|
|
90
|
+
const html = '<html><body>Hello</body></html>';
|
|
91
|
+
const res = response.html(html);
|
|
92
|
+
|
|
93
|
+
expect(res._isResponse).toBe(true);
|
|
94
|
+
expect(res.headers['Content-Type']).toBe('text/html');
|
|
95
|
+
expect(res.body).toBe(html);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should allow additional headers', () => {
|
|
99
|
+
const res = response.html('<p>Test</p>', {
|
|
100
|
+
headers: { 'X-Frame-Options': 'DENY' }
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(res.headers['Content-Type']).toBe('text/html');
|
|
104
|
+
expect(res.headers['X-Frame-Options']).toBe('DENY');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('response.redirect()', () => {
|
|
109
|
+
it('should create 302 redirect by default', () => {
|
|
110
|
+
const res = response.redirect('/new-location');
|
|
111
|
+
|
|
112
|
+
expect(res._isResponse).toBe(true);
|
|
113
|
+
expect(res.status).toBe(302);
|
|
114
|
+
expect(res.headers['Location']).toBe('/new-location');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should allow 301 permanent redirect', () => {
|
|
118
|
+
const res = response.redirect('/permanent', 301);
|
|
119
|
+
|
|
120
|
+
expect(res.status).toBe(301);
|
|
121
|
+
expect(res.headers['Location']).toBe('/permanent');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should handle absolute URLs', () => {
|
|
125
|
+
const res = response.redirect('https://example.com/path');
|
|
126
|
+
|
|
127
|
+
expect(res.headers['Location']).toBe('https://example.com/path');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('response.empty()', () => {
|
|
132
|
+
it.skip('should create empty 204 response by default', () => {
|
|
133
|
+
const res = response.empty();
|
|
134
|
+
|
|
135
|
+
expect(res._isResponse).toBe(true);
|
|
136
|
+
expect(res.status).toBe(204);
|
|
137
|
+
expect(res.body).toBe('');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it.skip('should allow custom status', () => {
|
|
141
|
+
const res = response.empty(202);
|
|
142
|
+
|
|
143
|
+
expect(res.status).toBe(202);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tests/session.test.js
|
|
3
|
+
*
|
|
4
|
+
* Tests for the session module
|
|
5
|
+
* Uses emulated natives with in-memory Map
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
8
|
+
import { session } from '../index.js';
|
|
9
|
+
|
|
10
|
+
describe('session', () => {
|
|
11
|
+
const SESSION_ID = 'test-session-123';
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
// setup.js clears sessions before each test
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('set() and get()', () => {
|
|
18
|
+
it('should store and retrieve session value', () => {
|
|
19
|
+
session.set(SESSION_ID, 'username', 'john');
|
|
20
|
+
|
|
21
|
+
expect(session.get(SESSION_ID, 'username')).toBe('john');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should keep sessions separate by ID', () => {
|
|
25
|
+
session.set('session-1', 'user', 'alice');
|
|
26
|
+
session.set('session-2', 'user', 'bob');
|
|
27
|
+
|
|
28
|
+
expect(session.get('session-1', 'user')).toBe('alice');
|
|
29
|
+
expect(session.get('session-2', 'user')).toBe('bob');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should return empty for non-existing key', () => {
|
|
33
|
+
expect(session.get(SESSION_ID, 'nonexistent')).toBe('');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should store multiple keys per session', () => {
|
|
37
|
+
session.set(SESSION_ID, 'key1', 'value1');
|
|
38
|
+
session.set(SESSION_ID, 'key2', 'value2');
|
|
39
|
+
session.set(SESSION_ID, 'key3', 'value3');
|
|
40
|
+
|
|
41
|
+
expect(session.get(SESSION_ID, 'key1')).toBe('value1');
|
|
42
|
+
expect(session.get(SESSION_ID, 'key2')).toBe('value2');
|
|
43
|
+
expect(session.get(SESSION_ID, 'key3')).toBe('value3');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('delete()', () => {
|
|
48
|
+
it('should delete specific key from session', () => {
|
|
49
|
+
session.set(SESSION_ID, 'toDelete', 'value');
|
|
50
|
+
session.set(SESSION_ID, 'toKeep', 'value');
|
|
51
|
+
|
|
52
|
+
session.delete(SESSION_ID, 'toDelete');
|
|
53
|
+
|
|
54
|
+
expect(session.get(SESSION_ID, 'toDelete')).toBe('');
|
|
55
|
+
expect(session.get(SESSION_ID, 'toKeep')).toBe('value');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should not fail when deleting non-existing key', () => {
|
|
59
|
+
expect(() => session.delete(SESSION_ID, 'nonexistent')).not.toThrow();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('clear()', () => {
|
|
64
|
+
it('should delete entire session', () => {
|
|
65
|
+
session.set(SESSION_ID, 'key1', 'value1');
|
|
66
|
+
session.set(SESSION_ID, 'key2', 'value2');
|
|
67
|
+
|
|
68
|
+
session.clear(SESSION_ID);
|
|
69
|
+
|
|
70
|
+
expect(session.get(SESSION_ID, 'key1')).toBe('');
|
|
71
|
+
expect(session.get(SESSION_ID, 'key2')).toBe('');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should not affect other sessions', () => {
|
|
75
|
+
session.set('session-1', 'data', 'one');
|
|
76
|
+
session.set('session-2', 'data', 'two');
|
|
77
|
+
|
|
78
|
+
session.clear('session-1');
|
|
79
|
+
|
|
80
|
+
expect(session.get('session-1', 'data')).toBe('');
|
|
81
|
+
expect(session.get('session-2', 'data')).toBe('two');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('real-world use cases', () => {
|
|
86
|
+
it('should handle auth token', () => {
|
|
87
|
+
const authSession = 'auth-abc123';
|
|
88
|
+
const token = 'eyJhbGciOiJIUzI1NiJ9.test';
|
|
89
|
+
|
|
90
|
+
session.set(authSession, 'token', token);
|
|
91
|
+
session.set(authSession, 'expires', '2025-12-31');
|
|
92
|
+
|
|
93
|
+
expect(session.get(authSession, 'token')).toBe(token);
|
|
94
|
+
expect(session.get(authSession, 'expires')).toBe('2025-12-31');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should handle shopping cart', () => {
|
|
98
|
+
const cartSession = 'cart-xyz789';
|
|
99
|
+
const cart = JSON.stringify([
|
|
100
|
+
{ id: 1, qty: 2 },
|
|
101
|
+
{ id: 2, qty: 1 }
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
session.set(cartSession, 'items', cart);
|
|
105
|
+
|
|
106
|
+
const retrieved = JSON.parse(session.get(cartSession, 'items'));
|
|
107
|
+
expect(retrieved).toHaveLength(2);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|