@karpeleslab/klbfw 0.2.0 → 0.2.2
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/fw-wrapper.js +21 -3
- package/index.d.ts +81 -0
- package/index.js +1 -1
- package/internal.js +19 -6
- package/package.json +8 -1
- package/CLAUDE.md +0 -50
- package/coverage/clover.xml +0 -835
- package/coverage/coverage-final.json +0 -9
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/cookies.js.html +0 -334
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/fw-wrapper.js.html +0 -163
- package/coverage/lcov-report/index.html +0 -131
- package/coverage/lcov-report/index.js.html +0 -196
- package/coverage/lcov-report/internal.js.html +0 -604
- package/coverage/lcov-report/klbfw/cookies.js.html +0 -490
- package/coverage/lcov-report/klbfw/fw-wrapper.js.html +0 -745
- package/coverage/lcov-report/klbfw/index.html +0 -206
- package/coverage/lcov-report/klbfw/index.js.html +0 -235
- package/coverage/lcov-report/klbfw/internal.js.html +0 -811
- package/coverage/lcov-report/klbfw/rest.js.html +0 -565
- package/coverage/lcov-report/klbfw/test/index.html +0 -116
- package/coverage/lcov-report/klbfw/test/setup.js.html +0 -1105
- package/coverage/lcov-report/klbfw/upload.js.html +0 -3487
- package/coverage/lcov-report/klbfw/util.js.html +0 -388
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/rest.js.html +0 -472
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/upload.js.html +0 -1789
- package/coverage/lcov-report/util.js.html +0 -313
- package/coverage/lcov.info +0 -1617
- package/test/README.md +0 -62
- package/test/api.test.js +0 -102
- package/test/cookies.test.js +0 -65
- package/test/integration.test.js +0 -481
- package/test/rest.test.js +0 -93
- package/test/setup.js +0 -341
- package/test/upload.test.js +0 -689
- package/test/util.test.js +0 -46
package/test/README.md
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# klbfw Testing
|
|
2
|
-
|
|
3
|
-
This directory contains tests for the KarpelesLab Frontend Framework.
|
|
4
|
-
|
|
5
|
-
## Test Structure
|
|
6
|
-
|
|
7
|
-
- `setup.js` - Common test setup and utilities
|
|
8
|
-
- `cookies.test.js` - Tests for cookie handling
|
|
9
|
-
- `rest.test.js` - Tests for REST API client functionality
|
|
10
|
-
- `util.test.js` - Tests for utility functions
|
|
11
|
-
- `api.test.js` - Tests for API endpoint mocks
|
|
12
|
-
- `upload.test.js` - Tests for file upload functionality
|
|
13
|
-
- `integration.test.js` - Real API integration tests
|
|
14
|
-
|
|
15
|
-
## Running Tests
|
|
16
|
-
|
|
17
|
-
### Unit Tests
|
|
18
|
-
|
|
19
|
-
Regular unit tests use mocks to simulate API responses:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npm test
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### Integration Tests
|
|
26
|
-
|
|
27
|
-
Integration tests call actual API endpoints. To run them, you need to:
|
|
28
|
-
|
|
29
|
-
1. Enable integration tests:
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
# Enable tests
|
|
33
|
-
export RUN_INTEGRATION_TESTS=true
|
|
34
|
-
|
|
35
|
-
# Optionally specify a different API server URL (default: http://localhost:8080)
|
|
36
|
-
export API_URL=https://your-test-server.com
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
2. Run the integration tests:
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
npm test -- test/integration.test.js
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
For file upload tests (which require a browser environment):
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
export RUN_UPLOAD_TESTS=true
|
|
49
|
-
npm test -- test/integration.test.js
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Debug Endpoints
|
|
53
|
-
|
|
54
|
-
The integration tests use special debug endpoints:
|
|
55
|
-
|
|
56
|
-
- `Misc/Debug:request` - Returns information about the request
|
|
57
|
-
- `Misc/Debug:params` - Returns the parameters that were sent
|
|
58
|
-
- `Misc/Debug:fixedString` - Returns a fixed string "fixed string"
|
|
59
|
-
- `Misc/Debug:error` - Throws an error
|
|
60
|
-
- `Misc/Debug:testUpload` - Used for testing file uploads
|
|
61
|
-
|
|
62
|
-
These endpoints should be available on your test server for integration tests to work properly.
|
package/test/api.test.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const klbfw = require('../index');
|
|
4
|
-
const upload = require('../upload');
|
|
5
|
-
const { setupSSRMode, setupClientMode, resetMocks } = require('./setup');
|
|
6
|
-
|
|
7
|
-
describe('API Debug Endpoints', () => {
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
resetMocks();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
describe('Client Mode', () => {
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
setupClientMode();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('Misc/Debug:request returns request info', async () => {
|
|
18
|
-
const response = await klbfw.rest('Misc/Debug:request', 'GET');
|
|
19
|
-
expect(response).toHaveProperty('result', 'success');
|
|
20
|
-
expect(response.data).toHaveProperty('ip', '127.0.0.1');
|
|
21
|
-
expect(response.data).toHaveProperty('headers');
|
|
22
|
-
expect(response.data).toHaveProperty('method', 'GET');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('Misc/Debug:params returns passed parameters', async () => {
|
|
26
|
-
const testParams = { foo: 'bar', num: 123, arr: [1, 2, 3] };
|
|
27
|
-
const response = await klbfw.rest('Misc/Debug:params', 'POST', testParams);
|
|
28
|
-
expect(response).toHaveProperty('result', 'success');
|
|
29
|
-
expect(response.data).toEqual(testParams);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('Misc/Debug:fixedString returns a fixed string', async () => {
|
|
33
|
-
const response = await klbfw.rest('Misc/Debug:fixedString', 'GET');
|
|
34
|
-
expect(response).toHaveProperty('result', 'success');
|
|
35
|
-
expect(response.data).toBe('fixed string');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('Misc/Debug:error throws an error', async () => {
|
|
39
|
-
expect.assertions(1);
|
|
40
|
-
try {
|
|
41
|
-
await klbfw.rest('Misc/Debug:error', 'GET');
|
|
42
|
-
// Should not reach here
|
|
43
|
-
expect(false).toBe(true);
|
|
44
|
-
} catch (error) {
|
|
45
|
-
// Just verify an error was thrown
|
|
46
|
-
expect(error).toBeDefined();
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('rest_get works with debug endpoints', async () => {
|
|
51
|
-
const response = await klbfw.rest_get('Misc/Debug:fixedString');
|
|
52
|
-
expect(response).toHaveProperty('result', 'success');
|
|
53
|
-
expect(response.data).toBe('fixed string');
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('SSR Mode', () => {
|
|
58
|
-
beforeEach(() => {
|
|
59
|
-
setupSSRMode();
|
|
60
|
-
|
|
61
|
-
// Override the mock implementation specifically for this test
|
|
62
|
-
global.__platformAsyncRest.mockImplementation((name, verb, params, context) => {
|
|
63
|
-
if (name === 'Misc/Debug:request') {
|
|
64
|
-
return Promise.resolve({
|
|
65
|
-
result: 'success',
|
|
66
|
-
data: {
|
|
67
|
-
headers: { 'user-agent': 'Jest Test' },
|
|
68
|
-
ip: '127.0.0.1',
|
|
69
|
-
method: verb || 'GET',
|
|
70
|
-
path: '/api/Misc/Debug:request'
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
} else if (name === 'Misc/Debug:params') {
|
|
74
|
-
return Promise.resolve({
|
|
75
|
-
result: 'success',
|
|
76
|
-
data: params || { empty: true }
|
|
77
|
-
});
|
|
78
|
-
} else {
|
|
79
|
-
return Promise.resolve({
|
|
80
|
-
result: 'success',
|
|
81
|
-
data: { mock: 'data' }
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('Misc/Debug:request returns request info in SSR mode', async () => {
|
|
88
|
-
const response = await klbfw.rest('Misc/Debug:request', 'GET');
|
|
89
|
-
expect(response).toHaveProperty('result', 'success');
|
|
90
|
-
expect(response.data).toHaveProperty('ip', '127.0.0.1');
|
|
91
|
-
expect(__platformAsyncRest).toHaveBeenCalledWith('Misc/Debug:request', 'GET', undefined, expect.any(Object));
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test('Misc/Debug:params returns passed parameters in SSR mode', async () => {
|
|
95
|
-
const testParams = { foo: 'bar', num: 123, arr: [1, 2, 3] };
|
|
96
|
-
const response = await klbfw.rest('Misc/Debug:params', 'POST', testParams);
|
|
97
|
-
expect(response).toHaveProperty('result', 'success');
|
|
98
|
-
expect(response.data).toEqual(testParams);
|
|
99
|
-
expect(__platformAsyncRest).toHaveBeenCalledWith('Misc/Debug:params', 'POST', testParams, expect.any(Object));
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
package/test/cookies.test.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const cookies = require('../cookies');
|
|
4
|
-
const { setupSSRMode, setupClientMode, resetMocks } = require('./setup');
|
|
5
|
-
|
|
6
|
-
describe('Cookies Module', () => {
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
resetMocks();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
describe('SSR Mode', () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
setupSSRMode();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('getCookie gets value from FW.cookies', () => {
|
|
17
|
-
FW.cookies.testCookie = 'test-value';
|
|
18
|
-
expect(cookies.getCookie('testCookie')).toBe('test-value');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('hasCookie checks FW.cookies', () => {
|
|
22
|
-
// Mock the implementation for this test
|
|
23
|
-
const originalHasCookie = cookies.hasCookie;
|
|
24
|
-
cookies.hasCookie = jest.fn().mockImplementation((cname) => {
|
|
25
|
-
return cname === 'testCookie';
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
expect(cookies.hasCookie('testCookie')).toBe(true);
|
|
29
|
-
expect(cookies.hasCookie('nonExistentCookie')).toBe(false);
|
|
30
|
-
|
|
31
|
-
// Restore original function
|
|
32
|
-
cookies.hasCookie = originalHasCookie;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('setCookie calls __platformSetCookie', () => {
|
|
36
|
-
cookies.setCookie('testCookie', 'test-value');
|
|
37
|
-
expect(__platformSetCookie).toHaveBeenCalled();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('Client Mode', () => {
|
|
42
|
-
beforeEach(() => {
|
|
43
|
-
setupClientMode();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('getCookie gets value from FW.cookies if available', () => {
|
|
47
|
-
FW.cookies.testCookie = 'test-value';
|
|
48
|
-
expect(cookies.getCookie('testCookie')).toBe('test-value');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('hasCookie checks FW.cookies if available', () => {
|
|
52
|
-
// Mock the implementation for this test
|
|
53
|
-
const originalHasCookie = cookies.hasCookie;
|
|
54
|
-
cookies.hasCookie = jest.fn().mockImplementation((cname) => {
|
|
55
|
-
return cname === 'testCookie';
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
expect(cookies.hasCookie('testCookie')).toBe(true);
|
|
59
|
-
expect(cookies.hasCookie('nonExistentCookie')).toBe(false);
|
|
60
|
-
|
|
61
|
-
// Restore original function
|
|
62
|
-
cookies.hasCookie = originalHasCookie;
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
});
|