Skip to content

Commit 6f7685c

Browse files
committed
test faster
Signed-off-by: 🕷️ <[email protected]>
1 parent ee8183b commit 6f7685c

File tree

7 files changed

+27
-21
lines changed

7 files changed

+27
-21
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ valid:
2525
pnpm exec svelte-check --no-tsconfig # only for *.svelte files
2626

2727
test: valid
28-
deno test --no-check --trace-leaks --reporter=dot
28+
deno test --parallel --no-check --trace-leaks --reporter=dot
29+
30+
test-dev:
31+
deno test --watch --parallel --no-check --trace-leaks
2932

3033
prod: test
3134
rm -rf $(BUILD_DIR) $(CHROME_ZIP)

tests/AnimationWrapper_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ describe('AnimationWrapper', () => {
8484
});
8585
});
8686

87-
await wait(1e1);
87+
await wait(10);

tests/EvalWrapper_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@ describe('EvalWrapper', () => {
9191
});
9292
});
9393

94-
await wait(1e1);
94+
await wait(10);

tests/IdleWrapper_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ describe('IdleWrapper', () => {
9696
});
9797
});
9898

99-
await wait(1e1);
99+
await wait(10);

tests/TimerWrapper_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ describe('wrappers', () => {
266266
expect(Fact.check(rec.facts, ClearTimerFact.BAD_HANDLER)).toBe(false);
267267
});
268268

269-
test('clearIntervalHistory - non existent handler', () => {
269+
test('clearIntervalHistory - non-existent handler', () => {
270270
globalThis.clearInterval(1000);
271271

272272
const rec = Array.from(apiTimer.clearIntervalHistory.values())[0];
@@ -287,4 +287,4 @@ describe('wrappers', () => {
287287
});
288288
});
289289

290-
await wait(1e1);
290+
await wait(10);

tests/browserPolyfill.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
console.log('👋 globals');
21
import { PropertySymbol, Window } from 'happy-dom';
32

43
const window = new Window();
@@ -11,17 +10,19 @@ Object.assign(globalThis, {
1110
location: window.location,
1211
Element: browserWindow.Element,
1312
Document: browserWindow.Document,
13+
1414
requestAnimationFrame: function requestAnimationFrameDumbStub(
1515
callback: (delay: number) => void,
1616
) {
1717
return setTimeout(() => {
1818
callback(performance.now());
1919
}, 1e3 / 60);
20-
// We need to call endImmediate() before the callback as the callback might throw an error.
2120
},
21+
2222
cancelAnimationFrame: function cancelAnimationFrameDumbStub(id: number) {
2323
clearTimeout(id);
2424
},
25+
2526
requestIdleCallback: function requestIdleCallbackDumbStub(
2627
callback: (deadline: {
2728
didTimeout: boolean;
@@ -33,6 +34,7 @@ Object.assign(globalThis, {
3334
callback({ didTimeout: false, timeRemaining: performance.now() });
3435
}, options?.timeout || 0);
3536
},
37+
3638
cancelIdleCallback: function cancelIdleCallbackDumbStub(id: number) {
3739
clearTimeout(id);
3840
},

tests/time_test.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
wait,
1212
} from '../src/api/time.ts';
1313

14+
const DELAY = 10;
15+
1416
describe('Stopper', () => {
1517
let stopper: Stopper;
1618

@@ -19,7 +21,6 @@ describe('Stopper', () => {
1921
});
2022

2123
test('start/stop', async () => {
22-
const DELAY = 10;
2324
stopper.start();
2425
await wait(DELAY);
2526
stopper.stop();
@@ -34,7 +35,6 @@ describe('Stopper', () => {
3435
});
3536

3637
test('elapsed continues counting after stop', async () => {
37-
const DELAY = 10;
3838
stopper.start();
3939
await wait(DELAY);
4040
stopper.stop();
@@ -58,7 +58,6 @@ describe('Stopper', () => {
5858
describe('Timer - default options', () => {
5959
test('start', async () => {
6060
let counter = 0;
61-
const DELAY = 10;
6261
const timer = new Timer({ delay: DELAY }, () => {
6362
counter++;
6463
});
@@ -73,7 +72,6 @@ describe('Timer - default options', () => {
7372

7473
test('stop before expected', async () => {
7574
let counter = 0;
76-
const DELAY = 10;
7775
const timer = new Timer({ delay: 2 * DELAY }, () => {
7876
counter++;
7977
});
@@ -91,7 +89,6 @@ describe('Timer - default options', () => {
9189
describe('Timer - interval option', () => {
9290
test('start/stop', async () => {
9391
let counter = 0;
94-
const DELAY = 10;
9592
const interval = new Timer({ delay: DELAY, repetitive: true }, () => {
9693
counter++;
9794
});
@@ -106,23 +103,27 @@ describe('Timer - interval option', () => {
106103

107104
describe('Timer - animation + measurable', () => {
108105
test('start/stop', async () => {
109-
const SECOND = 1e3;
110106
let count = 0;
111-
const timer = new Timer({ animation: true, measurable: true }, () => {
107+
const TIMESPAN = 100;
108+
const timer = new Timer({
109+
animation: true,
110+
repetitive: true,
111+
measurable: true,
112+
}, () => {
112113
count++;
113114
});
114115

115116
expect(timer.isPending()).toBe(false);
116-
117117
timer.start();
118-
119118
expect(timer.isPending()).toBe(true);
120-
await wait(SECOND);
119+
120+
await wait(TIMESPAN);
121121

122122
timer.stop();
123123
expect(timer.isPending()).toBe(false);
124-
expect(timer.callbackSelfTime < 0.5).toBe(true);
125-
expect(count).toBeLessThan(62);
124+
expect(timer.callbackSelfTime).toBeLessThan(0.5);
125+
expect(count).toBeGreaterThan(1);
126+
expect(count).toBeLessThan(TIMESPAN / (1e3 / 60));
126127
});
127128
});
128129

@@ -174,4 +175,4 @@ describe('callableOnce', () => {
174175
});
175176
});
176177

177-
await wait(1e3);
178+
await wait(10);

0 commit comments

Comments
 (0)