@effectionx/test-adapter 0.1.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 ADDED
@@ -0,0 +1,38 @@
1
+ # Test Adapter
2
+
3
+ An abstract helper for integrating Effection with testing frameworks.
4
+
5
+ ---
6
+
7
+ Typically, you won't use this module directly, but instead you'll use one of the
8
+ actual testing framework integrations. The following shows how you might
9
+ integrate it with the `@std/bdd` module. You would never use it this way, this
10
+ demonstrates the general pattern of lifecycle.
11
+
12
+ ```ts
13
+ import { run, sleep } from "effection";
14
+ import { createTestAdapter, TestAdapter } from "@effectionx/test-adapter";
15
+ import { describe, it, beforeEach } from "@std/bdd";
16
+
17
+
18
+ describe("something", () => {
19
+ let adapter: TestAdapter;
20
+ beforeAll(() => {)
21
+ adapter = createTestAdapter("something");
22
+ });
23
+
24
+ afterAll(() => adapter.destroy())
25
+
26
+ adapter.addSetup(function*() {
27
+ /* do some setup. equivalent of beforeEach() */
28
+ /* contexts set here will be visible in the test */*
29
+ });
30
+
31
+ it("does a thing", async () => {
32
+ await adapter.runTest(function*() {
33
+ /* ... the body of the test */
34
+ });
35
+ });
36
+
37
+ });
38
+ ```
package/esm/mod.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ import type { Future, Operation, Scope } from "effection";
2
+ export interface TestOperation {
3
+ (): Operation<void>;
4
+ }
5
+ export interface TestAdapter {
6
+ /**
7
+ * The parent of this adapter. All of the setup from this adapter will be
8
+ * run in addition to the setup of this adapter during `runTest()`
9
+ */
10
+ readonly parent?: TestAdapter;
11
+ /**
12
+ * The name of this adapter which is mostly useful for debugging purposes
13
+ */
14
+ readonly name: string;
15
+ /**
16
+ * A qualified name that contains not only the name of this adapter, but of all its
17
+ * ancestors. E.g. `All Tests > File System > write`
18
+ */
19
+ readonly fullname: string;
20
+ /**
21
+ * Every test adapter has its own Effection `Scope` which holds the resources necessary
22
+ * to run this test.
23
+ */
24
+ readonly scope: Scope;
25
+ /**
26
+ * A list of this test adapter and every adapter that it descends from.
27
+ */
28
+ readonly lineage: Array<TestAdapter>;
29
+ /**
30
+ * The setup operations that will be run by this test adapter. It only includes those
31
+ * setups that are associated with this adapter, not those of its ancestors.
32
+ */
33
+ readonly setups: TestOperation[];
34
+ /**
35
+ * Add a setup operation to every test that is part of this adapter. In BDD integrations,
36
+ * this is usually called by `beforEach()`
37
+ */
38
+ addSetup(op: TestOperation): void;
39
+ /**
40
+ * Actually run a test. This evaluates all setup operations, and then after those have completed
41
+ * it runs the body of the test itself.
42
+ */
43
+ runTest(body: TestOperation): Future<void>;
44
+ /**
45
+ * Teardown this test adapter and all of the task and resources that are running inside it.
46
+ * This basically destroys the Effection `Scope` associated with this adapter.
47
+ */
48
+ destroy(): Future<void>;
49
+ }
50
+ export interface TestAdapterOptions {
51
+ /**
52
+ * The name of this test adapter which is handy for debugging.
53
+ * Usually, you'll give this the same name as the current test
54
+ * context. For example, when integrating with BDD, this would be
55
+ * the same as
56
+ */
57
+ name?: string;
58
+ /**
59
+ * The parent test adapter. All of the setup from this adapter will be
60
+ * run in addition to the setup of this adapter during `runTest()`
61
+ */
62
+ parent?: TestAdapter;
63
+ }
64
+ /**
65
+ * Create a new test adapter with the given options.
66
+ */
67
+ export declare function createTestAdapter(options?: TestAdapterOptions): TestAdapter;
68
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAG1D,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;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAErC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC;IAEjC;;;OAGG;IACH,QAAQ,CAAC,EAAE,EAAE,aAAa,GAAG,IAAI,CAAC;IAElC;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAE3C;;;OAGG;IACH,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;CACzB;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,CAwCb"}
package/esm/mod.js ADDED
@@ -0,0 +1,45 @@
1
+ import { createScope } from "effection";
2
+ const anonymousNames = (function* () {
3
+ let count = 1;
4
+ while (true) {
5
+ yield `anonymous test adapter ${count++}`;
6
+ }
7
+ })();
8
+ /**
9
+ * Create a new test adapter with the given options.
10
+ */
11
+ export function createTestAdapter(options = {}) {
12
+ let setups = [];
13
+ let { parent, name = anonymousNames.next().value } = options;
14
+ let [scope, destroy] = createScope(parent?.scope);
15
+ let adapter = {
16
+ parent,
17
+ name,
18
+ scope,
19
+ setups,
20
+ get lineage() {
21
+ let lineage = [adapter];
22
+ for (let current = parent; current; current = current.parent) {
23
+ lineage.unshift(current);
24
+ }
25
+ return lineage;
26
+ },
27
+ get fullname() {
28
+ return adapter.lineage.map((adapter) => adapter.name).join(" > ");
29
+ },
30
+ addSetup(op) {
31
+ setups.push(op);
32
+ },
33
+ runTest(op) {
34
+ return scope.run(function* () {
35
+ let allSetups = adapter.lineage.reduce((all, adapter) => all.concat(adapter.setups), []);
36
+ for (let setup of allSetups) {
37
+ yield* setup();
38
+ }
39
+ yield* op();
40
+ });
41
+ },
42
+ destroy,
43
+ };
44
+ return adapter;
45
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@effectionx/test-adapter",
3
+ "version": "0.1.1",
4
+ "author": "engineering@frontside.com",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/thefrontside/effectionx.git"
8
+ },
9
+ "license": "MIT",
10
+ "bugs": {
11
+ "url": "https://github.com/thefrontside/effectionx/issues"
12
+ },
13
+ "main": "./script/mod.js",
14
+ "module": "./esm/mod.js",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./esm/mod.js",
18
+ "require": "./script/mod.js"
19
+ }
20
+ },
21
+ "engines": {
22
+ "node": ">= 16"
23
+ },
24
+ "sideEffects": false,
25
+ "dependencies": {
26
+ "effection": "4.0.0-alpha.5"
27
+ },
28
+ "_generatedBy": "dnt@dev"
29
+ }
@@ -0,0 +1,68 @@
1
+ import type { Future, Operation, Scope } from "effection";
2
+ export interface TestOperation {
3
+ (): Operation<void>;
4
+ }
5
+ export interface TestAdapter {
6
+ /**
7
+ * The parent of this adapter. All of the setup from this adapter will be
8
+ * run in addition to the setup of this adapter during `runTest()`
9
+ */
10
+ readonly parent?: TestAdapter;
11
+ /**
12
+ * The name of this adapter which is mostly useful for debugging purposes
13
+ */
14
+ readonly name: string;
15
+ /**
16
+ * A qualified name that contains not only the name of this adapter, but of all its
17
+ * ancestors. E.g. `All Tests > File System > write`
18
+ */
19
+ readonly fullname: string;
20
+ /**
21
+ * Every test adapter has its own Effection `Scope` which holds the resources necessary
22
+ * to run this test.
23
+ */
24
+ readonly scope: Scope;
25
+ /**
26
+ * A list of this test adapter and every adapter that it descends from.
27
+ */
28
+ readonly lineage: Array<TestAdapter>;
29
+ /**
30
+ * The setup operations that will be run by this test adapter. It only includes those
31
+ * setups that are associated with this adapter, not those of its ancestors.
32
+ */
33
+ readonly setups: TestOperation[];
34
+ /**
35
+ * Add a setup operation to every test that is part of this adapter. In BDD integrations,
36
+ * this is usually called by `beforEach()`
37
+ */
38
+ addSetup(op: TestOperation): void;
39
+ /**
40
+ * Actually run a test. This evaluates all setup operations, and then after those have completed
41
+ * it runs the body of the test itself.
42
+ */
43
+ runTest(body: TestOperation): Future<void>;
44
+ /**
45
+ * Teardown this test adapter and all of the task and resources that are running inside it.
46
+ * This basically destroys the Effection `Scope` associated with this adapter.
47
+ */
48
+ destroy(): Future<void>;
49
+ }
50
+ export interface TestAdapterOptions {
51
+ /**
52
+ * The name of this test adapter which is handy for debugging.
53
+ * Usually, you'll give this the same name as the current test
54
+ * context. For example, when integrating with BDD, this would be
55
+ * the same as
56
+ */
57
+ name?: string;
58
+ /**
59
+ * The parent test adapter. All of the setup from this adapter will be
60
+ * run in addition to the setup of this adapter during `runTest()`
61
+ */
62
+ parent?: TestAdapter;
63
+ }
64
+ /**
65
+ * Create a new test adapter with the given options.
66
+ */
67
+ export declare function createTestAdapter(options?: TestAdapterOptions): TestAdapter;
68
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAG1D,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;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAErC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC;IAEjC;;;OAGG;IACH,QAAQ,CAAC,EAAE,EAAE,aAAa,GAAG,IAAI,CAAC;IAElC;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAE3C;;;OAGG;IACH,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;CACzB;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,CAwCb"}
package/script/mod.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTestAdapter = createTestAdapter;
4
+ const effection_1 = require("effection");
5
+ const anonymousNames = (function* () {
6
+ let count = 1;
7
+ while (true) {
8
+ yield `anonymous test adapter ${count++}`;
9
+ }
10
+ })();
11
+ /**
12
+ * Create a new test adapter with the given options.
13
+ */
14
+ function createTestAdapter(options = {}) {
15
+ let setups = [];
16
+ let { parent, name = anonymousNames.next().value } = options;
17
+ let [scope, destroy] = (0, effection_1.createScope)(parent?.scope);
18
+ let adapter = {
19
+ parent,
20
+ name,
21
+ scope,
22
+ setups,
23
+ get lineage() {
24
+ let lineage = [adapter];
25
+ for (let current = parent; current; current = current.parent) {
26
+ lineage.unshift(current);
27
+ }
28
+ return lineage;
29
+ },
30
+ get fullname() {
31
+ return adapter.lineage.map((adapter) => adapter.name).join(" > ");
32
+ },
33
+ addSetup(op) {
34
+ setups.push(op);
35
+ },
36
+ runTest(op) {
37
+ return scope.run(function* () {
38
+ let allSetups = adapter.lineage.reduce((all, adapter) => all.concat(adapter.setups), []);
39
+ for (let setup of allSetups) {
40
+ yield* setup();
41
+ }
42
+ yield* op();
43
+ });
44
+ },
45
+ destroy,
46
+ };
47
+ return adapter;
48
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }