kempo-testing-framework 1.1.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/.github/copilot-instructions.md +105 -0
- package/CONTRIBUTING.md +107 -0
- package/README.md +293 -0
- package/gui/components/Collapsible.js +54 -0
- package/gui/components/Icon.js +151 -0
- package/gui/components/Logs.js +73 -0
- package/gui/components/SettingCheckbox.js +42 -0
- package/gui/components/SettingNumber.js +77 -0
- package/gui/components/SettingSelect.js +67 -0
- package/gui/components/Test.js +99 -0
- package/gui/components/TestFramework.js +236 -0
- package/gui/components/TestSuite.js +181 -0
- package/gui/components/TestSummary.js +189 -0
- package/gui/components/Theme.js +40 -0
- package/gui/components/settingsStore.js +46 -0
- package/gui/icons/fail.svg +1 -0
- package/gui/icons/logs.svg +1 -0
- package/gui/icons/pass.svg +1 -0
- package/gui/icons/play.svg +1 -0
- package/gui/icons/running.svg +1 -0
- package/gui/icons/scheduled.svg +1 -0
- package/gui/icons/settings.svg +1 -0
- package/gui/icons/theme-auto.svg +1 -0
- package/gui/icons/theme-dark.svg +1 -0
- package/gui/icons/theme-light.svg +1 -0
- package/gui/index.html +108 -0
- package/gui/lit-all.min.js +120 -0
- package/index.js +122 -0
- package/package.json +21 -0
- package/src/browserTestServer.js +115 -0
- package/src/cli.js +198 -0
- package/src/findTests.js +34 -0
- package/src/gui.js +249 -0
- package/src/runBrowserTests.js +71 -0
- package/src/runTestFiles.js +94 -0
- package/src/runTests.js +83 -0
- package/src/utils/logLevels.js +7 -0
- package/test.html +23 -0
- package/tests/Counter.js +34 -0
- package/tests/cli-flags.node-test.js +54 -0
- package/tests/cli-loglevel.node-test.js +40 -0
- package/tests/collapsible.browser-test.js +49 -0
- package/tests/counter.browser-test.js +141 -0
- package/tests/example.node-test.js +103 -0
- package/tests/icon.browser-test.js +54 -0
- package/tests/logs.browser-test.js +47 -0
- package/tests/setting-checkbox.browser-test.js +48 -0
- package/tests/setting-number.browser-test.js +54 -0
- package/tests/setting-select.browser-test.js +47 -0
- package/tests/settings-store.browser-test.js +26 -0
- package/tests/src-browserTestServer.node-test.js +47 -0
- package/tests/src-cli.node-test.js +32 -0
- package/tests/src-findTests.node-test.js +41 -0
- package/tests/src-logLevels.node-test.js +29 -0
- package/tests/src-runBrowserTests.node-test.js +41 -0
- package/tests/src-runTestFiles.node-test.js +42 -0
- package/tests/src-runTests.node-test.js +56 -0
- package/tests/test-framework.browser-test.js +65 -0
- package/tests/test-summary.browser-test.js +78 -0
- package/tests/test.browser-test.js +56 -0
- package/tests/testfile.browser-test.js +60 -0
- package/tests/theme.browser-test.js +38 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Code Contribution Guidelines
|
|
2
|
+
|
|
3
|
+
## Project Structure
|
|
4
|
+
|
|
5
|
+
- All code should be in the `src/` directory, with the exception of index.js.
|
|
6
|
+
- All utility function module files should be in the `src/utils/` directory.
|
|
7
|
+
|
|
8
|
+
### GUI
|
|
9
|
+
|
|
10
|
+
All files served by the GUI should be in the `gui/` directory, with the exception of scripts shared with the CLI, custom endpoints, and node_modules like essential.css (which should have custom endpoints).
|
|
11
|
+
|
|
12
|
+
## Coding Style Guidelines
|
|
13
|
+
|
|
14
|
+
### Code Organization
|
|
15
|
+
Use multi-line comments to separate code into logical sections. Group related functionality together.
|
|
16
|
+
- Example: In Lit components, group lifecycle callbacks, event handlers, public methods, utility functions, and rendering logic separately.
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
/*
|
|
20
|
+
Lifecycle Callbacks
|
|
21
|
+
*/
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Avoid single-use variables/functions
|
|
25
|
+
Avoid defining a variable or function to only use it once; inline the logic where needed. Some exceptions include:
|
|
26
|
+
- recursion
|
|
27
|
+
- scope encapsulation (IIFE)
|
|
28
|
+
- context changes
|
|
29
|
+
|
|
30
|
+
### Minimal Comments, Empty Lines, and Spacing
|
|
31
|
+
|
|
32
|
+
Use minimal comments. Assume readers understand the language. Some exceptions include:
|
|
33
|
+
- complex logic
|
|
34
|
+
- anti-patterns
|
|
35
|
+
- code organization
|
|
36
|
+
|
|
37
|
+
Do not put random empty lines within code; put them where they make sense for readability, for example:
|
|
38
|
+
- above and below definitions for functions and classes.
|
|
39
|
+
- to help break up large sections of logic to be more readable. If there are 100 lines of code with no breaks, it gets hard to read.
|
|
40
|
+
- above multi-line comments to indicate the comment belongs to the code below
|
|
41
|
+
|
|
42
|
+
No empty lines in css.
|
|
43
|
+
|
|
44
|
+
End each file with an empty line.
|
|
45
|
+
|
|
46
|
+
End each line with a `;` when possible, even if it is optional.
|
|
47
|
+
|
|
48
|
+
Avoid unnecessary spacing, for example:
|
|
49
|
+
- after the word `if`
|
|
50
|
+
- within parentheses for conditional statements
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
let count = 1;
|
|
54
|
+
|
|
55
|
+
const incrementOdd = (n) => {
|
|
56
|
+
if(n % 2 !== 0){
|
|
57
|
+
return n++;
|
|
58
|
+
}
|
|
59
|
+
return n;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
count = incrementOdd(count);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Prefer Arrow Functions
|
|
66
|
+
Prefer the use of arrow functions when possible, especially for class methods to avoid binding. Use normal functions if needed for preserving the proper context.
|
|
67
|
+
- For very basic logic, use implicit returns
|
|
68
|
+
- If there is a single parameter, omit the parentheses.
|
|
69
|
+
```javascript
|
|
70
|
+
const addOne = n => n + 1;
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Module Exports
|
|
74
|
+
- If a module has only one export, use the "default" export, not a named export.
|
|
75
|
+
- Do not declare the default export as a const or give it a name; just export the value.
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
export default (n) => n + 1;
|
|
79
|
+
```
|
|
80
|
+
- If a module has multiple exports, use named exports and do not use a "default" export.
|
|
81
|
+
|
|
82
|
+
### Code Reuse
|
|
83
|
+
Create utility functions for shared logic.
|
|
84
|
+
- If the shared logic is used in a single file, define a utility function in that file.
|
|
85
|
+
- If the shared logic is used in multiple files, create a utility function module file in `src/utils/`.
|
|
86
|
+
|
|
87
|
+
### Naming
|
|
88
|
+
Do not prefix identifiers with underscores.
|
|
89
|
+
- Never use leading underscores (`_`) for variable, property, method, or function names.
|
|
90
|
+
- Use clear, descriptive names without prefixes.
|
|
91
|
+
- When true privacy is needed inside classes, prefer native JavaScript private fields (e.g., `#myField`) instead of simulated privacy via underscores.
|
|
92
|
+
|
|
93
|
+
## Lit Components
|
|
94
|
+
|
|
95
|
+
### Component Architecture and Communication
|
|
96
|
+
|
|
97
|
+
- Use methods to cause actions; do not emit events to trigger logic. Events are for notifying that something already happened.
|
|
98
|
+
- Prefer `el.closest('ktf-test-framework')?.enqueueSuite({...})` over firing an `enqueue` event.
|
|
99
|
+
|
|
100
|
+
- Wrap dependent GUI components inside a parent `ktf-test-framework` element. Children find it via `closest('ktf-test-framework')` and call its methods. The framework can query its subtree to orchestrate children.
|
|
101
|
+
|
|
102
|
+
- Avoid `window` globals and global custom events for coordination. If broadcast is needed, scope events to the framework element; reserve window events for global, non-visual concerns (e.g., settings changes).
|
|
103
|
+
|
|
104
|
+
- Queued status must show the `scheduled` icon. Running may apply `animation="spin"`.
|
|
105
|
+
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Code Contribution Guidelines
|
|
2
|
+
|
|
3
|
+
## Project Structure
|
|
4
|
+
|
|
5
|
+
- All code should be in the `src/` directory, with the exception of index.js.
|
|
6
|
+
- All utility function module files should be in the `src/utils/` directory.
|
|
7
|
+
|
|
8
|
+
### GUI
|
|
9
|
+
|
|
10
|
+
All files served by the GUI should be in the `gui/` directory, with the exception of scripts shared with the CLI, custom endpoints, and node_modules like essential.css (which should have custom endpoints).
|
|
11
|
+
|
|
12
|
+
## Coding Style Guidelines
|
|
13
|
+
|
|
14
|
+
### Code Organization
|
|
15
|
+
Use multi-line comments to separate code into logical sections. Group related functionality together.
|
|
16
|
+
- Example: In Lit components, group lifecycle callbacks, event handlers, public methods, utility functions, and rendering logic separately.
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
/*
|
|
20
|
+
Lifecycle Callbacks
|
|
21
|
+
*/
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Avoid single-use variables/functions
|
|
25
|
+
Avoid defining a variable or function to only use it once; inline the logic where needed. Some exceptions include:
|
|
26
|
+
- recursion
|
|
27
|
+
- scope encapsulation (IIFE)
|
|
28
|
+
- context changes
|
|
29
|
+
|
|
30
|
+
### Minimal Comments, Empty Lines, and Spacing
|
|
31
|
+
|
|
32
|
+
Use minimal comments. Assume readers understand the language. Some exceptions include:
|
|
33
|
+
- complex logic
|
|
34
|
+
- anti-patterns
|
|
35
|
+
- code organization
|
|
36
|
+
|
|
37
|
+
Do not put random empty lines within code; put them where they make sense for readability, for example:
|
|
38
|
+
- above and below definitions for functions and classes.
|
|
39
|
+
- to help break up large sections of logic to be more readable. If there are 100 lines of code with no breaks, it gets hard to read.
|
|
40
|
+
- above multi-line comments to indicate the comment belongs to the code below
|
|
41
|
+
|
|
42
|
+
No empty lines in css.
|
|
43
|
+
|
|
44
|
+
End each file with an empty line.
|
|
45
|
+
|
|
46
|
+
End each line with a `;` when possible, even if it is optional.
|
|
47
|
+
|
|
48
|
+
Avoid unnecessary spacing, for example:
|
|
49
|
+
- after the word `if`
|
|
50
|
+
- within parentheses for conditional statements
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
let count = 1;
|
|
54
|
+
|
|
55
|
+
const incrementOdd = (n) => {
|
|
56
|
+
if(n % 2 !== 0){
|
|
57
|
+
return n++;
|
|
58
|
+
}
|
|
59
|
+
return n;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
count = incrementOdd(count);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Prefer Arrow Functions
|
|
66
|
+
Prefer the use of arrow functions when possible, especially for class methods to avoid binding. Use normal functions if needed for preserving the proper context.
|
|
67
|
+
- For very basic logic, use implicit returns
|
|
68
|
+
- If there is a single parameter, omit the parentheses.
|
|
69
|
+
```javascript
|
|
70
|
+
const addOne = n => n + 1;
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Module Exports
|
|
74
|
+
- If a module has only one export, use the "default" export, not a named export.
|
|
75
|
+
- Do not declare the default export as a const or give it a name; just export the value.
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
export default (n) => n + 1;
|
|
79
|
+
```
|
|
80
|
+
- If a module has multiple exports, use named exports and do not use a "default" export.
|
|
81
|
+
|
|
82
|
+
### Code Reuse
|
|
83
|
+
Create utility functions for shared logic.
|
|
84
|
+
- If the shared logic is used in a single file, define a utility function in that file.
|
|
85
|
+
- If the shared logic is used in multiple files, create a utility function module file in `src/utils/`.
|
|
86
|
+
|
|
87
|
+
### Naming
|
|
88
|
+
Do not prefix identifiers with underscores.
|
|
89
|
+
- Never use leading underscores (`_`) for variable, property, method, or function names.
|
|
90
|
+
- Use clear, descriptive names without prefixes.
|
|
91
|
+
- When true privacy is needed inside classes, prefer native JavaScript private fields (e.g., `#myField`) instead of simulated privacy via underscores.
|
|
92
|
+
|
|
93
|
+
## Lit Components
|
|
94
|
+
|
|
95
|
+
### Component Architecture and Communication
|
|
96
|
+
|
|
97
|
+
- Prefer direct method calls to trigger behavior. Do not dispatch custom events to make something happen. Use events only to inform that something already happened.
|
|
98
|
+
- Do: `this.closest('ktf-test-framework').enqueueTest({...});`
|
|
99
|
+
- Don’t: `this.closest('ktf-test-framework').dispatchEvent(new CustomEvent('enqueue', {...}))` to trigger logic.
|
|
100
|
+
|
|
101
|
+
- Containment-first design: place orchestrators (e.g., `ktf-test-framework`) as a parent that wraps all dependent components (summary, suites, tests). Children should locate the parent with `closest('ktf-test-framework')` and call its methods.
|
|
102
|
+
- Parents may query their own subtree (`this.querySelectorAll(...)`) to find children.
|
|
103
|
+
|
|
104
|
+
- Avoid window globals and window-scoped events for app logic. Scope cross-component events to the containing framework element when possible. Window events are reserved for process-wide concerns (e.g., settings store changes).
|
|
105
|
+
|
|
106
|
+
- Status and UI mapping: queued status should render the `scheduled` icon; running may use spin animation.
|
|
107
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
# Kempo Testing Framework
|
|
2
|
+
|
|
3
|
+
The Kempo Testing Framework is a simple testing framework built on these principles:
|
|
4
|
+
|
|
5
|
+
- **Test in the right environment:** Code should be tested in the environment it is written for. Code intended to be ran in the browser is tested in the browser; code intended to be ran in Node is tested in Node. And code intended to be ran in either should be tested in both.
|
|
6
|
+
- **No mocks, no shims:** Test the real thing, not a simulation.
|
|
7
|
+
- **Simplicity:** No custom syntax to learn. Just JavaScript functions and three helpers: `log`, `pass`, and `fail`.
|
|
8
|
+
- **Zero learning curve:** If you know JavaScript, you know how to write tests.
|
|
9
|
+
|
|
10
|
+
It can be run from a web GUI or from the command line.
|
|
11
|
+
|
|
12
|
+
This was originally built to test Kempo, but there is nothing Kempo specific about it, it could be used for any JavaScript project.
|
|
13
|
+
|
|
14
|
+
## Requirements
|
|
15
|
+
|
|
16
|
+
- Node.js version 14.8.0 or higher is required (for ES modules and top-level await support).
|
|
17
|
+
- Modern browsers for running browser tests.
|
|
18
|
+
|
|
19
|
+
If you are using an older version of Node.js, please upgrade to a supported version to use Kempo Testing Framework.
|
|
20
|
+
|
|
21
|
+
## Setup
|
|
22
|
+
|
|
23
|
+
Install `kempo-testing-framework` as a dependency in your project:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install kempo-testing-framework --save-dev
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Test Types
|
|
30
|
+
|
|
31
|
+
Kempo supports two types of tests that can coexist in the same test suite:
|
|
32
|
+
|
|
33
|
+
### Browser Tests
|
|
34
|
+
Tests that run directly in the browser environment. Best for:
|
|
35
|
+
- DOM manipulation
|
|
36
|
+
- Browser APIs
|
|
37
|
+
- UI components
|
|
38
|
+
- Client-side functionality
|
|
39
|
+
|
|
40
|
+
### Node Tests
|
|
41
|
+
Tests that run on the server via API calls. Best for:
|
|
42
|
+
- Server-side logic
|
|
43
|
+
- File system operations
|
|
44
|
+
- Node-specific APIs
|
|
45
|
+
- Pure JavaScript functions
|
|
46
|
+
|
|
47
|
+
Each type of test (browser / node) should have its own test file, but both will run
|
|
48
|
+
|
|
49
|
+
## Test File Naming
|
|
50
|
+
|
|
51
|
+
Kempo supports three types of test files:
|
|
52
|
+
|
|
53
|
+
- `[name].browser-test.js` — runs only in the browser
|
|
54
|
+
- `[name].node-test.js` — runs only in Node
|
|
55
|
+
- `[name].test.js` — runs in both environments
|
|
56
|
+
|
|
57
|
+
If your code is intended to run in both Node and the browser, you should write a single test file named `[name].test.js.`, otherwise use the environment specific file names `[name].browser-test.js` and/or `[name]node-test.js`.
|
|
58
|
+
|
|
59
|
+
## Writing Tests
|
|
60
|
+
|
|
61
|
+
### Lifecycle Callbacks
|
|
62
|
+
Test files can export the following optional lifecycle functions:
|
|
63
|
+
|
|
64
|
+
- **`beforeAll`** - Runs once before all tests (setup)
|
|
65
|
+
- **`afterAll`** - Runs once after all tests (cleanup)
|
|
66
|
+
- **`beforeEach`** - Runs before each individual test
|
|
67
|
+
- **`afterEach`** - Runs after each individual test
|
|
68
|
+
|
|
69
|
+
**Note:** All test functions and lifecycle callbacks can be `async` functions if you need to await asynchronous operations.
|
|
70
|
+
|
|
71
|
+
## Example Test File
|
|
72
|
+
|
|
73
|
+
`[name].test.js`, `[name].browser-test.js`, or `[name].node-test.js`... they all should look exactly the same.
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
// Import the thing to test
|
|
77
|
+
import yourModule from '../../src/yourModule.js';
|
|
78
|
+
|
|
79
|
+
/* Export the optional lifecycle callbacks */
|
|
80
|
+
export const beforeAll = async (log) => {
|
|
81
|
+
log('Setting up Node test environment...');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const beforeEach = async (log) => {
|
|
85
|
+
log('Setting up Node test for each test')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const beforeEach = async (log) => {
|
|
89
|
+
log('Cleaning up Node test for each test')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const afterAll = async (log) => {
|
|
93
|
+
log('Cleaning up Node test environment...');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* Export the Tests */
|
|
97
|
+
export default {
|
|
98
|
+
'should handle basic functionality': async ({pass, fail, log}) => {
|
|
99
|
+
const expected = 'abc123';
|
|
100
|
+
const result = yourModule.someFunction();
|
|
101
|
+
if (result === expected) {
|
|
102
|
+
log('✓ Basic functionality works');
|
|
103
|
+
pass('Test passed successfully')
|
|
104
|
+
} else {
|
|
105
|
+
fail(`Expected ${expected}, got ${result}`);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
'should validate input parameters': async ({pass, fail, log}) => {
|
|
109
|
+
try {
|
|
110
|
+
yourModule.someFunction(null);
|
|
111
|
+
fail('Should have thrown an error for null input');
|
|
112
|
+
} catch (error) {
|
|
113
|
+
log('✓ Properly validates input');
|
|
114
|
+
pass('Input validation test passed');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Running Tests
|
|
122
|
+
|
|
123
|
+
### CLI (Command-Line Interface)
|
|
124
|
+
Run all tests using npx:
|
|
125
|
+
```bash
|
|
126
|
+
npx kempo-test
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Run only the browser tests:
|
|
130
|
+
```bash
|
|
131
|
+
npx kempo-test -b
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Run only the node tests:
|
|
135
|
+
```bash
|
|
136
|
+
npx kempo-test -n
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### GUI (webpage)
|
|
140
|
+
|
|
141
|
+
Run the GUI interface:
|
|
142
|
+
```bash
|
|
143
|
+
npx kempo-test --gui
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Using npm Scripts (Optional)
|
|
147
|
+
|
|
148
|
+
You can add npm scripts to your `package.json` for convenience:
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"scripts": {
|
|
153
|
+
"tests": "npx kempo-test",
|
|
154
|
+
"tests:gui": "npx kempo-test --gui",
|
|
155
|
+
"tests:browser": "npx kempo-test -b",
|
|
156
|
+
"tests:node": "npx kempo-test -n"
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Then run with:
|
|
162
|
+
```bash
|
|
163
|
+
npm run tests # Run all tests
|
|
164
|
+
npm run tests:gui # Start GUI
|
|
165
|
+
npm run tests:browser # Run only browser tests
|
|
166
|
+
npm run tests:node # Run only node tests
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Important:** npm scripts with npx don't reliably pass additional arguments. If you need to use flags like `--show-browser`, `--log-level`, or filters, use `npx kempo-test` directly instead of npm scripts.
|
|
170
|
+
|
|
171
|
+
## CLI Flags Reference
|
|
172
|
+
|
|
173
|
+
When running tests via the CLI, you can use various flags to control test execution and output. These flags only affect CLI execution and are ignored when using the GUI (`--gui` flag).
|
|
174
|
+
|
|
175
|
+
Note: For flags that take values, you can use either a space or equals: `--log-level verbose` or `--log-level=verbose`. Short flags also support equals for value flags: `-l verbose` or `-l=verbose`. Examples below use spaces for clarity.
|
|
176
|
+
|
|
177
|
+
### Environment Flags
|
|
178
|
+
|
|
179
|
+
**`-b` or `--browser`**
|
|
180
|
+
- Runs only browser tests (`.browser-test.js` files and `.test.js` files in browser environment)
|
|
181
|
+
- Example: `npx kempo-test -b`
|
|
182
|
+
- Example with filter: `npx kempo-test -b auth`
|
|
183
|
+
|
|
184
|
+
**`-n` or `--node`**
|
|
185
|
+
- Runs only Node tests (`.node-test.js` files and `.test.js` files in Node environment)
|
|
186
|
+
- Example: `npx kempo-test -n`
|
|
187
|
+
- Example with filter: `npx kempo-test -n user`
|
|
188
|
+
|
|
189
|
+
### Log Level Flag
|
|
190
|
+
|
|
191
|
+
Set the verbosity of output:
|
|
192
|
+
|
|
193
|
+
**`-l` or `--log-level`**
|
|
194
|
+
- Accepts numeric 0–4 or names: `silent|minimal|normal|verbose|debug` (also `s|m|n|v|d`)
|
|
195
|
+
- Examples:
|
|
196
|
+
- `npx kempo-test -l debug`
|
|
197
|
+
- `npx kempo-test --log-level 3`
|
|
198
|
+
- `npx kempo-test -l n`
|
|
199
|
+
|
|
200
|
+
### Server Configuration Flags
|
|
201
|
+
|
|
202
|
+
**`-p` or `--port`**
|
|
203
|
+
- Specify the port for the browser test server (default: 3000)
|
|
204
|
+
- Port must be between 1 and 65535
|
|
205
|
+
- Example: `npx kempo-test -b --port 8080`
|
|
206
|
+
- Example: `npx kempo-test -p 3001`
|
|
207
|
+
|
|
208
|
+
**`--show-browser` or `-w`**
|
|
209
|
+
- Show the browser window during browser tests (default: headless mode)
|
|
210
|
+
- Useful for debugging browser tests and seeing what's happening
|
|
211
|
+
- Example: `npx kempo-test -b --show-browser`
|
|
212
|
+
- Example: `npx kempo-test -b -w`
|
|
213
|
+
|
|
214
|
+
**`--delay` or `-d`**
|
|
215
|
+
- Specify a browser pause delay in milliseconds (applies before and after browser tests when the browser window is shown)
|
|
216
|
+
- Example: `npx kempo-test -b --show-browser --delay 2000`
|
|
217
|
+
|
|
218
|
+
### Combining Flags
|
|
219
|
+
|
|
220
|
+
You can combine multiple flags for precise control:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
# Run only browser tests with verbose-like output using log level
|
|
224
|
+
npx kempo-test -b -l verbose auth
|
|
225
|
+
|
|
226
|
+
# Run only node tests with minimal output
|
|
227
|
+
npx kempo-test -n -l minimal user
|
|
228
|
+
|
|
229
|
+
# Run all tests silently with a specific filter
|
|
230
|
+
npx kempo-test -l silent payment
|
|
231
|
+
|
|
232
|
+
# Run browser tests with visible browser window, custom port and delay
|
|
233
|
+
npx kempo-test -b --show-browser --port 8080 --delay 2000
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Running Specific or Filtered Tests
|
|
237
|
+
|
|
238
|
+
Kempo supports two levels of filtering to help you run only the tests you need:
|
|
239
|
+
|
|
240
|
+
### File-Level Filtering
|
|
241
|
+
|
|
242
|
+
You can filter which test files to run by providing a partial filename (substring) as an argument. All test files whose names include the substring will be run. This works for both full and partial names, and matches anywhere in the filename (not just the start).
|
|
243
|
+
|
|
244
|
+
For example, if you have test files named `auth.browser-test.js`, `auth.node-test.js`, `user-auth.test.js`, and `payment.test.js`:
|
|
245
|
+
|
|
246
|
+
Run all tests with `auth` in the name (in both environments):
|
|
247
|
+
```bash
|
|
248
|
+
npx kempo-test auth
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Run only the browser tests with `auth` in the name:
|
|
252
|
+
```bash
|
|
253
|
+
npx kempo-test -b auth
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Run only the node tests with `auth` in the name:
|
|
257
|
+
```bash
|
|
258
|
+
npx kempo-test -n auth
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Individual Test Filtering
|
|
262
|
+
|
|
263
|
+
You can also filter individual tests within files by providing a second argument. This will find files matching the first filter, then within those files, run only tests whose names (object keys) contain the second filter.
|
|
264
|
+
|
|
265
|
+
Using the same example files, if your `auth.browser-test.js` contains tests like:
|
|
266
|
+
```javascript
|
|
267
|
+
export default {
|
|
268
|
+
'should handle user login validation': async ({pass, fail, log}) => { /* ... */ },
|
|
269
|
+
'should handle user logout process': async ({pass, fail, log}) => { /* ... */ },
|
|
270
|
+
'should validate password requirements': async ({pass, fail, log}) => { /* ... */ }
|
|
271
|
+
};
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Run only tests containing "login" in files containing "auth":
|
|
275
|
+
```bash
|
|
276
|
+
npx kempo-test auth login
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Run only browser tests containing "logout" in files containing "auth":
|
|
280
|
+
```bash
|
|
281
|
+
npx kempo-test -b auth logout
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Both file and test filtering are case-insensitive and use substring matching.
|
|
285
|
+
|
|
286
|
+
If you do not provide any filters, all test files will be auto-discovered and run.
|
|
287
|
+
|
|
288
|
+
### Help
|
|
289
|
+
|
|
290
|
+
Get usage instructions and see all available options:
|
|
291
|
+
```bash
|
|
292
|
+
npx kempo-test --help
|
|
293
|
+
```
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { LitElement, html, css } from '../lit-all.min.js';
|
|
2
|
+
|
|
3
|
+
window.customElements.define('ktf-collapsible', class extends LitElement {
|
|
4
|
+
/*
|
|
5
|
+
Properties
|
|
6
|
+
*/
|
|
7
|
+
static properties = {
|
|
8
|
+
opened: { type: Boolean, reflect: true }
|
|
9
|
+
}
|
|
10
|
+
constructor(){
|
|
11
|
+
super();
|
|
12
|
+
this.opened = false;
|
|
13
|
+
}
|
|
14
|
+
connectedCallback(){
|
|
15
|
+
super.connectedCallback();
|
|
16
|
+
if (this.hasAttribute('opened')) this.opened = true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
Event Handling
|
|
21
|
+
*/
|
|
22
|
+
toggle = () => {
|
|
23
|
+
this.opened = !this.opened;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
Rendering
|
|
28
|
+
*/
|
|
29
|
+
render(){
|
|
30
|
+
return html`
|
|
31
|
+
<link rel="stylesheet" href="/essential.css">
|
|
32
|
+
<div class="header">
|
|
33
|
+
<div class="actions">
|
|
34
|
+
<slot name="actions"></slot>
|
|
35
|
+
</div>
|
|
36
|
+
<button class="no-btn p r title" @click=${this.toggle}>
|
|
37
|
+
<slot name="title">Show ${this.opened?'Less':'More'}</slot>
|
|
38
|
+
</button>
|
|
39
|
+
</div>
|
|
40
|
+
${this.opened?html`<div class="bt p pb0"><slot></slot></div>`:''}
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
static styles = css`
|
|
44
|
+
:host {
|
|
45
|
+
display: block;
|
|
46
|
+
border: 1px solid var(--c_border, #cccccc);
|
|
47
|
+
border-radius: var(--radius, 0.25rem);
|
|
48
|
+
margin-bottom: var(--spacer, 1rem);
|
|
49
|
+
}
|
|
50
|
+
.header { display: flex; align-items: center; }
|
|
51
|
+
.title { flex: 1; text-align: left; }
|
|
52
|
+
.actions { display: inline-flex; align-items: center; gap: .5rem; }
|
|
53
|
+
`;
|
|
54
|
+
});
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { LitElement, html, css, unsafeHTML } from '../lit-all.min.js';
|
|
2
|
+
|
|
3
|
+
// Static cache to store fetched icons across all instances
|
|
4
|
+
const iconCache = new Map();
|
|
5
|
+
|
|
6
|
+
window.customElements.define('ktf-icon', class extends LitElement {
|
|
7
|
+
/*
|
|
8
|
+
Properties
|
|
9
|
+
*/
|
|
10
|
+
static properties = {
|
|
11
|
+
name: { type: String, reflect: true },
|
|
12
|
+
svg: { type: String },
|
|
13
|
+
animation: { type: String, reflect: true }
|
|
14
|
+
}
|
|
15
|
+
constructor(){
|
|
16
|
+
super();
|
|
17
|
+
this.name = '';
|
|
18
|
+
this.animation = 'none';
|
|
19
|
+
this.defaultSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960""><path fill="currentColor" d="M480-79q-16 0-30.5-6T423-102L102-423q-11-12-17-26.5T79-480q0-16 6-31t17-26l321-321q12-12 26.5-17.5T480-881q16 0 31 5.5t26 17.5l321 321q12 11 17.5 26t5.5 31q0 16-5.5 30.5T858-423L537-102q-11 11-26 17t-31 6Zm0-80 321-321-321-321-321 321 321 321Zm-40-281h80v-240h-80v240Zm40 120q17 0 28.5-11.5T520-360q0-17-11.5-28.5T480-400q-17 0-28.5 11.5T440-360q0 17 11.5 28.5T480-320Zm0-160Z"/></svg>';
|
|
20
|
+
this.svg = this.defaultSvg;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
Lifecycle Callback
|
|
25
|
+
*/
|
|
26
|
+
updated(changedProperties){
|
|
27
|
+
if(changedProperties.has('name')){
|
|
28
|
+
this.fetchIcon();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
Methods
|
|
34
|
+
*/
|
|
35
|
+
async fetchIcon(){
|
|
36
|
+
if (this.name) {
|
|
37
|
+
// Check cache first
|
|
38
|
+
const cached = iconCache.get(this.name);
|
|
39
|
+
if (cached) {
|
|
40
|
+
if (cached instanceof Promise) {
|
|
41
|
+
this.svg = await cached;
|
|
42
|
+
} else {
|
|
43
|
+
this.svg = cached;
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Cache the promise immediately
|
|
49
|
+
const promise = (async () => {
|
|
50
|
+
try {
|
|
51
|
+
const response = await fetch(`/icons/${this.name}.svg`);
|
|
52
|
+
return response.ok ? await response.text() : this.defaultSvg;
|
|
53
|
+
} catch {
|
|
54
|
+
return this.defaultSvg;
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
|
|
58
|
+
iconCache.set(this.name, promise);
|
|
59
|
+
|
|
60
|
+
const svgContent = await promise;
|
|
61
|
+
iconCache.set(this.name, svgContent);
|
|
62
|
+
this.svg = svgContent;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
Rendering
|
|
68
|
+
*/
|
|
69
|
+
render(){
|
|
70
|
+
return html`${unsafeHTML(this.svg)}`;
|
|
71
|
+
}
|
|
72
|
+
static styles = css`
|
|
73
|
+
:host {
|
|
74
|
+
display: inline-block;
|
|
75
|
+
height: 1.35em;
|
|
76
|
+
width: 1.35em;
|
|
77
|
+
vertical-align: top;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* Animation classes */
|
|
81
|
+
:host([animation="spin"]) {
|
|
82
|
+
animation: spin 1s linear infinite;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
:host([animation="pulse"]) {
|
|
86
|
+
animation: pulse 1.5s ease-in-out infinite;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
:host([animation="bounce"]) {
|
|
90
|
+
animation: bounce 1s ease-in-out infinite;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
:host([animation="shake"]) {
|
|
94
|
+
animation: shake 0.5s ease-in-out infinite;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
:host([animation="fade"]) {
|
|
98
|
+
animation: fade 2s ease-in-out infinite;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
:host([animation="flip"]) {
|
|
102
|
+
animation: flip 2s ease-in-out infinite;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* Keyframe definitions */
|
|
106
|
+
@keyframes spin {
|
|
107
|
+
from { transform: rotate(0deg); }
|
|
108
|
+
to { transform: rotate(360deg); }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@keyframes pulse {
|
|
112
|
+
0%, 100% {
|
|
113
|
+
transform: scale(1);
|
|
114
|
+
opacity: 1;
|
|
115
|
+
}
|
|
116
|
+
50% {
|
|
117
|
+
transform: scale(1.1);
|
|
118
|
+
opacity: 0.7;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@keyframes bounce {
|
|
123
|
+
0%, 20%, 50%, 80%, 100% {
|
|
124
|
+
transform: translateY(0);
|
|
125
|
+
}
|
|
126
|
+
40% {
|
|
127
|
+
transform: translateY(-0.3em);
|
|
128
|
+
}
|
|
129
|
+
60% {
|
|
130
|
+
transform: translateY(-0.15em);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@keyframes shake {
|
|
135
|
+
0%, 100% { transform: translateX(0); }
|
|
136
|
+
10%, 30%, 50%, 70%, 90% { transform: translateX(-0.1em); }
|
|
137
|
+
20%, 40%, 60%, 80% { transform: translateX(0.1em); }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@keyframes fade {
|
|
141
|
+
0%, 100% { opacity: 1; }
|
|
142
|
+
50% { opacity: 0.3; }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@keyframes flip {
|
|
146
|
+
0% { transform: rotateY(0deg); }
|
|
147
|
+
50% { transform: rotateY(180deg); }
|
|
148
|
+
100% { transform: rotateY(360deg); }
|
|
149
|
+
}
|
|
150
|
+
`
|
|
151
|
+
});
|