@effect/vitest 0.5.20 → 0.6.0
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/dist/cjs/index.js +10 -54
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal.js +97 -0
- package/dist/cjs/internal.js.map +1 -0
- package/dist/dts/index.d.ts +41 -19
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal.d.ts +2 -0
- package/dist/dts/internal.d.ts.map +1 -0
- package/dist/esm/index.js +8 -47
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal.js +64 -0
- package/dist/esm/internal.js.map +1 -0
- package/internal/package.json +6 -0
- package/package.json +14 -2
- package/src/index.ts +44 -159
- package/src/internal.ts +104 -0
package/dist/cjs/index.js
CHANGED
|
@@ -6,24 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
var _exportNames = {
|
|
7
7
|
addEqualityTesters: true,
|
|
8
8
|
effect: true,
|
|
9
|
-
live: true,
|
|
10
|
-
flakyTest: true,
|
|
11
9
|
scoped: true,
|
|
10
|
+
live: true,
|
|
12
11
|
scopedLive: true,
|
|
12
|
+
flakyTest: true,
|
|
13
13
|
it: true
|
|
14
14
|
};
|
|
15
15
|
exports.scopedLive = exports.scoped = exports.live = exports.it = exports.flakyTest = exports.effect = exports.addEqualityTesters = void 0;
|
|
16
|
-
var Cause = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Cause"));
|
|
17
|
-
var Duration = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Duration"));
|
|
18
|
-
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
|
|
19
|
-
var Equal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Equal"));
|
|
20
|
-
var Exit = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Exit"));
|
|
21
|
-
var _Function = /*#__PURE__*/require("effect/Function");
|
|
22
|
-
var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Layer"));
|
|
23
|
-
var Logger = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Logger"));
|
|
24
|
-
var Schedule = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Schedule"));
|
|
25
|
-
var TestEnvironment = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/TestContext"));
|
|
26
|
-
var Utils = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Utils"));
|
|
27
16
|
var V = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("vitest"));
|
|
28
17
|
Object.keys(V).forEach(function (key) {
|
|
29
18
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -36,6 +25,7 @@ Object.keys(V).forEach(function (key) {
|
|
|
36
25
|
}
|
|
37
26
|
});
|
|
38
27
|
});
|
|
28
|
+
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./internal.js"));
|
|
39
29
|
function _getRequireWildcardCache(e) {
|
|
40
30
|
if ("function" != typeof WeakMap) return null;
|
|
41
31
|
var r = new WeakMap(),
|
|
@@ -61,65 +51,31 @@ function _interopRequireWildcard(e, r) {
|
|
|
61
51
|
}
|
|
62
52
|
return n.default = e, t && t.set(e, n), n;
|
|
63
53
|
}
|
|
64
|
-
const runTest = effect => Effect.gen(function* () {
|
|
65
|
-
const exit = yield* Effect.exit(effect);
|
|
66
|
-
if (Exit.isSuccess(exit)) {
|
|
67
|
-
return () => {};
|
|
68
|
-
} else {
|
|
69
|
-
const errors = Cause.prettyErrors(exit.cause);
|
|
70
|
-
for (let i = 1; i < errors.length; i++) {
|
|
71
|
-
yield* Effect.logError(errors[i]);
|
|
72
|
-
}
|
|
73
|
-
return () => {
|
|
74
|
-
throw errors[0];
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
}).pipe(Effect.runPromise).then(f => f());
|
|
78
|
-
const TestEnv = /*#__PURE__*/TestEnvironment.TestContext.pipe( /*#__PURE__*/Layer.provide( /*#__PURE__*/Logger.remove(Logger.defaultLogger)));
|
|
79
|
-
/** @internal */
|
|
80
|
-
function customTester(a, b, customTesters) {
|
|
81
|
-
if (!Equal.isEqual(a) || !Equal.isEqual(b)) {
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
return Utils.structuralRegion(() => Equal.equals(a, b), (x, y) => this.equals(x, y, customTesters.filter(t => t !== customTester)));
|
|
85
|
-
}
|
|
86
54
|
/**
|
|
87
55
|
* @since 1.0.0
|
|
88
56
|
*/
|
|
89
|
-
const addEqualityTesters =
|
|
90
|
-
V.expect.addEqualityTesters([customTester]);
|
|
91
|
-
};
|
|
57
|
+
const addEqualityTesters = exports.addEqualityTesters = internal.addEqualityTesters;
|
|
92
58
|
/**
|
|
93
59
|
* @since 1.0.0
|
|
94
60
|
*/
|
|
95
|
-
exports.
|
|
96
|
-
const effect = exports.effect = /*#__PURE__*/(() => {
|
|
97
|
-
const f = (name, self, timeout = 5_000) => it(name, c => (0, _Function.pipe)(Effect.suspend(() => self(c)), Effect.provide(TestEnv), runTest), timeout);
|
|
98
|
-
return Object.assign(f, {
|
|
99
|
-
skip: (name, self, timeout = 5_000) => it.skip(name, c => (0, _Function.pipe)(Effect.suspend(() => self(c)), Effect.provide(TestEnv), runTest), timeout),
|
|
100
|
-
only: (name, self, timeout = 5_000) => it.only(name, c => (0, _Function.pipe)(Effect.suspend(() => self(c)), Effect.provide(TestEnv), runTest), timeout)
|
|
101
|
-
});
|
|
102
|
-
})();
|
|
61
|
+
const effect = exports.effect = internal.effect;
|
|
103
62
|
/**
|
|
104
63
|
* @since 1.0.0
|
|
105
64
|
*/
|
|
106
|
-
const
|
|
65
|
+
const scoped = exports.scoped = internal.scoped;
|
|
107
66
|
/**
|
|
108
67
|
* @since 1.0.0
|
|
109
68
|
*/
|
|
110
|
-
exports.live = live;
|
|
111
|
-
const flakyTest = (self, timeout = Duration.seconds(30)) => (0, _Function.pipe)(Effect.catchAllDefect(self, Effect.fail), Effect.retry((0, _Function.pipe)(Schedule.recurs(10), Schedule.compose(Schedule.elapsed), Schedule.whileOutput(Duration.lessThanOrEqualTo(timeout)))), Effect.orDie);
|
|
69
|
+
const live = exports.live = internal.live;
|
|
112
70
|
/**
|
|
113
71
|
* @since 1.0.0
|
|
114
72
|
*/
|
|
115
|
-
exports.
|
|
116
|
-
const scoped = (name, self, timeout = 5_000) => it(name, c => (0, _Function.pipe)(Effect.suspend(() => self(c)), Effect.scoped, Effect.provide(TestEnv), runTest), timeout);
|
|
73
|
+
const scopedLive = exports.scopedLive = internal.scopedLive;
|
|
117
74
|
/**
|
|
118
75
|
* @since 1.0.0
|
|
119
76
|
*/
|
|
120
|
-
exports.
|
|
121
|
-
|
|
122
|
-
exports.scopedLive = scopedLive;
|
|
77
|
+
const flakyTest = exports.flakyTest = internal.flakyTest;
|
|
78
|
+
/** @ignored */
|
|
123
79
|
const methods = {
|
|
124
80
|
effect,
|
|
125
81
|
live,
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["V","_interopRequireWildcard","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","internal","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","n","__proto__","a","getOwnPropertyDescriptor","u","i","set","addEqualityTesters","effect","scoped","live","scopedLive","flakyTest","methods","it","assign"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;AAOA,IAAAA,CAAA,gBAAAC,uBAAA,eAAAC,OAAA;AAqFAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,EAAAK,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAA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AA3B,MAAA,CAAAS,cAAA,CAAAY,CAAA,EAAAI,CAAA,EAAAC,CAAA,IAAAL,CAAA,CAAAI,CAAA,IAAAX,CAAA,CAAAW,CAAA;EAAA;EAAA,OAAAJ,CAAA,CAAAF,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAU,GAAA,CAAAb,CAAA,EAAAO,CAAA,GAAAA,CAAA;AAAA;AAwCzC;;;AAGO,MAAMO,kBAAkB,GAAApB,OAAA,CAAAoB,kBAAA,GAAehB,QAAQ,CAACgB,kBAAkB;AAEzE;;;AAGO,MAAMC,MAAM,GAAArB,OAAA,CAAAqB,MAAA,GAA6CjB,QAAQ,CAACiB,MAAM;AAE/E;;;AAGO,MAAMC,MAAM,GAAAtB,OAAA,CAAAsB,MAAA,GAA2DlB,QAAQ,CAACkB,MAAM;AAE7F;;;AAGO,MAAMC,IAAI,GAAAvB,OAAA,CAAAuB,IAAA,GAAyBnB,QAAQ,CAACmB,IAAI;AAEvD;;;AAGO,MAAMC,UAAU,GAAAxB,OAAA,CAAAwB,UAAA,GAA+BpB,QAAQ,CAACoB,UAAU;AAEzE;;;AAGO,MAAMC,SAAS,GAAAzB,OAAA,CAAAyB,SAAA,GAGYrB,QAAQ,CAACqB,SAAS;AAEpD;AACA,MAAMC,OAAO,GAAG;EAAEL,MAAM;EAAEE,IAAI;EAAEE,SAAS;EAAEH,MAAM;EAAEE;AAAU,CAAW;AAExE;;;AAGO,MAAMG,EAAE,GAAA3B,OAAA,CAAA2B,EAAA,gBAAyBnC,MAAM,CAACoC,MAAM,CAACvC,CAAC,CAACsC,EAAE,EAAED,OAAO,CAAC;AAEpE","ignoreList":[]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.scopedLive = exports.scoped = exports.live = exports.flakyTest = exports.effect = exports.addEqualityTesters = void 0;
|
|
7
|
+
var Cause = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Cause"));
|
|
8
|
+
var Duration = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Duration"));
|
|
9
|
+
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
|
|
10
|
+
var Equal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Equal"));
|
|
11
|
+
var Exit = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Exit"));
|
|
12
|
+
var _Function = /*#__PURE__*/require("effect/Function");
|
|
13
|
+
var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Layer"));
|
|
14
|
+
var Logger = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Logger"));
|
|
15
|
+
var Schedule = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Schedule"));
|
|
16
|
+
var TestEnvironment = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/TestContext"));
|
|
17
|
+
var Utils = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Utils"));
|
|
18
|
+
var V = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("vitest"));
|
|
19
|
+
function _getRequireWildcardCache(e) {
|
|
20
|
+
if ("function" != typeof WeakMap) return null;
|
|
21
|
+
var r = new WeakMap(),
|
|
22
|
+
t = new WeakMap();
|
|
23
|
+
return (_getRequireWildcardCache = function (e) {
|
|
24
|
+
return e ? t : r;
|
|
25
|
+
})(e);
|
|
26
|
+
}
|
|
27
|
+
function _interopRequireWildcard(e, r) {
|
|
28
|
+
if (!r && e && e.__esModule) return e;
|
|
29
|
+
if (null === e || "object" != typeof e && "function" != typeof e) return {
|
|
30
|
+
default: e
|
|
31
|
+
};
|
|
32
|
+
var t = _getRequireWildcardCache(r);
|
|
33
|
+
if (t && t.has(e)) return t.get(e);
|
|
34
|
+
var n = {
|
|
35
|
+
__proto__: null
|
|
36
|
+
},
|
|
37
|
+
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
38
|
+
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
39
|
+
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
40
|
+
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
|
|
41
|
+
}
|
|
42
|
+
return n.default = e, t && t.set(e, n), n;
|
|
43
|
+
}
|
|
44
|
+
/** @internal */
|
|
45
|
+
const runTest = effect => Effect.gen(function* () {
|
|
46
|
+
const exit = yield* Effect.exit(effect);
|
|
47
|
+
if (Exit.isSuccess(exit)) {
|
|
48
|
+
return () => {};
|
|
49
|
+
} else {
|
|
50
|
+
const errors = Cause.prettyErrors(exit.cause);
|
|
51
|
+
for (let i = 1; i < errors.length; i++) {
|
|
52
|
+
yield* Effect.logError(errors[i]);
|
|
53
|
+
}
|
|
54
|
+
return () => {
|
|
55
|
+
throw errors[0];
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}).pipe(Effect.runPromise).then(f => f());
|
|
59
|
+
/** @internal */
|
|
60
|
+
const TestEnv = /*#__PURE__*/TestEnvironment.TestContext.pipe( /*#__PURE__*/Layer.provide( /*#__PURE__*/Logger.remove(Logger.defaultLogger)));
|
|
61
|
+
/** @internal */
|
|
62
|
+
function customTester(a, b, customTesters) {
|
|
63
|
+
if (!Equal.isEqual(a) || !Equal.isEqual(b)) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
return Utils.structuralRegion(() => Equal.equals(a, b), (x, y) => this.equals(x, y, customTesters.filter(t => t !== customTester)));
|
|
67
|
+
}
|
|
68
|
+
/** @internal */
|
|
69
|
+
const addEqualityTesters = () => {
|
|
70
|
+
V.expect.addEqualityTesters([customTester]);
|
|
71
|
+
};
|
|
72
|
+
/** @internal */
|
|
73
|
+
exports.addEqualityTesters = addEqualityTesters;
|
|
74
|
+
const makeTester = mapEffect => {
|
|
75
|
+
const run = self => (...args) => (0, _Function.pipe)(Effect.suspend(() => self(...args)), mapEffect, runTest);
|
|
76
|
+
const f = (name, self, timeout) => V.it(name, run(self), timeout);
|
|
77
|
+
const skip = (name, self, timeout) => V.it.skip(name, run(self), timeout);
|
|
78
|
+
const only = (name, self, timeout) => V.it.only(name, run(self), timeout);
|
|
79
|
+
const each = cases => (name, self, timeout) => V.it.each(cases)(name, run(self), timeout);
|
|
80
|
+
return Object.assign(f, {
|
|
81
|
+
skip,
|
|
82
|
+
only,
|
|
83
|
+
each
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
/** @internal */
|
|
87
|
+
const effect = exports.effect = /*#__PURE__*/makeTester( /*#__PURE__*/Effect.provide(TestEnv));
|
|
88
|
+
/** @internal */
|
|
89
|
+
const scoped = exports.scoped = /*#__PURE__*/makeTester( /*#__PURE__*/(0, _Function.flow)(Effect.scoped, /*#__PURE__*/Effect.provide(TestEnv)));
|
|
90
|
+
/** @internal */
|
|
91
|
+
const live = exports.live = /*#__PURE__*/makeTester(_Function.identity);
|
|
92
|
+
/** @internal */
|
|
93
|
+
const scopedLive = exports.scopedLive = /*#__PURE__*/makeTester(Effect.scoped);
|
|
94
|
+
/** @internal */
|
|
95
|
+
const flakyTest = (self, timeout = Duration.seconds(30)) => (0, _Function.pipe)(Effect.catchAllDefect(self, Effect.fail), Effect.retry((0, _Function.pipe)(Schedule.recurs(10), Schedule.compose(Schedule.elapsed), Schedule.whileOutput(Duration.lessThanOrEqualTo(timeout)))), Effect.orDie);
|
|
96
|
+
exports.flakyTest = flakyTest;
|
|
97
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","names":["Cause","_interopRequireWildcard","require","Duration","Effect","Equal","Exit","_Function","Layer","Logger","Schedule","TestEnvironment","Utils","V","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","runTest","effect","gen","exit","isSuccess","errors","prettyErrors","cause","length","logError","pipe","runPromise","then","f","TestEnv","TestContext","provide","remove","defaultLogger","customTester","b","customTesters","isEqual","undefined","structuralRegion","equals","x","y","filter","addEqualityTesters","expect","exports","makeTester","mapEffect","run","self","args","suspend","name","timeout","it","skip","only","each","cases","assign","scoped","flow","live","identity","scopedLive","flakyTest","seconds","catchAllDefect","fail","retry","recurs","compose","elapsed","whileOutput","lessThanOrEqualTo","orDie"],"sources":["../../src/internal.ts"],"sourcesContent":[null],"mappings":";;;;;;AAIA,IAAAA,KAAA,gBAAAC,uBAAA,eAAAC,OAAA;AACA,IAAAC,QAAA,gBAAAF,uBAAA,eAAAC,OAAA;AACA,IAAAE,MAAA,gBAAAH,uBAAA,eAAAC,OAAA;AACA,IAAAG,KAAA,gBAAAJ,uBAAA,eAAAC,OAAA;AACA,IAAAI,IAAA,gBAAAL,uBAAA,eAAAC,OAAA;AACA,IAAAK,SAAA,gBAAAL,OAAA;AACA,IAAAM,KAAA,gBAAAP,uBAAA,eAAAC,OAAA;AACA,IAAAO,MAAA,gBAAAR,uBAAA,eAAAC,OAAA;AACA,IAAAQ,QAAA,gBAAAT,uBAAA,eAAAC,OAAA;AAEA,IAAAS,eAAA,gBAAAV,uBAAA,eAAAC,OAAA;AAEA,IAAAU,KAAA,gBAAAX,uBAAA,eAAAC,OAAA;AACA,IAAAW,CAAA,gBAAAZ,uBAAA,eAAAC,OAAA;AAA2B,SAAAY,yBAAAC,CAAA;EAAA,yBAAAC,OAAA;EAAA,IAAAC,CAAA,OAAAD,OAAA;IAAAE,CAAA,OAAAF,OAAA;EAAA,QAAAF,wBAAA,YAAAA,CAAAC,CAAA;IAAA,OAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA;EAAA,GAAAF,CAAA;AAAA;AAAA,SAAAd,wBAAAc,CAAA,EAAAE,CAAA;EAAA,KAAAA,CAAA,IA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AAA3D,SAAA,CAAA0E,IAAI,EAAC7E,MAAM,CAAC4E,MAAM,eAAE5E,MAAM,CAAC8C,OAAO,CAACF,OAAO,CAAC,CAAC,CAAC;AAEvH;AACO,MAAMkC,IAAI,GAAAjB,OAAA,CAAAiB,IAAA,gBAAGhB,UAAU,CAAQ3D,SAAA,CAAA4E,QAAQ,CAAC;AAE/C;AACO,MAAMC,UAAU,GAAAnB,OAAA,CAAAmB,UAAA,gBAAGlB,UAAU,CAAc9D,MAAM,CAAC4E,MAAM,CAAC;AAEhE;AACO,MAAMK,SAAS,GAAGA,CACvBhB,IAA4B,EAC5BI,OAAA,GAAkCtE,QAAQ,CAACmF,OAAO,CAAC,EAAE,CAAC,KAEtD,IAAA/E,SAAA,CAAAqC,IAAI,EACFxC,MAAM,CAACmF,cAAc,CAAClB,IAAI,EAAEjE,MAAM,CAACoF,IAAI,CAAC,EACxCpF,MAAM,CAACqF,KAAK,CACV,IAAAlF,SAAA,CAAAqC,IAAI,EACFlC,QAAQ,CAACgF,MAAM,CAAC,EAAE,CAAC,EACnBhF,QAAQ,CAACiF,OAAO,CAACjF,QAAQ,CAACkF,OAAO,CAAC,EAClClF,QAAQ,CAACmF,WAAW,CAAC1F,QAAQ,CAAC2F,iBAAiB,CAACrB,OAAO,CAAC,CAAC,CAC1D,CACF,EACDrE,MAAM,CAAC2F,KAAK,CACb;AAAA9B,OAAA,CAAAoB,SAAA,GAAAA,SAAA","ignoreList":[]}
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -1,13 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import type * as Duration from "effect/Duration";
|
|
5
|
+
import type * as Effect from "effect/Effect";
|
|
3
6
|
import type * as Scope from "effect/Scope";
|
|
4
7
|
import type * as TestServices from "effect/TestServices";
|
|
5
|
-
import type { TestAPI } from "vitest";
|
|
6
8
|
import * as V from "vitest";
|
|
7
9
|
/**
|
|
8
10
|
* @since 1.0.0
|
|
9
11
|
*/
|
|
10
|
-
export type API = TestAPI<{}>;
|
|
12
|
+
export type API = V.TestAPI<{}>;
|
|
13
|
+
/**
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
*/
|
|
16
|
+
export declare namespace Vitest {
|
|
17
|
+
/**
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
*/
|
|
20
|
+
interface TestFunction<A, E, R, TestArgs extends Array<any>> {
|
|
21
|
+
(...args: TestArgs): Effect.Effect<A, E, R>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @since 1.0.0
|
|
25
|
+
*/
|
|
26
|
+
interface Test<R> {
|
|
27
|
+
<A, E>(name: string, self: TestFunction<A, E, R, [V.TaskContext<V.Test<{}>> & V.TestContext]>, timeout?: number | V.TestOptions): void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @since 1.0.0
|
|
31
|
+
*/
|
|
32
|
+
interface Tester<R> extends Vitest.Test<R> {
|
|
33
|
+
skip: Vitest.Test<R>;
|
|
34
|
+
only: Vitest.Test<R>;
|
|
35
|
+
each: <T>(cases: ReadonlyArray<T>) => <A, E>(name: string, self: TestFunction<A, E, R, Array<T>>, timeout?: number | V.TestOptions) => void;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
11
38
|
/**
|
|
12
39
|
* @since 1.0.0
|
|
13
40
|
*/
|
|
@@ -15,35 +42,30 @@ export declare const addEqualityTesters: () => void;
|
|
|
15
42
|
/**
|
|
16
43
|
* @since 1.0.0
|
|
17
44
|
*/
|
|
18
|
-
export declare const effect:
|
|
19
|
-
skip: <E, A>(name: string, self: (ctx: V.TaskContext<V.Test<{}>> & V.TestContext) => Effect.Effect<A, E, TestServices.TestServices>, timeout?: number) => void;
|
|
20
|
-
only: <E, A>(name: string, self: (ctx: V.TaskContext<V.Test<{}>> & V.TestContext) => Effect.Effect<A, E, TestServices.TestServices>, timeout?: number) => void;
|
|
21
|
-
};
|
|
45
|
+
export declare const effect: Vitest.Tester<TestServices.TestServices>;
|
|
22
46
|
/**
|
|
23
47
|
* @since 1.0.0
|
|
24
48
|
*/
|
|
25
|
-
export declare const
|
|
49
|
+
export declare const scoped: Vitest.Tester<TestServices.TestServices | Scope.Scope>;
|
|
26
50
|
/**
|
|
27
51
|
* @since 1.0.0
|
|
28
52
|
*/
|
|
29
|
-
export declare const
|
|
53
|
+
export declare const live: Vitest.Tester<never>;
|
|
30
54
|
/**
|
|
31
55
|
* @since 1.0.0
|
|
32
56
|
*/
|
|
33
|
-
export declare const
|
|
57
|
+
export declare const scopedLive: Vitest.Tester<Scope.Scope>;
|
|
34
58
|
/**
|
|
35
59
|
* @since 1.0.0
|
|
36
60
|
*/
|
|
37
|
-
export declare const
|
|
61
|
+
export declare const flakyTest: <A, E, R>(self: Effect.Effect<A, E, R>, timeout?: Duration.DurationInput) => Effect.Effect<A, never, R>;
|
|
62
|
+
/** @ignored */
|
|
38
63
|
declare const methods: {
|
|
39
|
-
readonly effect:
|
|
40
|
-
|
|
41
|
-
only: <E, A>(name: string, self: (ctx: V.TaskContext<V.Test<{}>> & V.TestContext) => Effect.Effect<A, E, TestServices.TestServices>, timeout?: number) => void;
|
|
42
|
-
};
|
|
43
|
-
readonly live: <E, A>(name: string, self: (ctx: V.TaskContext<V.Test<{}>> & V.TestContext) => Effect.Effect<A, E>, timeout?: number) => void;
|
|
64
|
+
readonly effect: Vitest.Tester<TestServices.TestServices>;
|
|
65
|
+
readonly live: Vitest.Tester<never>;
|
|
44
66
|
readonly flakyTest: <A, E, R>(self: Effect.Effect<A, E, R>, timeout?: Duration.DurationInput) => Effect.Effect<A, never, R>;
|
|
45
|
-
readonly scoped:
|
|
46
|
-
readonly scopedLive:
|
|
67
|
+
readonly scoped: Vitest.Tester<TestServices.TestServices | Scope.Scope>;
|
|
68
|
+
readonly scopedLive: Vitest.Tester<Scope.Scope>;
|
|
47
69
|
};
|
|
48
70
|
/**
|
|
49
71
|
* @since 1.0.0
|
package/dist/dts/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,KAAK,YAAY,MAAM,qBAAqB,CAAA;AACxD,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAA;AAG3B;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;AAE/B;;GAEG;AACH,yBAAiB,MAAM,CAAC;IACtB;;OAEG;IACH,UAAiB,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,SAAS,KAAK,CAAC,GAAG,CAAC;QAChE,CAAC,GAAG,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;KAC5C;IAED;;OAEG;IACH,UAAiB,IAAI,CAAC,CAAC;QACrB,CAAC,CAAC,EAAE,CAAC,EACH,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,EACxE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,WAAW,GAC/B,IAAI,CAAA;KACR;IAED;;OAEG;IACH,UAAiB,MAAM,CAAC,CAAC,CAAE,SAAQ,MAAM,CAAC,IAAI,CA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Y,CAAC,EAAE,CAAC,EAAE,CAAC,QACxB,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,YAClB,QAAQ,CAAC,aAAa,KAC7B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;;;CAGyC,CAAA;AAExE;;GAEG;AACH,eAAO,MAAM,EAAE,EAAE,GAAG,GAAG,OAAO,OAAsC,CAAA;AAEpE;;GAEG;AACH,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":""}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,69 +1,30 @@
|
|
|
1
|
-
import * as Cause from "effect/Cause";
|
|
2
|
-
import * as Duration from "effect/Duration";
|
|
3
|
-
import * as Effect from "effect/Effect";
|
|
4
|
-
import * as Equal from "effect/Equal";
|
|
5
|
-
import * as Exit from "effect/Exit";
|
|
6
|
-
import { pipe } from "effect/Function";
|
|
7
|
-
import * as Layer from "effect/Layer";
|
|
8
|
-
import * as Logger from "effect/Logger";
|
|
9
|
-
import * as Schedule from "effect/Schedule";
|
|
10
|
-
import * as TestEnvironment from "effect/TestContext";
|
|
11
|
-
import * as Utils from "effect/Utils";
|
|
12
1
|
import * as V from "vitest";
|
|
13
|
-
|
|
14
|
-
const exit = yield* Effect.exit(effect);
|
|
15
|
-
if (Exit.isSuccess(exit)) {
|
|
16
|
-
return () => {};
|
|
17
|
-
} else {
|
|
18
|
-
const errors = Cause.prettyErrors(exit.cause);
|
|
19
|
-
for (let i = 1; i < errors.length; i++) {
|
|
20
|
-
yield* Effect.logError(errors[i]);
|
|
21
|
-
}
|
|
22
|
-
return () => {
|
|
23
|
-
throw errors[0];
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}).pipe(Effect.runPromise).then(f => f());
|
|
27
|
-
const TestEnv = /*#__PURE__*/TestEnvironment.TestContext.pipe( /*#__PURE__*/Layer.provide( /*#__PURE__*/Logger.remove(Logger.defaultLogger)));
|
|
28
|
-
/** @internal */
|
|
29
|
-
function customTester(a, b, customTesters) {
|
|
30
|
-
if (!Equal.isEqual(a) || !Equal.isEqual(b)) {
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
return Utils.structuralRegion(() => Equal.equals(a, b), (x, y) => this.equals(x, y, customTesters.filter(t => t !== customTester)));
|
|
34
|
-
}
|
|
2
|
+
import * as internal from "./internal.js";
|
|
35
3
|
/**
|
|
36
4
|
* @since 1.0.0
|
|
37
5
|
*/
|
|
38
|
-
export const addEqualityTesters =
|
|
39
|
-
V.expect.addEqualityTesters([customTester]);
|
|
40
|
-
};
|
|
6
|
+
export const addEqualityTesters = internal.addEqualityTesters;
|
|
41
7
|
/**
|
|
42
8
|
* @since 1.0.0
|
|
43
9
|
*/
|
|
44
|
-
export const effect =
|
|
45
|
-
const f = (name, self, timeout = 5_000) => it(name, c => pipe(Effect.suspend(() => self(c)), Effect.provide(TestEnv), runTest), timeout);
|
|
46
|
-
return Object.assign(f, {
|
|
47
|
-
skip: (name, self, timeout = 5_000) => it.skip(name, c => pipe(Effect.suspend(() => self(c)), Effect.provide(TestEnv), runTest), timeout),
|
|
48
|
-
only: (name, self, timeout = 5_000) => it.only(name, c => pipe(Effect.suspend(() => self(c)), Effect.provide(TestEnv), runTest), timeout)
|
|
49
|
-
});
|
|
50
|
-
})();
|
|
10
|
+
export const effect = internal.effect;
|
|
51
11
|
/**
|
|
52
12
|
* @since 1.0.0
|
|
53
13
|
*/
|
|
54
|
-
export const
|
|
14
|
+
export const scoped = internal.scoped;
|
|
55
15
|
/**
|
|
56
16
|
* @since 1.0.0
|
|
57
17
|
*/
|
|
58
|
-
export const
|
|
18
|
+
export const live = internal.live;
|
|
59
19
|
/**
|
|
60
20
|
* @since 1.0.0
|
|
61
21
|
*/
|
|
62
|
-
export const
|
|
22
|
+
export const scopedLive = internal.scopedLive;
|
|
63
23
|
/**
|
|
64
24
|
* @since 1.0.0
|
|
65
25
|
*/
|
|
66
|
-
export const
|
|
26
|
+
export const flakyTest = internal.flakyTest;
|
|
27
|
+
/** @ignored */
|
|
67
28
|
const methods = {
|
|
68
29
|
effect,
|
|
69
30
|
live,
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["V","internal","addEqualityTesters","effect","scoped","live","scopedLive","flakyTest","methods","it","Object","assign"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAOA,OAAO,KAAKA,CAAC,MAAM,QAAQ;AAC3B,OAAO,KAAKC,QAAQ,MAAM,eAAe;AAwCzC;;;AAGA,OAAO,MAAMC,kBAAkB,GAAeD,QAAQ,CAACC,kBAAkB;AAEzE;;;AAGA,OAAO,MAAMC,MAAM,GAA6CF,QAAQ,CAACE,MAAM;AAE/E;;;AAGA,OAAO,MAAMC,MAAM,GAA2DH,QAAQ,CAACG,MAAM;AAE7F;;;AAGA,OAAO,MAAMC,IAAI,GAAyBJ,QAAQ,CAACI,IAAI;AAEvD;;;AAGA,OAAO,MAAMC,UAAU,GAA+BL,QAAQ,CAACK,UAAU;AAEzE;;;AAGA,OAAO,MAAMC,SAAS,GAGYN,QAAQ,CAACM,SAAS;AAEpD;AACA,MAAMC,OAAO,GAAG;EAAEL,MAAM;EAAEE,IAAI;EAAEE,SAAS;EAAEH,MAAM;EAAEE;AAAU,CAAW;AAExE;;;AAGA,OAAO,MAAMG,EAAE,gBAAyBC,MAAM,CAACC,MAAM,CAACX,CAAC,CAACS,EAAE,EAAED,OAAO,CAAC;AAEpE;;;AAGA,cAAc,QAAQ","ignoreList":[]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as Cause from "effect/Cause";
|
|
2
|
+
import * as Duration from "effect/Duration";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Equal from "effect/Equal";
|
|
5
|
+
import * as Exit from "effect/Exit";
|
|
6
|
+
import { flow, identity, pipe } from "effect/Function";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
import * as Logger from "effect/Logger";
|
|
9
|
+
import * as Schedule from "effect/Schedule";
|
|
10
|
+
import * as TestEnvironment from "effect/TestContext";
|
|
11
|
+
import * as Utils from "effect/Utils";
|
|
12
|
+
import * as V from "vitest";
|
|
13
|
+
/** @internal */
|
|
14
|
+
const runTest = effect => Effect.gen(function* () {
|
|
15
|
+
const exit = yield* Effect.exit(effect);
|
|
16
|
+
if (Exit.isSuccess(exit)) {
|
|
17
|
+
return () => {};
|
|
18
|
+
} else {
|
|
19
|
+
const errors = Cause.prettyErrors(exit.cause);
|
|
20
|
+
for (let i = 1; i < errors.length; i++) {
|
|
21
|
+
yield* Effect.logError(errors[i]);
|
|
22
|
+
}
|
|
23
|
+
return () => {
|
|
24
|
+
throw errors[0];
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}).pipe(Effect.runPromise).then(f => f());
|
|
28
|
+
/** @internal */
|
|
29
|
+
const TestEnv = /*#__PURE__*/TestEnvironment.TestContext.pipe( /*#__PURE__*/Layer.provide( /*#__PURE__*/Logger.remove(Logger.defaultLogger)));
|
|
30
|
+
/** @internal */
|
|
31
|
+
function customTester(a, b, customTesters) {
|
|
32
|
+
if (!Equal.isEqual(a) || !Equal.isEqual(b)) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return Utils.structuralRegion(() => Equal.equals(a, b), (x, y) => this.equals(x, y, customTesters.filter(t => t !== customTester)));
|
|
36
|
+
}
|
|
37
|
+
/** @internal */
|
|
38
|
+
export const addEqualityTesters = () => {
|
|
39
|
+
V.expect.addEqualityTesters([customTester]);
|
|
40
|
+
};
|
|
41
|
+
/** @internal */
|
|
42
|
+
const makeTester = mapEffect => {
|
|
43
|
+
const run = self => (...args) => pipe(Effect.suspend(() => self(...args)), mapEffect, runTest);
|
|
44
|
+
const f = (name, self, timeout) => V.it(name, run(self), timeout);
|
|
45
|
+
const skip = (name, self, timeout) => V.it.skip(name, run(self), timeout);
|
|
46
|
+
const only = (name, self, timeout) => V.it.only(name, run(self), timeout);
|
|
47
|
+
const each = cases => (name, self, timeout) => V.it.each(cases)(name, run(self), timeout);
|
|
48
|
+
return Object.assign(f, {
|
|
49
|
+
skip,
|
|
50
|
+
only,
|
|
51
|
+
each
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
/** @internal */
|
|
55
|
+
export const effect = /*#__PURE__*/makeTester( /*#__PURE__*/Effect.provide(TestEnv));
|
|
56
|
+
/** @internal */
|
|
57
|
+
export const scoped = /*#__PURE__*/makeTester( /*#__PURE__*/flow(Effect.scoped, /*#__PURE__*/Effect.provide(TestEnv)));
|
|
58
|
+
/** @internal */
|
|
59
|
+
export const live = /*#__PURE__*/makeTester(identity);
|
|
60
|
+
/** @internal */
|
|
61
|
+
export const scopedLive = /*#__PURE__*/makeTester(Effect.scoped);
|
|
62
|
+
/** @internal */
|
|
63
|
+
export const flakyTest = (self, timeout = Duration.seconds(30)) => pipe(Effect.catchAllDefect(self, Effect.fail), Effect.retry(pipe(Schedule.recurs(10), Schedule.compose(Schedule.elapsed), Schedule.whileOutput(Duration.lessThanOrEqualTo(timeout)))), Effect.orDie);
|
|
64
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","names":["Cause","Duration","Effect","Equal","Exit","flow","identity","pipe","Layer","Logger","Schedule","TestEnvironment","Utils","V","runTest","effect","gen","exit","isSuccess","errors","prettyErrors","cause","i","length","logError","runPromise","then","f","TestEnv","TestContext","provide","remove","defaultLogger","customTester","a","b","customTesters","isEqual","undefined","structuralRegion","equals","x","y","filter","t","addEqualityTesters","expect","makeTester","mapEffect","run","self","args","suspend","name","timeout","it","skip","only","each","cases","Object","assign","scoped","live","scopedLive","flakyTest","seconds","catchAllDefect","fail","retry","recurs","compose","elapsed","whileOutput","lessThanOrEqualTo","orDie"],"sources":["../../src/internal.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,SAASC,IAAI,EAAEC,QAAQ,EAAEC,IAAI,QAAQ,iBAAiB;AACtD,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAE3C,OAAO,KAAKC,eAAe,MAAM,oBAAoB;AAErD,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,CAAC,MAAM,QAAQ;AAG3B;AACA,MAAMC,OAAO,GAAUC,MAA2B,IAChDb,MAAM,CAACc,GAAG,CAAC,aAAS;EAClB,MAAMC,IAAI,GAAoB,OAAOf,MAAM,CAACe,IAAI,CAACF,MAAM,CAAC;EACxD,IAAIX,IAAI,CAACc,SAAS,CAACD,IAAI,CAAC,EAAE;IACxB,OAAO,MAAK,CAAE,CAAC;EACjB,CAAC,MAAM;IACL,MAAME,MAAM,GAAGnB,KAAK,CAACoB,YAAY,CAACH,IAAI,CAACI,KAAK,CAAC;IAC7C,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,MAAM,CAACI,MAAM,EAAED,CAAC,EAAE,EAAE;MACtC,OAAOpB,MAAM,CAACsB,QAAQ,CAACL,MAAM,CAACG,CAAC,CAAC,CAAC;IACnC;IACA,OAAO,MAAK;MACV,MAAMH,MAAM,CAAC,CAAC,CAAC;IACjB,CAAC;EACH;AACF,CAAC,CAAC,CAACZ,IAAI,CAACL,MAAM,CAACuB,UAAU,CAAC,CAACC,IAAI,CAAEC,CAAC,IAA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ACxClE,MAAM,CAACmE,KAAK,CACV9D,IAAI,CACFG,QAAQ,CAAC4D,MAAM,CAAC,EAAE,CAAC,EACnB5D,QAAQ,CAAC6D,OAAO,CAAC7D,QAAQ,CAAC8D,OAAO,CAAC,EAClC9D,QAAQ,CAAC+D,WAAW,CAACxE,QAAQ,CAACyE,iBAAiB,CAACpB,OAAO,CAAC,CAAC,CAC1D,CACF,EACDpD,MAAM,CAACyE,KAAK,CACb","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/vitest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A set of helpers for testing Effects with vitest",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"sideEffects": [],
|
|
12
12
|
"peerDependencies": {
|
|
13
13
|
"vitest": "^1.4.0",
|
|
14
|
-
"effect": "^3.4.
|
|
14
|
+
"effect": "^3.4.6"
|
|
15
15
|
},
|
|
16
16
|
"publishConfig": {
|
|
17
17
|
"provenance": true
|
|
@@ -25,6 +25,18 @@
|
|
|
25
25
|
"types": "./dist/dts/index.d.ts",
|
|
26
26
|
"import": "./dist/esm/index.js",
|
|
27
27
|
"default": "./dist/cjs/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./internal": {
|
|
30
|
+
"types": "./dist/dts/internal.d.ts",
|
|
31
|
+
"import": "./dist/esm/internal.js",
|
|
32
|
+
"default": "./dist/cjs/internal.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"typesVersions": {
|
|
36
|
+
"*": {
|
|
37
|
+
"internal": [
|
|
38
|
+
"./dist/dts/internal.d.ts"
|
|
39
|
+
]
|
|
28
40
|
}
|
|
29
41
|
}
|
|
30
42
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,206 +1,91 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import type
|
|
5
|
-
import * as
|
|
6
|
-
import * as Duration from "effect/Duration"
|
|
7
|
-
import * as Effect from "effect/Effect"
|
|
8
|
-
import * as Equal from "effect/Equal"
|
|
9
|
-
import * as Exit from "effect/Exit"
|
|
10
|
-
import { pipe } from "effect/Function"
|
|
11
|
-
import * as Layer from "effect/Layer"
|
|
12
|
-
import * as Logger from "effect/Logger"
|
|
13
|
-
import * as Schedule from "effect/Schedule"
|
|
4
|
+
import type * as Duration from "effect/Duration"
|
|
5
|
+
import type * as Effect from "effect/Effect"
|
|
14
6
|
import type * as Scope from "effect/Scope"
|
|
15
|
-
import * as TestEnvironment from "effect/TestContext"
|
|
16
7
|
import type * as TestServices from "effect/TestServices"
|
|
17
|
-
import * as Utils from "effect/Utils"
|
|
18
|
-
import type { TestAPI } from "vitest"
|
|
19
8
|
import * as V from "vitest"
|
|
9
|
+
import * as internal from "./internal.js"
|
|
20
10
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return () => {}
|
|
26
|
-
} else {
|
|
27
|
-
const errors = Cause.prettyErrors(exit.cause)
|
|
28
|
-
for (let i = 1; i < errors.length; i++) {
|
|
29
|
-
yield* Effect.logError(errors[i])
|
|
30
|
-
}
|
|
31
|
-
return () => {
|
|
32
|
-
throw errors[0]
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}).pipe(Effect.runPromise).then((f) => f())
|
|
11
|
+
/**
|
|
12
|
+
* @since 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
export type API = V.TestAPI<{}>
|
|
36
15
|
|
|
37
16
|
/**
|
|
38
17
|
* @since 1.0.0
|
|
39
18
|
*/
|
|
40
|
-
export
|
|
19
|
+
export namespace Vitest {
|
|
20
|
+
/**
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
*/
|
|
23
|
+
export interface TestFunction<A, E, R, TestArgs extends Array<any>> {
|
|
24
|
+
(...args: TestArgs): Effect.Effect<A, E, R>
|
|
25
|
+
}
|
|
41
26
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*/
|
|
30
|
+
export interface Test<R> {
|
|
31
|
+
<A, E>(
|
|
32
|
+
name: string,
|
|
33
|
+
self: TestFunction<A, E, R, [V.TaskContext<V.Test<{}>> & V.TestContext]>,
|
|
34
|
+
timeout?: number | V.TestOptions
|
|
35
|
+
): void
|
|
36
|
+
}
|
|
45
37
|
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
/**
|
|
39
|
+
* @since 1.0.0
|
|
40
|
+
*/
|
|
41
|
+
export interface Tester<R> extends Vitest.Test<R> {
|
|
42
|
+
skip: Vitest.Test<R>
|
|
43
|
+
only: Vitest.Test<R>
|
|
44
|
+
each: <T>(
|
|
45
|
+
cases: ReadonlyArray<T>
|
|
46
|
+
) => <A, E>(name: string, self: TestFunction<A, E, R, Array<T>>, timeout?: number | V.TestOptions) => void
|
|
50
47
|
}
|
|
51
|
-
return Utils.structuralRegion(
|
|
52
|
-
() => Equal.equals(a, b),
|
|
53
|
-
(x, y) => this.equals(x, y, customTesters.filter((t) => t !== customTester))
|
|
54
|
-
)
|
|
55
48
|
}
|
|
56
|
-
|
|
57
49
|
/**
|
|
58
50
|
* @since 1.0.0
|
|
59
51
|
*/
|
|
60
|
-
export const addEqualityTesters
|
|
61
|
-
V.expect.addEqualityTesters([customTester])
|
|
62
|
-
}
|
|
52
|
+
export const addEqualityTesters: () => void = internal.addEqualityTesters
|
|
63
53
|
|
|
64
54
|
/**
|
|
65
55
|
* @since 1.0.0
|
|
66
56
|
*/
|
|
67
|
-
export const effect =
|
|
68
|
-
const f = <E, A>(
|
|
69
|
-
name: string,
|
|
70
|
-
self: (ctx: V.TaskContext<V.Test<{}>> & V.TestContext) => Effect.Effect<A, E, TestServices.TestServices>,
|
|
71
|
-
timeout: number | V.TestOptions = 5_000
|
|
72
|
-
) =>
|
|
73
|
-
it(
|
|
74
|
-
name,
|
|
75
|
-
(c) =>
|
|
76
|
-
pipe(
|
|
77
|
-
Effect.suspend(() => self(c)),
|
|
78
|
-
Effect.provide(TestEnv),
|
|
79
|
-
runTest
|
|
80
|
-
),
|
|
81
|
-
timeout
|
|
82
|
-
)
|
|
83
|
-
return Object.assign(f, {
|
|
84
|
-
skip: <E, A>(
|
|
85
|
-
name: string,
|
|
86
|
-
self: (ctx: V.TaskContext<V.Test<{}>> & V.TestContext) => Effect.Effect<A, E, TestServices.TestServices>,
|
|
87
|
-
timeout = 5_000
|
|
88
|
-
) =>
|
|
89
|
-
it.skip(
|
|
90
|
-
name,
|
|
91
|
-
(c) =>
|
|
92
|
-
pipe(
|
|
93
|
-
Effect.suspend(() => self(c)),
|
|
94
|
-
Effect.provide(TestEnv),
|
|
95
|
-
runTest
|
|
96
|
-
),
|
|
97
|
-
timeout
|
|
98
|
-
),
|
|
99
|
-
only: <E, A>(
|
|
100
|
-
name: string,
|
|
101
|
-
self: (ctx: V.TaskContext<V.Test<{}>> & V.TestContext) => Effect.Effect<A, E, TestServices.TestServices>,
|
|
102
|
-
timeout = 5_000
|
|
103
|
-
) =>
|
|
104
|
-
it.only(
|
|
105
|
-
name,
|
|
106
|
-
(c) =>
|
|
107
|
-
pipe(
|
|
108
|
-
Effect.suspend(() => self(c)),
|
|
109
|
-
Effect.provide(TestEnv),
|
|
110
|
-
runTest
|
|
111
|
-
),
|
|
112
|
-
timeout
|
|
113
|
-
)
|
|
114
|
-
})
|
|
115
|
-
})()
|
|
57
|
+
export const effect: Vitest.Tester<TestServices.TestServices> = internal.effect
|
|
116
58
|
|
|
117
59
|
/**
|
|
118
60
|
* @since 1.0.0
|
|
119
61
|
*/
|
|
120
|
-
export const
|
|
121
|
-
name: string,
|
|
122
|
-
self: (ctx: V.TaskContext<V.Test<{}>> & V.TestContext) => Effect.Effect<A, E>,
|
|
123
|
-
timeout = 5_000
|
|
124
|
-
) =>
|
|
125
|
-
it(
|
|
126
|
-
name,
|
|
127
|
-
(c) =>
|
|
128
|
-
pipe(
|
|
129
|
-
Effect.suspend(() => self(c)),
|
|
130
|
-
runTest
|
|
131
|
-
),
|
|
132
|
-
timeout
|
|
133
|
-
)
|
|
62
|
+
export const scoped: Vitest.Tester<TestServices.TestServices | Scope.Scope> = internal.scoped
|
|
134
63
|
|
|
135
64
|
/**
|
|
136
65
|
* @since 1.0.0
|
|
137
66
|
*/
|
|
138
|
-
export const
|
|
139
|
-
self: Effect.Effect<A, E, R>,
|
|
140
|
-
timeout: Duration.DurationInput = Duration.seconds(30)
|
|
141
|
-
) =>
|
|
142
|
-
pipe(
|
|
143
|
-
Effect.catchAllDefect(self, Effect.fail),
|
|
144
|
-
Effect.retry(
|
|
145
|
-
pipe(
|
|
146
|
-
Schedule.recurs(10),
|
|
147
|
-
Schedule.compose(Schedule.elapsed),
|
|
148
|
-
Schedule.whileOutput(Duration.lessThanOrEqualTo(timeout))
|
|
149
|
-
)
|
|
150
|
-
),
|
|
151
|
-
Effect.orDie
|
|
152
|
-
)
|
|
67
|
+
export const live: Vitest.Tester<never> = internal.live
|
|
153
68
|
|
|
154
69
|
/**
|
|
155
70
|
* @since 1.0.0
|
|
156
71
|
*/
|
|
157
|
-
export const
|
|
158
|
-
name: string,
|
|
159
|
-
self: (
|
|
160
|
-
ctx: V.TaskContext<V.Test<{}>> & V.TestContext
|
|
161
|
-
) => Effect.Effect<A, E, Scope.Scope | TestServices.TestServices>,
|
|
162
|
-
timeout = 5_000
|
|
163
|
-
) =>
|
|
164
|
-
it(
|
|
165
|
-
name,
|
|
166
|
-
(c) =>
|
|
167
|
-
pipe(
|
|
168
|
-
Effect.suspend(() => self(c)),
|
|
169
|
-
Effect.scoped,
|
|
170
|
-
Effect.provide(TestEnv),
|
|
171
|
-
runTest
|
|
172
|
-
),
|
|
173
|
-
timeout
|
|
174
|
-
)
|
|
72
|
+
export const scopedLive: Vitest.Tester<Scope.Scope> = internal.scopedLive
|
|
175
73
|
|
|
176
74
|
/**
|
|
177
75
|
* @since 1.0.0
|
|
178
76
|
*/
|
|
179
|
-
export const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
) =>
|
|
184
|
-
it(
|
|
185
|
-
name,
|
|
186
|
-
(c) =>
|
|
187
|
-
pipe(
|
|
188
|
-
Effect.suspend(() => self(c)),
|
|
189
|
-
Effect.scoped,
|
|
190
|
-
runTest
|
|
191
|
-
),
|
|
192
|
-
timeout
|
|
193
|
-
)
|
|
77
|
+
export const flakyTest: <A, E, R>(
|
|
78
|
+
self: Effect.Effect<A, E, R>,
|
|
79
|
+
timeout?: Duration.DurationInput
|
|
80
|
+
) => Effect.Effect<A, never, R> = internal.flakyTest
|
|
194
81
|
|
|
82
|
+
/** @ignored */
|
|
195
83
|
const methods = { effect, live, flakyTest, scoped, scopedLive } as const
|
|
196
84
|
|
|
197
85
|
/**
|
|
198
86
|
* @since 1.0.0
|
|
199
87
|
*/
|
|
200
|
-
export const it: API & typeof methods = Object.assign(
|
|
201
|
-
V.it,
|
|
202
|
-
methods
|
|
203
|
-
)
|
|
88
|
+
export const it: API & typeof methods = Object.assign(V.it, methods)
|
|
204
89
|
|
|
205
90
|
/**
|
|
206
91
|
* @since 1.0.0
|
package/src/internal.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import type { Tester, TesterContext } from "@vitest/expect"
|
|
5
|
+
import * as Cause from "effect/Cause"
|
|
6
|
+
import * as Duration from "effect/Duration"
|
|
7
|
+
import * as Effect from "effect/Effect"
|
|
8
|
+
import * as Equal from "effect/Equal"
|
|
9
|
+
import * as Exit from "effect/Exit"
|
|
10
|
+
import { flow, identity, pipe } from "effect/Function"
|
|
11
|
+
import * as Layer from "effect/Layer"
|
|
12
|
+
import * as Logger from "effect/Logger"
|
|
13
|
+
import * as Schedule from "effect/Schedule"
|
|
14
|
+
import type * as Scope from "effect/Scope"
|
|
15
|
+
import * as TestEnvironment from "effect/TestContext"
|
|
16
|
+
import type * as TestServices from "effect/TestServices"
|
|
17
|
+
import * as Utils from "effect/Utils"
|
|
18
|
+
import * as V from "vitest"
|
|
19
|
+
import type * as Vitest from "./index.js"
|
|
20
|
+
|
|
21
|
+
/** @internal */
|
|
22
|
+
const runTest = <E, A>(effect: Effect.Effect<A, E>) =>
|
|
23
|
+
Effect.gen(function*() {
|
|
24
|
+
const exit: Exit.Exit<A, E> = yield* Effect.exit(effect)
|
|
25
|
+
if (Exit.isSuccess(exit)) {
|
|
26
|
+
return () => {}
|
|
27
|
+
} else {
|
|
28
|
+
const errors = Cause.prettyErrors(exit.cause)
|
|
29
|
+
for (let i = 1; i < errors.length; i++) {
|
|
30
|
+
yield* Effect.logError(errors[i])
|
|
31
|
+
}
|
|
32
|
+
return () => {
|
|
33
|
+
throw errors[0]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}).pipe(Effect.runPromise).then((f) => f())
|
|
37
|
+
|
|
38
|
+
/** @internal */
|
|
39
|
+
const TestEnv = TestEnvironment.TestContext.pipe(
|
|
40
|
+
Layer.provide(Logger.remove(Logger.defaultLogger))
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
/** @internal */
|
|
44
|
+
function customTester(this: TesterContext, a: unknown, b: unknown, customTesters: Array<Tester>) {
|
|
45
|
+
if (!Equal.isEqual(a) || !Equal.isEqual(b)) {
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
48
|
+
return Utils.structuralRegion(
|
|
49
|
+
() => Equal.equals(a, b),
|
|
50
|
+
(x, y) => this.equals(x, y, customTesters.filter((t) => t !== customTester))
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @internal */
|
|
55
|
+
export const addEqualityTesters = () => {
|
|
56
|
+
V.expect.addEqualityTesters([customTester])
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @internal */
|
|
60
|
+
const makeTester = <R>(
|
|
61
|
+
mapEffect: <A, E>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, never>
|
|
62
|
+
): Vitest.Vitest.Tester<R> => {
|
|
63
|
+
const run =
|
|
64
|
+
<A, E, TestArgs extends Array<any>>(self: Vitest.Vitest.TestFunction<A, E, R, TestArgs>) => (...args: TestArgs) =>
|
|
65
|
+
pipe(Effect.suspend(() => self(...args)), mapEffect, runTest)
|
|
66
|
+
|
|
67
|
+
const f: Vitest.Vitest.Test<R> = (name, self, timeout) => V.it(name, run(self), timeout)
|
|
68
|
+
|
|
69
|
+
const skip: Vitest.Vitest.Tester<R>["only"] = (name, self, timeout) => V.it.skip(name, run(self), timeout)
|
|
70
|
+
const only: Vitest.Vitest.Tester<R>["only"] = (name, self, timeout) => V.it.only(name, run(self), timeout)
|
|
71
|
+
const each: Vitest.Vitest.Tester<R>["each"] = (cases) => (name, self, timeout) =>
|
|
72
|
+
V.it.each(cases)(name, run(self), timeout)
|
|
73
|
+
|
|
74
|
+
return Object.assign(f, { skip, only, each })
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @internal */
|
|
78
|
+
export const effect = makeTester<TestServices.TestServices>(Effect.provide(TestEnv))
|
|
79
|
+
|
|
80
|
+
/** @internal */
|
|
81
|
+
export const scoped = makeTester<TestServices.TestServices | Scope.Scope>(flow(Effect.scoped, Effect.provide(TestEnv)))
|
|
82
|
+
|
|
83
|
+
/** @internal */
|
|
84
|
+
export const live = makeTester<never>(identity)
|
|
85
|
+
|
|
86
|
+
/** @internal */
|
|
87
|
+
export const scopedLive = makeTester<Scope.Scope>(Effect.scoped)
|
|
88
|
+
|
|
89
|
+
/** @internal */
|
|
90
|
+
export const flakyTest = <A, E, R>(
|
|
91
|
+
self: Effect.Effect<A, E, R>,
|
|
92
|
+
timeout: Duration.DurationInput = Duration.seconds(30)
|
|
93
|
+
) =>
|
|
94
|
+
pipe(
|
|
95
|
+
Effect.catchAllDefect(self, Effect.fail),
|
|
96
|
+
Effect.retry(
|
|
97
|
+
pipe(
|
|
98
|
+
Schedule.recurs(10),
|
|
99
|
+
Schedule.compose(Schedule.elapsed),
|
|
100
|
+
Schedule.whileOutput(Duration.lessThanOrEqualTo(timeout))
|
|
101
|
+
)
|
|
102
|
+
),
|
|
103
|
+
Effect.orDie
|
|
104
|
+
)
|