joist-test-utils 1.33.0 → 1.33.2
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/build/index.d.ts +1 -1
- package/build/index.js +3 -1
- package/build/index.js.map +1 -1
- package/build/run.d.ts +7 -2
- package/build/run.js +18 -8
- package/build/run.js.map +1 -1
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="jest" />
|
|
2
2
|
import { MatchedEntity } from "./toMatchEntity";
|
|
3
|
-
export { run, runEach } from "./run";
|
|
3
|
+
export { makeRun, makeRunEach, run, runEach } from "./run";
|
|
4
4
|
export { toMatchEntity } from "./toMatchEntity";
|
|
5
5
|
declare global {
|
|
6
6
|
namespace jest {
|
package/build/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toMatchEntity = exports.runEach = exports.run = void 0;
|
|
3
|
+
exports.toMatchEntity = exports.runEach = exports.run = exports.makeRunEach = exports.makeRun = void 0;
|
|
4
4
|
var run_1 = require("./run");
|
|
5
|
+
Object.defineProperty(exports, "makeRun", { enumerable: true, get: function () { return run_1.makeRun; } });
|
|
6
|
+
Object.defineProperty(exports, "makeRunEach", { enumerable: true, get: function () { return run_1.makeRunEach; } });
|
|
5
7
|
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return run_1.run; } });
|
|
6
8
|
Object.defineProperty(exports, "runEach", { enumerable: true, get: function () { return run_1.runEach; } });
|
|
7
9
|
var toMatchEntity_1 = require("./toMatchEntity");
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,6BAA2D;AAAlD,8FAAA,OAAO,OAAA;AAAE,kGAAA,WAAW,OAAA;AAAE,0FAAA,GAAG,OAAA;AAAE,8FAAA,OAAO,OAAA;AAC3C,iDAAgD;AAAvC,8GAAA,aAAa,OAAA"}
|
package/build/run.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Context } from "./context";
|
|
2
2
|
declare type MaybePromise<T> = T | Promise<T>;
|
|
3
|
+
export declare type ContextFn<C> = (ctx: C) => MaybePromise<C>;
|
|
3
4
|
/** Runs the `fn` in a dedicated / non-test Unit of Work . */
|
|
4
|
-
export declare function run<C extends Context, T>(ctx: C, fn: (ctx: C) => MaybePromise<T>): Promise<T>;
|
|
5
|
+
export declare function run<C extends Context, T>(ctx: C, fn: (ctx: C) => MaybePromise<T>, contextFn?: ContextFn<C>): Promise<T>;
|
|
6
|
+
/** Creates a `run` with a custom `newContext` method. */
|
|
7
|
+
export declare function makeRun<C extends Context>(contextFn: ContextFn<C>): <T>(ctx: C, fn: (ctx: C) => MaybePromise<T>) => Promise<T>;
|
|
5
8
|
/** Runs the `fn` in a dedicated / non-test Unit of Work for each value in `values */
|
|
6
|
-
export declare function runEach<C extends Context, T, U>(ctx: C, valuesFn: () => U[], fn: (ctx: C, value: U) => MaybePromise<T>): Promise<T[]>;
|
|
9
|
+
export declare function runEach<C extends Context, T, U>(ctx: C, valuesFn: () => U[], fn: (ctx: C, value: U) => MaybePromise<T>, contextFn?: ContextFn<C>): Promise<T[]>;
|
|
10
|
+
/** Creates a `runEach` with a custom `newContext` method. */
|
|
11
|
+
export declare function makeRunEach<C extends Context>(contextFn: ContextFn<C>): <T, U>(ctx: C, valuesFn: () => U[], fn: (ctx: C, value: U) => MaybePromise<T>) => Promise<T[]>;
|
|
7
12
|
export {};
|
package/build/run.js
CHANGED
|
@@ -1,35 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runEach = exports.run = void 0;
|
|
3
|
+
exports.makeRunEach = exports.runEach = exports.makeRun = exports.run = void 0;
|
|
4
4
|
const joist_orm_1 = require("joist-orm");
|
|
5
5
|
/** Runs the `fn` in a dedicated / non-test Unit of Work . */
|
|
6
|
-
async function run(ctx, fn) {
|
|
6
|
+
async function run(ctx, fn, contextFn = newContext) {
|
|
7
7
|
const { em } = ctx;
|
|
8
8
|
// Ensure any test data we've setup is flushed
|
|
9
9
|
await em.flush();
|
|
10
|
-
const result = await
|
|
10
|
+
const result = await fn(await contextFn(ctx));
|
|
11
11
|
// We expect `fn` (i.e. a resolver) to do its own UoW management, so don't flush.
|
|
12
12
|
await em.refresh({ deepLoad: true });
|
|
13
13
|
return mapResultToOriginalEm(em, result);
|
|
14
14
|
}
|
|
15
15
|
exports.run = run;
|
|
16
|
+
/** Creates a `run` with a custom `newContext` method. */
|
|
17
|
+
function makeRun(contextFn) {
|
|
18
|
+
return (ctx, fn) => run(ctx, fn, contextFn);
|
|
19
|
+
}
|
|
20
|
+
exports.makeRun = makeRun;
|
|
16
21
|
/** Runs the `fn` in a dedicated / non-test Unit of Work for each value in `values */
|
|
17
|
-
async function runEach(ctx, valuesFn, fn) {
|
|
22
|
+
async function runEach(ctx, valuesFn, fn, contextFn = newContext) {
|
|
18
23
|
const { em } = ctx;
|
|
19
24
|
// Ensure any test data we've setup is flushed
|
|
20
25
|
await em.flush();
|
|
21
|
-
const results = await Promise.all(valuesFn().map((value) =>
|
|
26
|
+
const results = await Promise.all(valuesFn().map(async (value) => fn(await contextFn(ctx), value)));
|
|
22
27
|
// We expect `fn` (i.e. a resolver) to do its own UoW management, so don't flush.
|
|
23
28
|
await em.refresh({ deepLoad: true });
|
|
24
29
|
return mapResultToOriginalEm(em, results);
|
|
25
30
|
}
|
|
26
31
|
exports.runEach = runEach;
|
|
27
|
-
/**
|
|
28
|
-
|
|
32
|
+
/** Creates a `runEach` with a custom `newContext` method. */
|
|
33
|
+
function makeRunEach(contextFn) {
|
|
34
|
+
return (ctx, valuesFn, fn) => runEach(ctx, valuesFn, fn, contextFn);
|
|
35
|
+
}
|
|
36
|
+
exports.makeRunEach = makeRunEach;
|
|
37
|
+
function newContext(ctx) {
|
|
29
38
|
const { em } = ctx;
|
|
30
39
|
const newCtx = { ...ctx };
|
|
31
40
|
const newEm = new joist_orm_1.EntityManager(newCtx, em.driver);
|
|
32
|
-
|
|
41
|
+
Object.assign(newCtx, { em: newEm });
|
|
42
|
+
return newCtx;
|
|
33
43
|
}
|
|
34
44
|
function gatherEntities(result) {
|
|
35
45
|
if ((0, joist_orm_1.isEntity)(result)) {
|
package/build/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":";;;AAAA,yCAA4D;
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":";;;AAAA,yCAA4D;AAO5D,6DAA6D;AACtD,KAAK,UAAU,GAAG,CACvB,GAAM,EACN,EAA+B,EAC/B,YAA0B,UAAU;IAEpC,MAAM,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC;IACnB,8CAA8C;IAC9C,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;IACjB,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9C,iFAAiF;IACjF,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACrC,OAAO,qBAAqB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;AAC3C,CAAC;AAZD,kBAYC;AAED,yDAAyD;AACzD,SAAgB,OAAO,CACrB,SAAuB;IAEvB,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;AAC9C,CAAC;AAJD,0BAIC;AAED,qFAAqF;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