kempo-testing-framework 1.2.4 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/.github/copilot-instructions.md +105 -105
  2. package/.github/workflows/publish-npm.yml +29 -0
  3. package/CONTRIBUTING.md +107 -107
  4. package/gui/components/Collapsible.js +54 -54
  5. package/gui/components/Icon.js +151 -151
  6. package/gui/components/Logs.js +73 -73
  7. package/gui/components/SettingCheckbox.js +42 -42
  8. package/gui/components/SettingNumber.js +77 -77
  9. package/gui/components/SettingSelect.js +67 -67
  10. package/gui/components/TestFramework.js +378 -378
  11. package/gui/components/TestSuite.js +181 -181
  12. package/gui/components/TestSummary.js +189 -189
  13. package/gui/components/Theme.js +40 -40
  14. package/gui/components/settingsStore.js +46 -46
  15. package/gui/icons/fail.svg +1 -1
  16. package/gui/icons/pass.svg +1 -1
  17. package/gui/icons/running.svg +1 -1
  18. package/gui/icons/settings.svg +1 -1
  19. package/package.json +6 -1
  20. package/src/browserTestServer.js +115 -115
  21. package/src/cli.js +198 -198
  22. package/src/gui.js +15 -2
  23. package/src/runBrowserTests.js +87 -87
  24. package/src/runTestFiles.js +94 -94
  25. package/src/runTests.js +83 -83
  26. package/src/utils/logLevels.js +7 -7
  27. package/test.html +30 -30
  28. package/tests/Counter.js +33 -33
  29. package/tests/cli-flags.node-test.js +54 -54
  30. package/tests/cli-help.node-test.js +61 -61
  31. package/tests/cli-loglevel.node-test.js +40 -40
  32. package/tests/collapsible.browser-test.js +49 -49
  33. package/tests/counter.browser-test.js +140 -140
  34. package/tests/example.node-test.js +103 -103
  35. package/tests/fibonacci.js +92 -92
  36. package/tests/fibonacci.test.js +285 -285
  37. package/tests/icon.browser-test.js +54 -54
  38. package/tests/logs.browser-test.js +47 -47
  39. package/tests/setting-checkbox.browser-test.js +48 -48
  40. package/tests/setting-number.browser-test.js +54 -54
  41. package/tests/setting-select.browser-test.js +47 -47
  42. package/tests/settings-store.browser-test.js +26 -26
  43. package/tests/src-browserTestServer.node-test.js +47 -47
  44. package/tests/src-cli.node-test.js +32 -32
  45. package/tests/src-findTests.node-test.js +41 -41
  46. package/tests/src-logLevels.node-test.js +29 -29
  47. package/tests/src-runBrowserTests.node-test.js +41 -41
  48. package/tests/src-runTestFiles.node-test.js +42 -42
  49. package/tests/src-runTests.node-test.js +56 -56
  50. package/tests/test-framework.browser-test.js +65 -65
  51. package/tests/test-summary.browser-test.js +78 -78
  52. package/tests/test.browser-test.js +56 -56
  53. package/tests/testfile.browser-test.js +60 -60
  54. package/tests/theme.browser-test.js +38 -38
