@agoric/internal 0.3.3-dev-2f90d3f.0.2f90d3f → 0.3.3-dev-12fdf15.0.12fdf15
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/internal",
|
|
3
|
-
"version": "0.3.3-dev-
|
|
3
|
+
"version": "0.3.3-dev-12fdf15.0.12fdf15",
|
|
4
4
|
"description": "Externally unsupported utilities internal to agoric-sdk",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"lint:types": "yarn run -T tsc"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@agoric/base-zone": "0.1.1-dev-
|
|
23
|
+
"@agoric/base-zone": "0.1.1-dev-12fdf15.0.12fdf15",
|
|
24
24
|
"@endo/cache-map": "^1.1.0",
|
|
25
25
|
"@endo/common": "^1.2.13",
|
|
26
26
|
"@endo/compartment-mapper": "^1.6.3",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"jessie.js": "^0.3.4"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@agoric/cosmic-proto": "0.4.1-dev-
|
|
42
|
+
"@agoric/cosmic-proto": "0.4.1-dev-12fdf15.0.12fdf15",
|
|
43
43
|
"@endo/exo": "^1.5.12",
|
|
44
44
|
"@endo/init": "^1.1.12",
|
|
45
45
|
"@endo/ses-ava": "^1.3.2",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"typeCoverage": {
|
|
67
67
|
"atLeast": 92.84
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "12fdf156ed8e9a425cf8bcc9cdd1662bf4cad247"
|
|
70
70
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @import {ExecutionContext, Macro, TestFn} from 'ava';
|
|
2
|
+
* @import {ExecutionContext, ImplementationFn, Macro, MacroDeclarationOptions,TestFn} from 'ava';
|
|
3
3
|
*/
|
|
4
|
+
/** Not an official AVA feature, so prefix with `AGORIC_` */
|
|
5
|
+
export const AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS: "AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS";
|
|
6
|
+
/** Backwards compatibility... */
|
|
4
7
|
export const AVA_EXPECT_UNHANDLED_REJECTIONS: "AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS";
|
|
5
|
-
export const SUBTEST_PREFIX: "(unhandled rejection subprocess): ";
|
|
6
8
|
export function countUnhandled(work: () => any | Promise<any>, { gcAndFinalize }: {
|
|
7
9
|
gcAndFinalize: () => Promise<void>;
|
|
8
10
|
}): Promise<{
|
|
@@ -10,10 +12,16 @@ export function countUnhandled(work: () => any | Promise<any>, { gcAndFinalize }
|
|
|
10
12
|
pending: number;
|
|
11
13
|
seenUnhandled: number;
|
|
12
14
|
}>;
|
|
13
|
-
export function makeExpectUnhandledRejection<C>({ test, importMetaUrl }: {
|
|
15
|
+
export function makeExpectUnhandledRejection<C>({ test, sameWorker, importMetaUrl, }: {
|
|
14
16
|
test: TestFn<C>;
|
|
17
|
+
sameWorker?: boolean | undefined;
|
|
15
18
|
importMetaUrl: string;
|
|
16
19
|
}): (expectedUnhandled: number) => Macro<[name: string, impl: (t: ExecutionContext<C>) => any], C>;
|
|
20
|
+
export function makeExpectUnhandledRejectionMacro<C = unknown>({ test, sameWorker, importMetaUrl, }: {
|
|
21
|
+
test: TestFn<C>;
|
|
22
|
+
sameWorker?: boolean | undefined;
|
|
23
|
+
importMetaUrl: string;
|
|
24
|
+
}): (numUnhandled: number, innerMacro?: Macro<A, C>) => Macro<A, C>;
|
|
17
25
|
import type { TestFn } from 'ava';
|
|
18
26
|
import type { ExecutionContext } from 'ava';
|
|
19
27
|
import type { Macro } from 'ava';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ava-unhandled-rejection.d.ts","sourceRoot":"","sources":["ava-unhandled-rejection.js"],"names":[],"mappings":"AAOA;;GAEG;AAEH,
|
|
1
|
+
{"version":3,"file":"ava-unhandled-rejection.d.ts","sourceRoot":"","sources":["ava-unhandled-rejection.js"],"names":[],"mappings":"AAOA;;GAEG;AAEH,4DAA4D;AAC5D,qDACE,wCAAwC,CAAC;AAC3C,iCAAiC;AACjC,uFACyC;AA2ElC,qCAJI,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,qBAEhC;IAAoC,aAAa,EAAzC,MAAM,OAAO,CAAC,IAAI,CAAC;CAC7B;;;;GA4BA;AAeM,6CARM,CAAC,wCAEX;IAA0B,IAAI,EAAtB,OAAO,CAAC,CAAC;IACQ,UAAU;IACZ,aAAa,EAA5B,MAAM;CACd,GAAU,CAAE,iBAAiB,EAAE,MAAM,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EACzE,iBAAqB,CAAC,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAkEpC;AASM,kDANO,CAAC,kDAEZ;IAA0B,IAAI,EAAtB,OAAO,CAAC,CAAC;IACQ,UAAU;IACZ,aAAa,EAA5B,MAAM;CAChB,IAiBS,cAJG,MAIS,EAAE,aAHX,MAAM,CAAC,EAAE,CAAC,CAGW,KAFnB,MAAM,CAAC,EAAE,CAAC,CAAC,CAoCzB;4BAxP2F,KAAK;sCAAL,KAAK;2BAAL,KAAK"}
|
|
@@ -6,13 +6,15 @@ import engineGC from './engine-gc.js';
|
|
|
6
6
|
import { makeGcAndFinalize } from './gc-and-finalize.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @import {ExecutionContext, Macro, TestFn} from 'ava';
|
|
9
|
+
* @import {ExecutionContext, ImplementationFn, Macro, MacroDeclarationOptions,TestFn} from 'ava';
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/** Not an official AVA feature, so prefix with `AGORIC_` */
|
|
13
|
+
export const AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS =
|
|
13
14
|
'AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS';
|
|
14
|
-
|
|
15
|
-
export const
|
|
15
|
+
/** Backwards compatibility... */
|
|
16
|
+
export const AVA_EXPECT_UNHANDLED_REJECTIONS =
|
|
17
|
+
AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS;
|
|
16
18
|
|
|
17
19
|
const delayTurn = () => new Promise(resolve => setImmediate(resolve));
|
|
18
20
|
const settleUnhandled = async () => {
|
|
@@ -117,51 +119,68 @@ export const countUnhandled = async (work, { gcAndFinalize }) => {
|
|
|
117
119
|
};
|
|
118
120
|
|
|
119
121
|
/**
|
|
122
|
+
* @deprecated Use `makeExpectUnhandledRejectionMacro` instead, which uses the
|
|
123
|
+
* test's first argument title instead of an explicit `name`, and can
|
|
124
|
+
* optionally wrap an inner `Macro`.
|
|
125
|
+
*
|
|
120
126
|
* @template C
|
|
121
127
|
* @param {object} powers
|
|
122
128
|
* @param {TestFn<C>} powers.test
|
|
129
|
+
* @param {boolean} [powers.sameWorker]
|
|
123
130
|
* @param {string} powers.importMetaUrl
|
|
124
|
-
* @returns {(
|
|
125
|
-
*
|
|
126
|
-
* ) => Macro<[name: string, impl: (t: ExecutionContext<C>) => any], C>}
|
|
131
|
+
* @returns {( expectedUnhandled: number) => Macro<[name: string, impl: (t:
|
|
132
|
+
* ExecutionContext<C>) => any], C>}
|
|
127
133
|
*/
|
|
128
|
-
export const makeExpectUnhandledRejection = ({
|
|
134
|
+
export const makeExpectUnhandledRejection = ({
|
|
135
|
+
test,
|
|
136
|
+
sameWorker = false,
|
|
137
|
+
importMetaUrl,
|
|
138
|
+
}) => {
|
|
129
139
|
const self = fileURLToPath(importMetaUrl);
|
|
130
140
|
const gcAndFinalize = makeGcAndFinalize(engineGC);
|
|
131
141
|
|
|
132
|
-
if (process.env[AVA_EXPECT_UNHANDLED_REJECTIONS]) {
|
|
142
|
+
if (sameWorker || process.env[AVA_EXPECT_UNHANDLED_REJECTIONS]) {
|
|
143
|
+
let mutex = Promise.resolve();
|
|
133
144
|
return expectedUnhandled =>
|
|
134
145
|
test.macro({
|
|
135
|
-
title: (
|
|
146
|
+
title: (_providedTitle = '', name, _impl) => name,
|
|
136
147
|
exec: async (t, _name, impl) => {
|
|
137
148
|
const rawExpected =
|
|
138
|
-
|
|
149
|
+
(sameWorker
|
|
150
|
+
? undefined
|
|
151
|
+
: process.env[AVA_EXPECT_UNHANDLED_REJECTIONS]) ||
|
|
152
|
+
expectedUnhandled;
|
|
139
153
|
const expected = Number(rawExpected);
|
|
140
154
|
if (!Number.isSafeInteger(expected) || expected < 0) {
|
|
141
155
|
t.fail(
|
|
142
156
|
`expected unhandled rejection count to be a natural number, got ${rawExpected}`,
|
|
143
157
|
);
|
|
144
158
|
}
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const totalUnhandled = unhandled + pending;
|
|
150
|
-
if (totalUnhandled !== expected) {
|
|
151
|
-
t.fail(
|
|
152
|
-
`expected ${expected} unhandled promise rejections, got ${totalUnhandled} (of ${seenUnhandled} seen, ${pending} pending finalization)`,
|
|
159
|
+
const nextP = mutex.then(async () => {
|
|
160
|
+
const { unhandled, pending, seenUnhandled } = await countUnhandled(
|
|
161
|
+
() => impl(t),
|
|
162
|
+
{ gcAndFinalize },
|
|
153
163
|
);
|
|
154
|
-
|
|
164
|
+
const totalUnhandled = unhandled + pending;
|
|
165
|
+
if (totalUnhandled !== expected) {
|
|
166
|
+
t.fail(
|
|
167
|
+
`expected ${expected} unhandled promise rejections, got ${totalUnhandled} (of ${seenUnhandled} seen, ${pending} pending finalization)`,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
mutex = nextP.catch(() => {}); // don't let a failure block the next test
|
|
172
|
+
await nextP;
|
|
155
173
|
},
|
|
156
174
|
});
|
|
157
175
|
}
|
|
158
176
|
|
|
159
177
|
return expectedUnhandled =>
|
|
160
178
|
test.macro({
|
|
161
|
-
title: (
|
|
179
|
+
title: (_providedTitle = '', name, _impl) =>
|
|
180
|
+
`${name} (unhandled: ${expectedUnhandled})`,
|
|
162
181
|
exec: async (t, name, _impl) =>
|
|
163
182
|
new Promise((resolve, reject) => {
|
|
164
|
-
const ps = spawn('ava', [self, '
|
|
183
|
+
const ps = spawn('ava', [self, '--match', name], {
|
|
165
184
|
env: {
|
|
166
185
|
...process.env,
|
|
167
186
|
[AVA_EXPECT_UNHANDLED_REJECTIONS]: `${expectedUnhandled}`,
|
|
@@ -177,3 +196,62 @@ export const makeExpectUnhandledRejection = ({ test, importMetaUrl }) => {
|
|
|
177
196
|
}),
|
|
178
197
|
});
|
|
179
198
|
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @template [C=unknown]
|
|
202
|
+
* @param {object} powers
|
|
203
|
+
* @param {TestFn<C>} powers.test
|
|
204
|
+
* @param {boolean} [powers.sameWorker] defaults to require in-process execution
|
|
205
|
+
* @param {string} powers.importMetaUrl
|
|
206
|
+
*/
|
|
207
|
+
export const makeExpectUnhandledRejectionMacro = ({
|
|
208
|
+
test,
|
|
209
|
+
sameWorker = true,
|
|
210
|
+
importMetaUrl,
|
|
211
|
+
}) => {
|
|
212
|
+
const expectUnhandledRejection = makeExpectUnhandledRejection({
|
|
213
|
+
test,
|
|
214
|
+
sameWorker,
|
|
215
|
+
importMetaUrl,
|
|
216
|
+
});
|
|
217
|
+
/**
|
|
218
|
+
* @template {any[]} [A=[ImplementationFn<any[], any>, ...any[]]]
|
|
219
|
+
* @param {number} numUnhandled
|
|
220
|
+
* @param {Macro<A, C>} [innerMacro]
|
|
221
|
+
* @returns {Macro<A, C>}
|
|
222
|
+
*/
|
|
223
|
+
return (numUnhandled, innerMacro) => {
|
|
224
|
+
const expector = expectUnhandledRejection(numUnhandled);
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @param {ExecutionContext<C>} _t
|
|
228
|
+
* @param {A} args
|
|
229
|
+
* @returns {(t: ExecutionContext<C>) => any}
|
|
230
|
+
*/
|
|
231
|
+
const makeImpl = (_t, args) =>
|
|
232
|
+
innerMacro
|
|
233
|
+
? async t => innerMacro.exec(t, ...args)
|
|
234
|
+
: t => (0, args[0])(t, ...args);
|
|
235
|
+
|
|
236
|
+
/** @type {string} */
|
|
237
|
+
return test.macro(
|
|
238
|
+
/** @type {MacroDeclarationOptions<A, C>} */ ({
|
|
239
|
+
title(providedTitle = '', ...args) {
|
|
240
|
+
let expectorName =
|
|
241
|
+
innerMacro?.title?.(providedTitle, ...args) ?? providedTitle;
|
|
242
|
+
const impl = () => {};
|
|
243
|
+
if (process.env[AVA_EXPECT_UNHANDLED_REJECTIONS]) {
|
|
244
|
+
expectorName =
|
|
245
|
+
expector.title?.(expectorName, expectorName, impl) ??
|
|
246
|
+
expectorName;
|
|
247
|
+
}
|
|
248
|
+
return expectorName;
|
|
249
|
+
},
|
|
250
|
+
async exec(t, ...args) {
|
|
251
|
+
const impl = makeImpl(t, args);
|
|
252
|
+
return expector.exec(t, t.title, impl);
|
|
253
|
+
},
|
|
254
|
+
}),
|
|
255
|
+
);
|
|
256
|
+
};
|
|
257
|
+
};
|