@effectionx/test-adapter 0.5.0 → 0.5.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/esm/box.d.ts +4 -0
- package/esm/box.d.ts.map +1 -0
- package/esm/box.js +15 -0
- package/esm/mod.d.ts +1 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +39 -32
- package/package.json +1 -1
- package/script/box.d.ts +4 -0
- package/script/box.d.ts.map +1 -0
- package/script/box.js +19 -0
- package/script/mod.d.ts +1 -1
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +38 -31
package/esm/box.d.ts
ADDED
package/esm/box.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../src/box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAEjE,wBAAiB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAMzE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAK7C"}
|
package/esm/box.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Err, Ok } from "effection";
|
|
2
|
+
export function* box(content) {
|
|
3
|
+
try {
|
|
4
|
+
return Ok(yield* content());
|
|
5
|
+
}
|
|
6
|
+
catch (error) {
|
|
7
|
+
return Err(error);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function unbox(result) {
|
|
11
|
+
if (result.ok) {
|
|
12
|
+
return result.value;
|
|
13
|
+
}
|
|
14
|
+
throw result.error;
|
|
15
|
+
}
|
package/esm/mod.d.ts
CHANGED
package/esm/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,SAAS,EACT,MAAM,EACN,KAAK,EAEN,MAAM,WAAW,CAAC;AAWnB,MAAM,WAAW,aAAa;IAC5B,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAErC;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE;QAAE,GAAG,EAAE,aAAa,EAAE,CAAC;QAAC,IAAI,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC;IAEhE;;;OAGG;IACH,QAAQ,CAAC,EAAE,EAAE,aAAa,GAAG,IAAI,CAAC;IAElC;;;OAGG;IACH,eAAe,CAAC,EAAE,EAAE,aAAa,GAAG,IAAI,CAAC;IAEzC;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAEnD;;;OAGG;IACH,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;IAExB;;;;OAIG;IACH,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AASD;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,GAAE,kBAAuB,GAC/B,WAAW,CA4Fb"}
|
package/esm/mod.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createScope, Ok, run, suspend, useScope, withResolvers, } from "effection";
|
|
2
|
+
import { box } from "./box.js";
|
|
2
3
|
const anonymousNames = (function* () {
|
|
3
4
|
let count = 1;
|
|
4
5
|
while (true) {
|
|
@@ -15,6 +16,7 @@ export function createTestAdapter(options = {}) {
|
|
|
15
16
|
};
|
|
16
17
|
const { parent, name = anonymousNames.next().value } = options;
|
|
17
18
|
let scope = undefined;
|
|
19
|
+
let destroy = function* () { };
|
|
18
20
|
const adapter = {
|
|
19
21
|
parent,
|
|
20
22
|
name,
|
|
@@ -36,47 +38,52 @@ export function createTestAdapter(options = {}) {
|
|
|
36
38
|
setup.all.push(op);
|
|
37
39
|
},
|
|
38
40
|
runTest(op) {
|
|
39
|
-
return run(
|
|
41
|
+
return run(function* () {
|
|
42
|
+
let init = yield* adapter["@@init@@"]();
|
|
43
|
+
if (!init.ok) {
|
|
44
|
+
return init;
|
|
45
|
+
}
|
|
46
|
+
let scope = init.value;
|
|
40
47
|
const setups = adapter.lineage.reduce((all, adapter) => all.concat(adapter.setup.each), []);
|
|
41
|
-
let
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
yield* setup();
|
|
48
|
+
let test = yield* scope.spawn(() => box(function* () {
|
|
49
|
+
for (let fn of setups) {
|
|
50
|
+
yield* fn();
|
|
45
51
|
}
|
|
46
52
|
yield* op();
|
|
47
|
-
});
|
|
48
|
-
yield* test;
|
|
49
|
-
}
|
|
53
|
+
}));
|
|
54
|
+
return yield* test;
|
|
55
|
+
});
|
|
50
56
|
},
|
|
51
|
-
// no-op that will be replaced once initialze
|
|
52
|
-
destroy: () => run(function* () { }),
|
|
53
57
|
*["@@init@@"]() {
|
|
54
58
|
if (scope) {
|
|
55
|
-
return scope;
|
|
59
|
+
return yield* scope.operation;
|
|
56
60
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
scope
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
scope = withResolvers();
|
|
62
|
+
let parent = adapter.parent
|
|
63
|
+
? yield* adapter.parent["@@init@@"]()
|
|
64
|
+
: Ok(createScope()[0]);
|
|
65
|
+
if (!parent.ok) {
|
|
66
|
+
scope.resolve(parent);
|
|
67
|
+
return yield* scope.operation;
|
|
68
|
+
}
|
|
69
|
+
let task = yield* parent.value.spawn(function* () {
|
|
70
|
+
let init = yield* box(function* () {
|
|
71
|
+
for (let initializer of adapter.setup.all) {
|
|
72
|
+
yield* initializer();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
if (!init.ok) {
|
|
76
|
+
scope.resolve(init);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
scope.resolve(Ok(yield* useScope()));
|
|
80
|
+
yield* suspend();
|
|
65
81
|
}
|
|
66
|
-
initialized.resolve(scope);
|
|
67
|
-
yield* suspend();
|
|
68
82
|
});
|
|
69
|
-
|
|
70
|
-
return yield*
|
|
83
|
+
destroy = task.halt;
|
|
84
|
+
return yield* scope.operation;
|
|
71
85
|
},
|
|
86
|
+
destroy: () => run(destroy),
|
|
72
87
|
};
|
|
73
88
|
return adapter;
|
|
74
89
|
}
|
|
75
|
-
function* box(op) {
|
|
76
|
-
try {
|
|
77
|
-
return Ok(yield* op);
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
return Err(error);
|
|
81
|
-
}
|
|
82
|
-
}
|
package/package.json
CHANGED
package/script/box.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../src/box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAEjE,wBAAiB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAMzE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAK7C"}
|
package/script/box.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.box = box;
|
|
4
|
+
exports.unbox = unbox;
|
|
5
|
+
const effection_1 = require("effection");
|
|
6
|
+
function* box(content) {
|
|
7
|
+
try {
|
|
8
|
+
return (0, effection_1.Ok)(yield* content());
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
return (0, effection_1.Err)(error);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function unbox(result) {
|
|
15
|
+
if (result.ok) {
|
|
16
|
+
return result.value;
|
|
17
|
+
}
|
|
18
|
+
throw result.error;
|
|
19
|
+
}
|
package/script/mod.d.ts
CHANGED
package/script/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,SAAS,EACT,MAAM,EACN,KAAK,EAEN,MAAM,WAAW,CAAC;AAWnB,MAAM,WAAW,aAAa;IAC5B,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAErC;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE;QAAE,GAAG,EAAE,aAAa,EAAE,CAAC;QAAC,IAAI,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC;IAEhE;;;OAGG;IACH,QAAQ,CAAC,EAAE,EAAE,aAAa,GAAG,IAAI,CAAC;IAElC;;;OAGG;IACH,eAAe,CAAC,EAAE,EAAE,aAAa,GAAG,IAAI,CAAC;IAEzC;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAEnD;;;OAGG;IACH,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;IAExB;;;;OAIG;IACH,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AASD;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,GAAE,kBAAuB,GAC/B,WAAW,CA4Fb"}
|
package/script/mod.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTestAdapter = createTestAdapter;
|
|
4
4
|
const effection_1 = require("effection");
|
|
5
|
+
const box_js_1 = require("./box.js");
|
|
5
6
|
const anonymousNames = (function* () {
|
|
6
7
|
let count = 1;
|
|
7
8
|
while (true) {
|
|
@@ -18,6 +19,7 @@ function createTestAdapter(options = {}) {
|
|
|
18
19
|
};
|
|
19
20
|
const { parent, name = anonymousNames.next().value } = options;
|
|
20
21
|
let scope = undefined;
|
|
22
|
+
let destroy = function* () { };
|
|
21
23
|
const adapter = {
|
|
22
24
|
parent,
|
|
23
25
|
name,
|
|
@@ -39,47 +41,52 @@ function createTestAdapter(options = {}) {
|
|
|
39
41
|
setup.all.push(op);
|
|
40
42
|
},
|
|
41
43
|
runTest(op) {
|
|
42
|
-
return (0, effection_1.run)(
|
|
44
|
+
return (0, effection_1.run)(function* () {
|
|
45
|
+
let init = yield* adapter["@@init@@"]();
|
|
46
|
+
if (!init.ok) {
|
|
47
|
+
return init;
|
|
48
|
+
}
|
|
49
|
+
let scope = init.value;
|
|
43
50
|
const setups = adapter.lineage.reduce((all, adapter) => all.concat(adapter.setup.each), []);
|
|
44
|
-
let
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
yield* setup();
|
|
51
|
+
let test = yield* scope.spawn(() => (0, box_js_1.box)(function* () {
|
|
52
|
+
for (let fn of setups) {
|
|
53
|
+
yield* fn();
|
|
48
54
|
}
|
|
49
55
|
yield* op();
|
|
50
|
-
});
|
|
51
|
-
yield* test;
|
|
52
|
-
}
|
|
56
|
+
}));
|
|
57
|
+
return yield* test;
|
|
58
|
+
});
|
|
53
59
|
},
|
|
54
|
-
// no-op that will be replaced once initialze
|
|
55
|
-
destroy: () => (0, effection_1.run)(function* () { }),
|
|
56
60
|
*["@@init@@"]() {
|
|
57
61
|
if (scope) {
|
|
58
|
-
return scope;
|
|
62
|
+
return yield* scope.operation;
|
|
59
63
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
scope
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
scope = (0, effection_1.withResolvers)();
|
|
65
|
+
let parent = adapter.parent
|
|
66
|
+
? yield* adapter.parent["@@init@@"]()
|
|
67
|
+
: (0, effection_1.Ok)((0, effection_1.createScope)()[0]);
|
|
68
|
+
if (!parent.ok) {
|
|
69
|
+
scope.resolve(parent);
|
|
70
|
+
return yield* scope.operation;
|
|
71
|
+
}
|
|
72
|
+
let task = yield* parent.value.spawn(function* () {
|
|
73
|
+
let init = yield* (0, box_js_1.box)(function* () {
|
|
74
|
+
for (let initializer of adapter.setup.all) {
|
|
75
|
+
yield* initializer();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
if (!init.ok) {
|
|
79
|
+
scope.resolve(init);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
scope.resolve((0, effection_1.Ok)(yield* (0, effection_1.useScope)()));
|
|
83
|
+
yield* (0, effection_1.suspend)();
|
|
68
84
|
}
|
|
69
|
-
initialized.resolve(scope);
|
|
70
|
-
yield* (0, effection_1.suspend)();
|
|
71
85
|
});
|
|
72
|
-
|
|
73
|
-
return yield*
|
|
86
|
+
destroy = task.halt;
|
|
87
|
+
return yield* scope.operation;
|
|
74
88
|
},
|
|
89
|
+
destroy: () => (0, effection_1.run)(destroy),
|
|
75
90
|
};
|
|
76
91
|
return adapter;
|
|
77
92
|
}
|
|
78
|
-
function* box(op) {
|
|
79
|
-
try {
|
|
80
|
-
return (0, effection_1.Ok)(yield* op);
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
return (0, effection_1.Err)(error);
|
|
84
|
-
}
|
|
85
|
-
}
|