@@ -1,285 +1,285 @@
1
- // Import the fibonacci utility functions
2
- import fibonacciUtils from './fibonacci.js';
3
-
4
- const { fibonacci, fibonacciSequence, isFibonacci } = fibonacciUtils;
5
-
6
- /*
7
- Lifecycle Callbacks
8
- */
9
- export const beforeAll = async (log) => {
10
- log('Setting up Fibonacci utility tests...');
11
- };
12
-
13
- export const beforeEach = async (log) => {
14
- log('Running Fibonacci test');
15
- };
16
-
17
- export const afterEach = async (log) => {
18
- log('Fibonacci test completed');
19
- };
20
-
21
- export const afterAll = async (log) => {
22
- log('Fibonacci utility tests finished');
23
- };
24
-
25
- /*
26
- Test Cases
27
- */
28
- export default {
29
- 'fibonacci - should return correct values for base cases': async ({pass, fail, log}) => {
30
- try {
31
- const testCases = [
32
- { input: 0, expected: 0 },
33
- { input: 1, expected: 1 },
34
- { input: 2, expected: 1 }
35
- ];
36
-
37
- for(const { input, expected } of testCases) {
38
- const result = fibonacci(input);
39
- if(result !== expected) {
40
- fail(`fibonacci(${input}) expected ${expected}, got ${result}`);
41
- return;
42
- }
43
- log(`✓ fibonacci(${input}) = ${result}`);
44
- }
45
-
46
- pass('Base cases work correctly');
47
- } catch (error) {
48
- fail(`Unexpected error: ${error.message}`);
49
- }
50
- },
51
-
52
- 'fibonacci - should calculate correct sequence values': async ({pass, fail, log}) => {
53
- try {
54
- const testCases = [
55
- { input: 3, expected: 2 },
56
- { input: 4, expected: 3 },
57
- { input: 5, expected: 5 },
58
- { input: 6, expected: 8 },
59
- { input: 7, expected: 13 },
60
- { input: 8, expected: 21 },
61
- { input: 10, expected: 55 }
62
- ];
63
-
64
- for(const { input, expected } of testCases) {
65
- const result = fibonacci(input);
66
- if(result !== expected) {
67
- fail(`fibonacci(${input}) expected ${expected}, got ${result}`);
68
- return;
69
- }
70
- log(`✓ fibonacci(${input}) = ${result}`);
71
- }
72
-
73
- pass('Sequence calculations are correct');
74
- } catch (error) {
75
- fail(`Unexpected error: ${error.message}`);
76
- }
77
- },
78
-
79
- 'fibonacci - should handle large numbers efficiently': async ({pass, fail, log}) => {
80
- try {
81
- const result = fibonacci(20);
82
- const expected = 6765;
83
-
84
- if(result !== expected) {
85
- fail(`fibonacci(20) expected ${expected}, got ${result}`);
86
- return;
87
- }
88
-
89
- log(`✓ fibonacci(20) = ${result}`);
90
- pass('Large number calculation works efficiently');
91
- } catch (error) {
92
- fail(`Unexpected error: ${error.message}`);
93
- }
94
- },
95
-
96
- 'fibonacci - should throw error for negative numbers': async ({pass, fail, log}) => {
97
- try {
98
- fibonacci(-1);
99
- fail('Should have thrown an error for negative input');
100
- } catch (error) {
101
- if(error.message === 'Input must be a non-negative integer') {
102
- log('✓ Properly rejects negative numbers');
103
- pass('Input validation for negative numbers works');
104
- } else {
105
- fail(`Expected specific error message, got: ${error.message}`);
106
- }
107
- }
108
- },
109
-
110
- 'fibonacci - should throw error for non-integer inputs': async ({pass, fail, log}) => {
111
- try {
112
- const testInputs = [3.14, 'string', null, undefined, {}];
113
-
114
- for(const input of testInputs) {
115
- try {
116
- fibonacci(input);
117
- fail(`Should have thrown an error for input: ${input}`);
118
- return;
119
- } catch (error) {
120
- if(error.message === 'Input must be a non-negative integer') {
121
- log(`✓ Properly rejects invalid input: ${input}`);
122
- } else {
123
- fail(`Expected specific error message for ${input}, got: ${error.message}`);
124
- return;
125
- }
126
- }
127
- }
128
-
129
- pass('Input validation for non-integers works');
130
- } catch (error) {
131
- fail(`Unexpected error: ${error.message}`);
132
- }
133
- },
134
-
135
- 'fibonacciSequence - should return empty array for count 0': async ({pass, fail, log}) => {
136
- try {
137
- const result = fibonacciSequence(0);
138
-
139
- if(!Array.isArray(result) || result.length !== 0) {
140
- fail(`Expected empty array, got: ${JSON.stringify(result)}`);
141
- return;
142
- }
143
-
144
- log('✓ Returns empty array for count 0');
145
- pass('Empty sequence handling works');
146
- } catch (error) {
147
- fail(`Unexpected error: ${error.message}`);
148
- }
149
- },
150
-
151
- 'fibonacciSequence - should return correct sequences': async ({pass, fail, log}) => {
152
- try {
153
- const testCases = [
154
- { count: 1, expected: [0] },
155
- { count: 2, expected: [0, 1] },
156
- { count: 5, expected: [0, 1, 1, 2, 3] },
157
- { count: 8, expected: [0, 1, 1, 2, 3, 5, 8, 13] }
158
- ];
159
-
160
- for(const { count, expected } of testCases) {
161
- const result = fibonacciSequence(count);
162
-
163
- if(JSON.stringify(result) !== JSON.stringify(expected)) {
164
- fail(`fibonacciSequence(${count}) expected ${JSON.stringify(expected)}, got ${JSON.stringify(result)}`);
165
- return;
166
- }
167
-
168
- log(`✓ fibonacciSequence(${count}) = [${result.join(', ')}]`);
169
- }
170
-
171
- pass('Sequence generation works correctly');
172
- } catch (error) {
173
- fail(`Unexpected error: ${error.message}`);
174
- }
175
- },
176
-
177
- 'fibonacciSequence - should validate input parameters': async ({pass, fail, log}) => {
178
- try {
179
- const invalidInputs = [-1, 3.14, 'string', null];
180
-
181
- for(const input of invalidInputs) {
182
- try {
183
- fibonacciSequence(input);
184
- fail(`Should have thrown an error for input: ${input}`);
185
- return;
186
- } catch (error) {
187
- if(error.message === 'Count must be a non-negative integer') {
188
- log(`✓ Properly rejects invalid input: ${input}`);
189
- } else {
190
- fail(`Expected specific error message for ${input}, got: ${error.message}`);
191
- return;
192
- }
193
- }
194
- }
195
-
196
- pass('Sequence input validation works');
197
- } catch (error) {
198
- fail(`Unexpected error: ${error.message}`);
199
- }
200
- },
201
-
202
- 'isFibonacci - should correctly identify Fibonacci numbers': async ({pass, fail, log}) => {
203
- try {
204
- const fibonacciNumbers = [0, 1, 2, 3, 5, 8, 13, 21, 34, 55];
205
- const nonFibonacciNumbers = [4, 6, 7, 9, 10, 11, 12, 14, 15, 16];
206
-
207
- for(const num of fibonacciNumbers) {
208
- const result = isFibonacci(num);
209
- if(!result) {
210
- fail(`isFibonacci(${num}) should return true, got false`);
211
- return;
212
- }
213
- log(`✓ ${num} is correctly identified as Fibonacci`);
214
- }
215
-
216
- for(const num of nonFibonacciNumbers) {
217
- const result = isFibonacci(num);
218
- if(result) {
219
- fail(`isFibonacci(${num}) should return false, got true`);
220
- return;
221
- }
222
- log(`✓ ${num} is correctly identified as non-Fibonacci`);
223
- }
224
-
225
- pass('Fibonacci number identification works correctly');
226
- } catch (error) {
227
- fail(`Unexpected error: ${error.message}`);
228
- }
229
- },
230
-
231
- 'isFibonacci - should handle edge cases and invalid inputs': async ({pass, fail, log}) => {
232
- try {
233
- const invalidInputs = [
234
- { input: -1, expected: false, desc: 'negative number' },
235
- { input: 3.14, expected: false, desc: 'decimal number' },
236
- { input: 'string', expected: false, desc: 'string input' },
237
- { input: null, expected: false, desc: 'null input' },
238
- { input: undefined, expected: false, desc: 'undefined input' }
239
- ];
240
-
241
- for(const { input, expected, desc } of invalidInputs) {
242
- const result = isFibonacci(input);
243
- if(result !== expected) {
244
- fail(`isFibonacci(${input}) for ${desc} expected ${expected}, got ${result}`);
245
- return;
246
- }
247
- log(`✓ ${desc} handled correctly`);
248
- }
249
-
250
- pass('Edge case handling works correctly');
251
- } catch (error) {
252
- fail(`Unexpected error: ${error.message}`);
253
- }
254
- },
255
-
256
- 'integration - should work together across all functions': async ({pass, fail, log}) => {
257
- try {
258
- // Generate a sequence and verify each number
259
- const sequence = fibonacciSequence(10);
260
- log(`Generated sequence: [${sequence.join(', ')}]`);
261
-
262
- // Verify each number in the sequence using fibonacci function
263
- for(let i = 0; i < sequence.length; i++) {
264
- const expected = fibonacci(i);
265
- if(sequence[i] !== expected) {
266
- fail(`Sequence position ${i}: expected ${expected}, got ${sequence[i]}`);
267
- return;
268
- }
269
- }
270
-
271
- // Verify each number is identified as Fibonacci
272
- for(const num of sequence) {
273
- if(!isFibonacci(num)) {
274
- fail(`Number ${num} from sequence not identified as Fibonacci`);
275
- return;
276
- }
277
- }
278
-
279
- log('✓ All functions work together correctly');
280
- pass('Integration test passed successfully');
281
- } catch (error) {
282
- fail(`Integration test failed: ${error.message}`);
283
- }
284
- }
285
- };
1
+ // Import the fibonacci utility functions
2
+ import fibonacciUtils from './fibonacci.js';
3
+
4
+ const { fibonacci, fibonacciSequence, isFibonacci } = fibonacciUtils;
5
+
6
+ /*
7
+ Lifecycle Callbacks
8
+ */
9
+ export const beforeAll = async (log) => {
10
+ log('Setting up Fibonacci utility tests...');
11
+ };
12
+
13
+ export const beforeEach = async (log) => {
14
+ log('Running Fibonacci test');
15
+ };
16
+
17
+ export const afterEach = async (log) => {
18
+ log('Fibonacci test completed');
19
+ };
20
+
21
+ export const afterAll = async (log) => {
22
+ log('Fibonacci utility tests finished');
23
+ };
24
+
25
+ /*
26
+ Test Cases
27
+ */
28
+ export default {
29
+ 'fibonacci - should return correct values for base cases': async ({pass, fail, log}) => {
30
+ try {
31
+ const testCases = [
32
+ { input: 0, expected: 0 },
33
+ { input: 1, expected: 1 },
34
+ { input: 2, expected: 1 }
35
+ ];
36
+
37
+ for(const { input, expected } of testCases) {
38
+ const result = fibonacci(input);
39
+ if(result !== expected) {
40
+ fail(`fibonacci(${input}) expected ${expected}, got ${result}`);
41
+ return;
42
+ }
43
+ log(`✓ fibonacci(${input}) = ${result}`);
44
+ }
45
+
46
+ pass('Base cases work correctly');
47
+ } catch (error) {
48
+ fail(`Unexpected error: ${error.message}`);
49
+ }
50
+ },
51
+
52
+ 'fibonacci - should calculate correct sequence values': async ({pass, fail, log}) => {
53
+ try {
54
+ const testCases = [
55
+ { input: 3, expected: 2 },
56
+ { input: 4, expected: 3 },
57
+ { input: 5, expected: 5 },
58
+ { input: 6, expected: 8 },
59
+ { input: 7, expected: 13 },
60
+ { input: 8, expected: 21 },
61
+ { input: 10, expected: 55 }
62
+ ];
63
+
64
+ for(const { input, expected } of testCases) {
65
+ const result = fibonacci(input);
66
+ if(result !== expected) {
67
+ fail(`fibonacci(${input}) expected ${expected}, got ${result}`);
68
+ return;
69
+ }
70
+ log(`✓ fibonacci(${input}) = ${result}`);
71
+ }
72
+
73
+ pass('Sequence calculations are correct');
74
+ } catch (error) {
75
+ fail(`Unexpected error: ${error.message}`);
76
+ }
77
+ },
78
+
79
+ 'fibonacci - should handle large numbers efficiently': async ({pass, fail, log}) => {
80
+ try {
81
+ const result = fibonacci(20);
82
+ const expected = 6765;
83
+
84
+ if(result !== expected) {
85
+ fail(`fibonacci(20) expected ${expected}, got ${result}`);
86
+ return;
87
+ }
88
+
89
+ log(`✓ fibonacci(20) = ${result}`);
90
+ pass('Large number calculation works efficiently');
91
+ } catch (error) {
92
+ fail(`Unexpected error: ${error.message}`);
93
+ }
94
+ },
95
+
96
+ 'fibonacci - should throw error for negative numbers': async ({pass, fail, log}) => {
97
+ try {
98
+ fibonacci(-1);
99
+ fail('Should have thrown an error for negative input');
100
+ } catch (error) {
101
+ if(error.message === 'Input must be a non-negative integer') {
102
+ log('✓ Properly rejects negative numbers');
103
+ pass('Input validation for negative numbers works');
104
+ } else {
105
+ fail(`Expected specific error message, got: ${error.message}`);
106
+ }
107
+ }
108
+ },
109
+
110
+ 'fibonacci - should throw error for non-integer inputs': async ({pass, fail, log}) => {
111
+ try {
112
+ const testInputs = [3.14, 'string', null, undefined, {}];
113
+
114
+ for(const input of testInputs) {
115
+ try {
116
+ fibonacci(input);
117
+ fail(`Should have thrown an error for input: ${input}`);
118
+ return;
119
+ } catch (error) {
120
+ if(error.message === 'Input must be a non-negative integer') {
121
+ log(`✓ Properly rejects invalid input: ${input}`);
122
+ } else {
123
+ fail(`Expected specific error message for ${input}, got: ${error.message}`);
124
+ return;
125
+ }
126
+ }
127
+ }
128
+
129
+ pass('Input validation for non-integers works');
130
+ } catch (error) {
131
+ fail(`Unexpected error: ${error.message}`);
132
+ }
133
+ },
134
+
135
+ 'fibonacciSequence - should return empty array for count 0': async ({pass, fail, log}) => {
136
+ try {
137
+ const result = fibonacciSequence(0);
138
+
139
+ if(!Array.isArray(result) || result.length !== 0) {
140
+ fail(`Expected empty array, got: ${JSON.stringify(result)}`);
141
+ return;
142
+ }
143
+
144
+ log('✓ Returns empty array for count 0');
145
+ pass('Empty sequence handling works');
146
+ } catch (error) {
147
+ fail(`Unexpected error: ${error.message}`);
148
+ }
149
+ },
150
+
151
+ 'fibonacciSequence - should return correct sequences': async ({pass, fail, log}) => {
152
+ try {
153
+ const testCases = [
154
+ { count: 1, expected: [0] },
155
+ { count: 2, expected: [0, 1] },
156
+ { count: 5, expected: [0, 1, 1, 2, 3] },
157
+ { count: 8, expected: [0, 1, 1, 2, 3, 5, 8, 13] }
158
+ ];
159
+
160
+ for(const { count, expected } of testCases) {
161
+ const result = fibonacciSequence(count);
162
+
163
+ if(JSON.stringify(result) !== JSON.stringify(expected)) {
164
+ fail(`fibonacciSequence(${count}) expected ${JSON.stringify(expected)}, got ${JSON.stringify(result)}`);
165
+ return;
166
+ }
167
+
168
+ log(`✓ fibonacciSequence(${count}) = [${result.join(', ')}]`);
169
+ }
170
+
171
+ pass('Sequence generation works correctly');
172
+ } catch (error) {
173
+ fail(`Unexpected error: ${error.message}`);
174
+ }
175
+ },
176
+
177
+ 'fibonacciSequence - should validate input parameters': async ({pass, fail, log}) => {
178
+ try {
179
+ const invalidInputs = [-1, 3.14, 'string', null];
180
+
181
+ for(const input of invalidInputs) {
182
+ try {
183
+ fibonacciSequence(input);
184
+ fail(`Should have thrown an error for input: ${input}`);
185
+ return;
186
+ } catch (error) {
187
+ if(error.message === 'Count must be a non-negative integer') {
188
+ log(`✓ Properly rejects invalid input: ${input}`);
189
+ } else {
190
+ fail(`Expected specific error message for ${input}, got: ${error.message}`);
191
+ return;
192
+ }
193
+ }
194
+ }
195
+
196
+ pass('Sequence input validation works');
197
+ } catch (error) {
198
+ fail(`Unexpected error: ${error.message}`);
199
+ }
200
+ },
201
+
202
+ 'isFibonacci - should correctly identify Fibonacci numbers': async ({pass, fail, log}) => {
203
+ try {
204
+ const fibonacciNumbers = [0, 1, 2, 3, 5, 8, 13, 21, 34, 55];
205
+ const nonFibonacciNumbers = [4, 6, 7, 9, 10, 11, 12, 14, 15, 16];
206
+
207
+ for(const num of fibonacciNumbers) {
208
+ const result = isFibonacci(num);
209
+ if(!result) {
210
+ fail(`isFibonacci(${num}) should return true, got false`);
211
+ return;
212
+ }
213
+ log(`✓ ${num} is correctly identified as Fibonacci`);
214
+ }
215
+
216
+ for(const num of nonFibonacciNumbers) {
217
+ const result = isFibonacci(num);
218
+ if(result) {
219
+ fail(`isFibonacci(${num}) should return false, got true`);
220
+ return;
221
+ }
222
+ log(`✓ ${num} is correctly identified as non-Fibonacci`);
223
+ }
224
+
225
+ pass('Fibonacci number identification works correctly');
226
+ } catch (error) {
227
+ fail(`Unexpected error: ${error.message}`);
228
+ }
229
+ },
230
+
231
+ 'isFibonacci - should handle edge cases and invalid inputs': async ({pass, fail, log}) => {
232
+ try {
233
+ const invalidInputs = [
234
+ { input: -1, expected: false, desc: 'negative number' },
235
+ { input: 3.14, expected: false, desc: 'decimal number' },
236
+ { input: 'string', expected: false, desc: 'string input' },
237
+ { input: null, expected: false, desc: 'null input' },
238
+ { input: undefined, expected: false, desc: 'undefined input' }
239
+ ];
240
+
241
+ for(const { input, expected, desc } of invalidInputs) {
242
+ const result = isFibonacci(input);
243
+ if(result !== expected) {
244
+ fail(`isFibonacci(${input}) for ${desc} expected ${expected}, got ${result}`);
245
+ return;
246
+ }
247
+ log(`✓ ${desc} handled correctly`);
248
+ }
249
+
250
+ pass('Edge case handling works correctly');
251
+ } catch (error) {
252
+ fail(`Unexpected error: ${error.message}`);
253
+ }
254
+ },
255
+
256
+ 'integration - should work together across all functions': async ({pass, fail, log}) => {
257
+ try {
258
+ // Generate a sequence and verify each number
259
+ const sequence = fibonacciSequence(10);
260
+ log(`Generated sequence: [${sequence.join(', ')}]`);
261
+
262
+ // Verify each number in the sequence using fibonacci function
263
+ for(let i = 0; i < sequence.length; i++) {
264
+ const expected = fibonacci(i);
265
+ if(sequence[i] !== expected) {
266
+ fail(`Sequence position ${i}: expected ${expected}, got ${sequence[i]}`);
267
+ return;
268
+ }
269
+ }
270
+
271
+ // Verify each number is identified as Fibonacci
272
+ for(const num of sequence) {
273
+ if(!isFibonacci(num)) {
274
+ fail(`Number ${num} from sequence not identified as Fibonacci`);
275
+ return;
276
+ }
277
+ }
278
+
279
+ log('✓ All functions work together correctly');
280
+ pass('Integration test passed successfully');
281
+ } catch (error) {
282
+ fail(`Integration test failed: ${error.message}`);
283
+ }
284
+ }
285
+ };