kempo-server 1.7.6 → 1.7.7
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 +1 -1
- package/tests/router-wildcard-double-asterisk.node-test.js +19 -20
- package/tests/router-wildcard.node-test.js +13 -13
- package/tests/test-server-root/docs/.config.json +2 -3
- package/tests/test-server-root/docs/src/components/Button.js +1 -1
- package/tests/test-server-root/docs/src/nested/file.js +1 -1
- package/tests/test-server-root/docs/src/utils/helpers/format.js +1 -1
- package/tests/test-server-root/src/components/Import.js +1 -0
- package/tests/test-server-root/src/deep/nested/file.js +1 -0
- package/tests/test-server-root/src/file.js +1 -1
- package/tests/test-server-root/src/nested/file.js +1 -1
- package/tests/test-server-root/src/utils/helpers.js +1 -0
- package/tests/test-server-root/README.md +0 -118
package/package.json
CHANGED
|
@@ -13,8 +13,8 @@ export default {
|
|
|
13
13
|
const fileC = await write(dir, 'src/deep/nested/folder/file.js', 'export const deep = true');
|
|
14
14
|
|
|
15
15
|
// Create files in docs directory that should be ignored when custom routes match
|
|
16
|
-
await write(dir, 'docs/src/components/Button.js', 'WRONG FILE');
|
|
17
|
-
await write(dir, 'docs/src/utils/helpers/format.js', 'WRONG FILE');
|
|
16
|
+
await write(dir, 'docs/src/components/Button.js', '// WRONG FILE');
|
|
17
|
+
await write(dir, 'docs/src/utils/helpers/format.js', '// WRONG FILE');
|
|
18
18
|
|
|
19
19
|
const prev = process.cwd();
|
|
20
20
|
process.chdir(dir);
|
|
@@ -70,12 +70,12 @@ export default {
|
|
|
70
70
|
'single asterisk only matches single path segments': async ({pass, fail, log}) => {
|
|
71
71
|
try {
|
|
72
72
|
await withTempDir(async (dir) => {
|
|
73
|
-
// Create
|
|
74
|
-
await write(dir, 'src/file.js', 'single level');
|
|
75
|
-
await write(dir, 'src/nested/file.js', 'nested level');
|
|
73
|
+
// Create files at different nesting levels
|
|
74
|
+
await write(dir, 'src/file.js', '// single level');
|
|
75
|
+
await write(dir, 'src/nested/file.js', '// nested level');
|
|
76
76
|
|
|
77
|
-
// Create fallback file
|
|
78
|
-
await write(dir, 'docs/src/nested/file.js', 'fallback file');
|
|
77
|
+
// Create docs directory with fallback file
|
|
78
|
+
await write(dir, 'docs/src/nested/file.js', '// fallback file');
|
|
79
79
|
|
|
80
80
|
const prev = process.cwd();
|
|
81
81
|
process.chdir(dir);
|
|
@@ -103,13 +103,13 @@ export default {
|
|
|
103
103
|
const r1 = await httpGet(`http://localhost:${port}/src/file.js`);
|
|
104
104
|
log('single level status: ' + r1.res.statusCode);
|
|
105
105
|
if(r1.res.statusCode !== 200) throw new Error('single level 200');
|
|
106
|
-
if(r1.body.toString() !== 'single level') throw new Error('single level content');
|
|
106
|
+
if(r1.body.toString() !== '// single level') throw new Error('single level content');
|
|
107
107
|
|
|
108
108
|
// Nested level should NOT work with single asterisk, should fall back to docs
|
|
109
109
|
const r2 = await httpGet(`http://localhost:${port}/src/nested/file.js`);
|
|
110
110
|
log('nested level status: ' + r2.res.statusCode);
|
|
111
111
|
if(r2.res.statusCode !== 200) throw new Error('nested level 200');
|
|
112
|
-
if(r2.body.toString() !== 'fallback file') throw new Error('nested level should use fallback');
|
|
112
|
+
if(r2.body.toString() !== '// fallback file') throw new Error('nested level should use fallback');
|
|
113
113
|
|
|
114
114
|
} finally {
|
|
115
115
|
server.close();
|
|
@@ -125,12 +125,12 @@ export default {
|
|
|
125
125
|
'wildcard routes take precedence over static files': async ({pass, fail, log}) => {
|
|
126
126
|
try {
|
|
127
127
|
await withTempDir(async (dir) => {
|
|
128
|
-
// Create
|
|
129
|
-
await write(dir, 'custom/data.json', '{"source": "custom"}');
|
|
130
|
-
|
|
131
|
-
// Create static files in docs that should be overridden
|
|
128
|
+
// Create static file in docs
|
|
132
129
|
await write(dir, 'docs/api/data.json', '{"source": "static"}');
|
|
133
130
|
|
|
131
|
+
// Create custom file outside docs
|
|
132
|
+
await write(dir, 'custom/data.json', '{"source": "custom"}');
|
|
133
|
+
|
|
134
134
|
const prev = process.cwd();
|
|
135
135
|
process.chdir(dir);
|
|
136
136
|
|
|
@@ -174,13 +174,11 @@ export default {
|
|
|
174
174
|
'wildcard routes serve nested files from server root': async ({pass, fail, log}) => {
|
|
175
175
|
try {
|
|
176
176
|
await withTempDir(async (dir) => {
|
|
177
|
-
// Create
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
// Create index.html in server root
|
|
183
|
-
await write(dir, 'index.html', '<h1>Home</h1>');
|
|
177
|
+
// Create additional test files needed for this specific test
|
|
178
|
+
await write(dir, 'src/components/Import.js', 'export default ImportComponent');
|
|
179
|
+
await write(dir, 'src/utils/helpers.js', 'export const helpers = {}');
|
|
180
|
+
await write(dir, 'src/deep/nested/file.js', 'export const deep = true');
|
|
181
|
+
await write(dir, 'index.html', '<html><body>Test Index</body></html>');
|
|
184
182
|
|
|
185
183
|
const prev = process.cwd();
|
|
186
184
|
process.chdir(dir);
|
|
@@ -220,6 +218,7 @@ export default {
|
|
|
220
218
|
const r3 = await httpGet(`http://localhost:${port}/src/deep/nested/file.js`);
|
|
221
219
|
log('deep nested file status: ' + r3.res.statusCode);
|
|
222
220
|
if(r3.res.statusCode !== 200) throw new Error(`Expected 200 for deep nested file, got ${r3.res.statusCode}`);
|
|
221
|
+
if(r3.body.toString() !== 'export const deep = true') throw new Error('Deep nested file content mismatch');
|
|
223
222
|
|
|
224
223
|
// Test that index.html still works (non-wildcard route)
|
|
225
224
|
const r4 = await httpGet(`http://localhost:${port}/index.html`);
|
|
@@ -13,8 +13,8 @@ export default {
|
|
|
13
13
|
const fileC = await write(dir, 'src/deep/nested/folder/file.js', 'export const deep = true');
|
|
14
14
|
|
|
15
15
|
// Create files in docs directory that should be ignored when custom routes match
|
|
16
|
-
await write(dir, 'docs/src/components/Button.js', 'WRONG FILE');
|
|
17
|
-
await write(dir, 'docs/src/utils/helpers/format.js', 'WRONG FILE');
|
|
16
|
+
await write(dir, 'docs/src/components/Button.js', '// WRONG FILE');
|
|
17
|
+
await write(dir, 'docs/src/utils/helpers/format.js', '// WRONG FILE');
|
|
18
18
|
|
|
19
19
|
const prev = process.cwd();
|
|
20
20
|
process.chdir(dir);
|
|
@@ -70,12 +70,12 @@ export default {
|
|
|
70
70
|
'single asterisk only matches single path segments': async ({pass, fail, log}) => {
|
|
71
71
|
try {
|
|
72
72
|
await withTempDir(async (dir) => {
|
|
73
|
-
// Create
|
|
74
|
-
await write(dir, 'src/file.js', 'single level');
|
|
75
|
-
await write(dir, 'src/nested/file.js', 'nested level');
|
|
73
|
+
// Create files at different nesting levels
|
|
74
|
+
await write(dir, 'src/file.js', '// single level');
|
|
75
|
+
await write(dir, 'src/nested/file.js', '// nested level');
|
|
76
76
|
|
|
77
|
-
// Create fallback file
|
|
78
|
-
await write(dir, 'docs/src/nested/file.js', 'fallback file');
|
|
77
|
+
// Create docs directory with fallback file
|
|
78
|
+
await write(dir, 'docs/src/nested/file.js', '// fallback file');
|
|
79
79
|
|
|
80
80
|
const prev = process.cwd();
|
|
81
81
|
process.chdir(dir);
|
|
@@ -103,13 +103,13 @@ export default {
|
|
|
103
103
|
const r1 = await httpGet(`http://localhost:${port}/src/file.js`);
|
|
104
104
|
log('single level status: ' + r1.res.statusCode);
|
|
105
105
|
if(r1.res.statusCode !== 200) throw new Error('single level 200');
|
|
106
|
-
if(r1.body.toString() !== 'single level') throw new Error('single level content');
|
|
106
|
+
if(r1.body.toString() !== '// single level') throw new Error('single level content');
|
|
107
107
|
|
|
108
108
|
// Nested level should NOT work with single asterisk, should fall back to docs
|
|
109
109
|
const r2 = await httpGet(`http://localhost:${port}/src/nested/file.js`);
|
|
110
110
|
log('nested level status: ' + r2.res.statusCode);
|
|
111
111
|
if(r2.res.statusCode !== 200) throw new Error('nested level 200');
|
|
112
|
-
if(r2.body.toString() !== 'fallback file') throw new Error('nested level should use fallback');
|
|
112
|
+
if(r2.body.toString() !== '// fallback file') throw new Error('nested level should use fallback');
|
|
113
113
|
|
|
114
114
|
} finally {
|
|
115
115
|
server.close();
|
|
@@ -125,12 +125,12 @@ export default {
|
|
|
125
125
|
'wildcard routes take precedence over static files': async ({pass, fail, log}) => {
|
|
126
126
|
try {
|
|
127
127
|
await withTempDir(async (dir) => {
|
|
128
|
-
// Create
|
|
129
|
-
await write(dir, 'custom/data.json', '{"source": "custom"}');
|
|
130
|
-
|
|
131
|
-
// Create static files in docs that should be overridden
|
|
128
|
+
// Create static file in docs
|
|
132
129
|
await write(dir, 'docs/api/data.json', '{"source": "static"}');
|
|
133
130
|
|
|
131
|
+
// Create custom file outside docs
|
|
132
|
+
await write(dir, 'custom/data.json', '{"source": "custom"}');
|
|
133
|
+
|
|
134
134
|
const prev = process.cwd();
|
|
135
135
|
process.chdir(dir);
|
|
136
136
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
WRONG FILE
|
|
1
|
+
// WRONG FILE
|
|
@@ -1 +1 @@
|
|
|
1
|
-
fallback file
|
|
1
|
+
// fallback file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
WRONG FILE
|
|
1
|
+
// WRONG FILE
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const Import = () => 'imported';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const nested = true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
single level
|
|
1
|
+
// single level
|
|
@@ -1 +1 @@
|
|
|
1
|
-
nested level
|
|
1
|
+
// nested level
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const helpers = {}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# Test Server Root
|
|
2
|
-
|
|
3
|
-
This directory contains the persistent test server structure used by unit tests instead of creating temporary files for each test run. Tests use `withTestDir()` to get a temporary copy of this structure, maintaining isolation while providing consistent base files.
|
|
4
|
-
|
|
5
|
-
## Directory Structure
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
test-server-root/
|
|
9
|
-
├── README.md # This file
|
|
10
|
-
├── .config.json # Basic config with middleware settings
|
|
11
|
-
├── index.html # Basic home page: "<h1>Home</h1>"
|
|
12
|
-
├── late.html # For rescan tests: "later"
|
|
13
|
-
├── hello.html # For CLI tests: "hello world"
|
|
14
|
-
├── a.txt # Test file: "A"
|
|
15
|
-
├── b/
|
|
16
|
-
│ └── 1.txt # Test file: "B1"
|
|
17
|
-
├── api/
|
|
18
|
-
│ ├── GET.js # Route handler returning {ok:true, params}
|
|
19
|
-
│ └── no-default.js # Route file without default export
|
|
20
|
-
├── src/
|
|
21
|
-
│ ├── file.js # Content: "single level"
|
|
22
|
-
│ ├── file.txt # Content: "custom"
|
|
23
|
-
│ ├── nested/
|
|
24
|
-
│ │ └── file.js # Content: "nested level"
|
|
25
|
-
│ ├── components/
|
|
26
|
-
│ │ └── Button.js # Content: "export default Button"
|
|
27
|
-
│ ├── utils/
|
|
28
|
-
│ │ └── helpers/
|
|
29
|
-
│ │ └── format.js # Content: "export const format = () => {}"
|
|
30
|
-
│ └── deep/
|
|
31
|
-
│ └── nested/
|
|
32
|
-
│ └── folder/
|
|
33
|
-
│ └── file.js # Content: "export const deep = true"
|
|
34
|
-
├── docs/
|
|
35
|
-
│ ├── .config.json # Config with custom routes to ../src/**
|
|
36
|
-
│ ├── api/
|
|
37
|
-
│ │ └── data.json # Content: {"source": "static"}
|
|
38
|
-
│ └── src/
|
|
39
|
-
│ ├── nested/
|
|
40
|
-
│ │ └── file.js # Content: "fallback file"
|
|
41
|
-
│ ├── components/
|
|
42
|
-
│ │ └── Button.js # Content: "WRONG FILE"
|
|
43
|
-
│ └── utils/
|
|
44
|
-
│ └── helpers/
|
|
45
|
-
│ └── format.js # Content: "WRONG FILE"
|
|
46
|
-
├── custom/
|
|
47
|
-
│ └── data.json # Content: {"source": "custom"}
|
|
48
|
-
└── public/
|
|
49
|
-
└── src/
|
|
50
|
-
└── file.txt # Content: "static"
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Configuration Files
|
|
54
|
-
|
|
55
|
-
### Root .config.json
|
|
56
|
-
Basic configuration for middleware testing:
|
|
57
|
-
```json
|
|
58
|
-
{
|
|
59
|
-
"middleware": {
|
|
60
|
-
"cors": {}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### docs/.config.json
|
|
66
|
-
Configuration for wildcard routing tests:
|
|
67
|
-
```json
|
|
68
|
-
{
|
|
69
|
-
"customRoutes": {
|
|
70
|
-
"/src/*": "../src/$1"
|
|
71
|
-
},
|
|
72
|
-
"routePreference": "customRoute"
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## Usage in Tests
|
|
77
|
-
|
|
78
|
-
### Simple Tests
|
|
79
|
-
Use `withTestDir()` for tests that can leverage the existing structure:
|
|
80
|
-
|
|
81
|
-
```javascript
|
|
82
|
-
await withTestDir(async (dir) => {
|
|
83
|
-
// dir contains a copy of all the above files
|
|
84
|
-
// Use existing files or create additional ones as needed
|
|
85
|
-
const handler = await router({root: dir}, log);
|
|
86
|
-
// ... test the handler
|
|
87
|
-
});
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### Subdirectory Tests
|
|
91
|
-
Use the `subdir` option to work within a specific folder:
|
|
92
|
-
|
|
93
|
-
```javascript
|
|
94
|
-
await withTestDir(async (dir) => {
|
|
95
|
-
// dir points to test-server-root/docs/
|
|
96
|
-
process.chdir(dir);
|
|
97
|
-
const handler = await router({root: '.'}, log);
|
|
98
|
-
// ... test from docs folder perspective
|
|
99
|
-
}, {subdir: 'docs'});
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### Complex Tests
|
|
103
|
-
For tests requiring very specific or complex structures, continue using `withTempDir()`:
|
|
104
|
-
|
|
105
|
-
```javascript
|
|
106
|
-
await withTempDir(async (dir) => {
|
|
107
|
-
await write(dir, 'very/specific/structure.js', 'content');
|
|
108
|
-
// ... custom test setup
|
|
109
|
-
});
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
## Benefits
|
|
113
|
-
|
|
114
|
-
1. **Consistency** - All tests start with the same base structure
|
|
115
|
-
2. **Speed** - No need to recreate common files for each test
|
|
116
|
-
3. **Maintainability** - Centralized test file management
|
|
117
|
-
4. **Documentation** - Clear visibility of what test files exist
|
|
118
|
-
5. **Isolation** - Each test still gets its own temporary copy
|