overtake 1.4.0 → 2.0.1
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/README.md +4 -15
- package/build/cli.js +126 -125
- package/build/executor.d.ts +6 -2
- package/build/executor.js +59 -46
- package/build/gc-watcher.js +2 -6
- package/build/index.d.ts +10 -11
- package/build/index.js +153 -155
- package/build/register-hook.d.ts +1 -0
- package/build/register-hook.js +15 -0
- package/build/reporter.d.ts +10 -2
- package/build/reporter.js +176 -214
- package/build/runner.d.ts +1 -1
- package/build/runner.js +128 -119
- package/build/types.d.ts +6 -6
- package/build/types.js +9 -14
- package/build/utils.d.ts +1 -17
- package/build/utils.js +53 -85
- package/build/worker.js +25 -24
- package/package.json +7 -25
- package/src/__tests__/assert-no-closure.ts +135 -0
- package/src/__tests__/benchmark-execute.ts +48 -0
- package/src/cli.ts +137 -142
- package/src/executor.ts +45 -15
- package/src/index.ts +85 -57
- package/src/register-hook.ts +15 -0
- package/src/reporter.ts +26 -18
- package/src/runner.ts +1 -4
- package/src/types.ts +8 -8
- package/src/utils.ts +15 -54
- package/src/worker.ts +5 -2
- package/tsconfig.json +2 -1
- package/build/cli.cjs +0 -179
- package/build/cli.cjs.map +0 -1
- package/build/cli.js.map +0 -1
- package/build/executor.cjs +0 -123
- package/build/executor.cjs.map +0 -1
- package/build/executor.js.map +0 -1
- package/build/gc-watcher.cjs +0 -30
- package/build/gc-watcher.cjs.map +0 -1
- package/build/gc-watcher.js.map +0 -1
- package/build/index.cjs +0 -442
- package/build/index.cjs.map +0 -1
- package/build/index.js.map +0 -1
- package/build/reporter.cjs +0 -311
- package/build/reporter.cjs.map +0 -1
- package/build/reporter.js.map +0 -1
- package/build/runner.cjs +0 -532
- package/build/runner.cjs.map +0 -1
- package/build/runner.js.map +0 -1
- package/build/types.cjs +0 -66
- package/build/types.cjs.map +0 -1
- package/build/types.js.map +0 -1
- package/build/utils.cjs +0 -174
- package/build/utils.cjs.map +0 -1
- package/build/utils.js.map +0 -1
- package/build/worker.cjs +0 -155
- package/build/worker.cjs.map +0 -1
- package/build/worker.js.map +0 -1
- package/src/__tests__/assert-no-closure.js +0 -134
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { assertNoClosure } from '../utils.js';
|
|
2
|
-
|
|
3
|
-
describe('assertNoClosure', () => {
|
|
4
|
-
describe('allows functions without closures', () => {
|
|
5
|
-
test('arrow with params only', () => {
|
|
6
|
-
expect(() => assertNoClosure('(x) => x * 2', 'run')).not.toThrow();
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
test('arrow with local variables', () => {
|
|
10
|
-
expect(() => assertNoClosure('(ctx, input) => { const y = ctx.value + input; return y; }', 'run')).not.toThrow();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test('function expression', () => {
|
|
14
|
-
expect(() => assertNoClosure('function(x) { return x + 1; }', 'run')).not.toThrow();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('named function expression', () => {
|
|
18
|
-
expect(() => assertNoClosure('function run(x) { return x + 1; }', 'run')).not.toThrow();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('async arrow', () => {
|
|
22
|
-
expect(() => assertNoClosure('async (ctx) => { const r = await fetch("url"); return r; }', 'run')).not.toThrow();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('destructured params', () => {
|
|
26
|
-
expect(() => assertNoClosure('({a, b: c}, [d, ...e]) => a + c + d + e.length', 'run')).not.toThrow();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('nested function declaration', () => {
|
|
30
|
-
expect(() => assertNoClosure('(arr) => { function helper(x) { return x * 2; } return arr.map(helper); }', 'run')).not.toThrow();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('for-of loop variable', () => {
|
|
34
|
-
expect(() => assertNoClosure('(arr) => { let sum = 0; for (const x of arr) sum += x; return sum; }', 'run')).not.toThrow();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('member access on params', () => {
|
|
38
|
-
expect(() => assertNoClosure('(ctx) => ctx.data.map(x => x.value)', 'run')).not.toThrow();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('globals like console, Buffer, Math, Array', () => {
|
|
42
|
-
expect(() => assertNoClosure('(ctx) => { console.log(Math.max(...ctx)); return Buffer.from(Array.of(1)); }', 'run')).not.toThrow();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('try-catch with error binding', () => {
|
|
46
|
-
expect(() => assertNoClosure('(ctx) => { try { return ctx(); } catch (e) { return e; } }', 'run')).not.toThrow();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('class expression', () => {
|
|
50
|
-
expect(() => assertNoClosure('() => { class Foo { bar() { return 1; } } return new Foo(); }', 'run')).not.toThrow();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('label statements', () => {
|
|
54
|
-
expect(() => assertNoClosure('() => { outer: for (let i = 0; i < 10; i++) { break outer; } }', 'run')).not.toThrow();
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('detects closures', () => {
|
|
59
|
-
test('single closed-over variable', () => {
|
|
60
|
-
expect(() => assertNoClosure('(x) => x + closedOver', 'run')).toThrow(/closedOver/);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('multiple closed-over variables', () => {
|
|
64
|
-
expect(() => {
|
|
65
|
-
assertNoClosure('(ctx) => sharedData.filter(x => x > threshold)', 'run');
|
|
66
|
-
}).toThrow(/sharedData/);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('closed-over function call', () => {
|
|
70
|
-
expect(() => assertNoClosure('(ctx) => helper(ctx)', 'run')).toThrow(/helper/);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('closed-over array', () => {
|
|
74
|
-
expect(() => assertNoClosure('() => myArray.map(x => x * 2)', 'run')).toThrow(/myArray/);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('computed member access with outer variable', () => {
|
|
78
|
-
expect(() => assertNoClosure('(obj) => obj[key]', 'run')).toThrow(/key/);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('variable used as argument', () => {
|
|
82
|
-
expect(() => assertNoClosure('() => JSON.stringify(config)', 'run')).toThrow(/config/);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('variable in template literal', () => {
|
|
86
|
-
expect(() => assertNoClosure('() => `${prefix}-value`', 'run')).toThrow(/prefix/);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe('error message', () => {
|
|
91
|
-
test('includes the function name', () => {
|
|
92
|
-
expect(() => assertNoClosure('() => x', 'setup')).toThrow(/"setup"/);
|
|
93
|
-
expect(() => assertNoClosure('() => x', 'run')).toThrow(/"run"/);
|
|
94
|
-
expect(() => assertNoClosure('() => x', 'teardown')).toThrow(/"teardown"/);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test('lists all closed-over variables', () => {
|
|
98
|
-
try {
|
|
99
|
-
assertNoClosure('() => a + b + c', 'run');
|
|
100
|
-
expect.unreachable('should have thrown');
|
|
101
|
-
} catch (e) {
|
|
102
|
-
expect(e.message).toMatch(/\ba\b/);
|
|
103
|
-
expect(e.message).toMatch(/\bb\b/);
|
|
104
|
-
expect(e.message).toMatch(/\bc\b/);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test('explains the problem and suggests fix', () => {
|
|
109
|
-
try {
|
|
110
|
-
assertNoClosure('() => x', 'run');
|
|
111
|
-
expect.unreachable('should have thrown');
|
|
112
|
-
} catch (e) {
|
|
113
|
-
expect(e.message).toContain('.toString()');
|
|
114
|
-
expect(e.message).toContain('worker');
|
|
115
|
-
expect(e.message).toContain('setup');
|
|
116
|
-
expect(e.message).toContain('data');
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('edge cases', () => {
|
|
122
|
-
test('silently passes on unparseable code', () => {
|
|
123
|
-
expect(() => assertNoClosure('not valid js {{{', 'run')).not.toThrow();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test('empty arrow function', () => {
|
|
127
|
-
expect(() => assertNoClosure('() => {}', 'run')).not.toThrow();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test('undefined return', () => {
|
|
131
|
-
expect(() => assertNoClosure('() => undefined', 'run')).not.toThrow();
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|