@autometa/app 0.0.0 → 0.1.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/CHANGELOG.md +14 -0
- package/dist/esm/index.js +83 -3
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.cts +72 -0
- package/dist/index.d.ts +71 -2
- package/dist/index.js +90 -2
- package/dist/index.js.map +1 -0
- package/package.json +30 -4
- package/tsup.config.ts +1 -0
package/CHANGELOG.md
ADDED
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/autometa-app.ts
|
|
14
|
+
var AutometaApp = class {
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/autometa-world.ts
|
|
18
|
+
import { PhraseParser } from "@autometa/phrases";
|
|
19
|
+
var AutometaWorld = class {
|
|
20
|
+
};
|
|
21
|
+
AutometaWorld = __decorateClass([
|
|
22
|
+
PhraseParser
|
|
23
|
+
], AutometaWorld);
|
|
24
|
+
|
|
25
|
+
// src/get-app.ts
|
|
26
|
+
import { container } from "tsyringe";
|
|
27
|
+
import { AutomationError } from "@autometa/errors";
|
|
28
|
+
function getApp(appType, worldType, ...instances) {
|
|
29
|
+
if (!appType) {
|
|
30
|
+
throw new AutomationError(`A reference to an 'app' and 'world' is required to run tests.
|
|
31
|
+
|
|
32
|
+
Configure the app by extending 'AutometaApp' and adding it to your
|
|
33
|
+
'autometa.config.ts' file:
|
|
34
|
+
|
|
35
|
+
@AppType(MyWorld)
|
|
36
|
+
export class MyAutometaApp extends AutometaApp {
|
|
37
|
+
...
|
|
38
|
+
}
|
|
39
|
+
defineConfig({
|
|
40
|
+
roots: {
|
|
41
|
+
app: './src/apps'
|
|
42
|
+
}
|
|
43
|
+
})`);
|
|
44
|
+
}
|
|
45
|
+
container.registerType(worldType, worldType);
|
|
46
|
+
instances.forEach(
|
|
47
|
+
({ token, instance, cls }) => instance ? child.registerInstance(token, instance) : cls ? child.registerType(token, cls) : null
|
|
48
|
+
);
|
|
49
|
+
const child = container.createChildContainer();
|
|
50
|
+
const app = child.resolve(appType);
|
|
51
|
+
app.world = child.resolve(worldType);
|
|
52
|
+
return app;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/decorators/fixture.ts
|
|
56
|
+
import "reflect-metadata";
|
|
57
|
+
import { scoped, inject, Lifecycle, injectable } from "tsyringe";
|
|
58
|
+
function Fixture(scope = Lifecycle.ContainerScoped) {
|
|
59
|
+
return (target) => {
|
|
60
|
+
injectable()(target);
|
|
61
|
+
scoped(scope)(
|
|
62
|
+
target
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
var Inject = inject;
|
|
67
|
+
|
|
68
|
+
// src/decorators/app-type.ts
|
|
69
|
+
import { Lifecycle as Lifecycle2 } from "tsyringe";
|
|
70
|
+
function AppType(container2, world, environment = "default") {
|
|
71
|
+
const env = environment ?? "default";
|
|
72
|
+
return (target) => {
|
|
73
|
+
Fixture(Lifecycle2.ContainerScoped)(target);
|
|
74
|
+
container2[env] = { app: target, world };
|
|
75
|
+
};
|
|
76
|
+
}
|
|
3
77
|
export {
|
|
4
|
-
|
|
78
|
+
AppType,
|
|
79
|
+
AutometaApp,
|
|
80
|
+
AutometaWorld,
|
|
81
|
+
Fixture,
|
|
82
|
+
Inject,
|
|
83
|
+
getApp
|
|
5
84
|
};
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/autometa-app.ts","../../src/autometa-world.ts","../../src/get-app.ts","../../src/decorators/fixture.ts","../../src/decorators/app-type.ts"],"sourcesContent":["import { World } from \"./fixtures.typings\";\n\nexport abstract class AutometaApp {\n [key: string]: unknown;\n world: World\n}\n","import { PhraseParser, IFromPhrase } from \"@autometa/phrases\";\n\n@PhraseParser\nexport class AutometaWorld {\n [key: string]: unknown;\n\n fromPhrase: IFromPhrase;\n}\n","import { container } from \"tsyringe\";\nimport { AutometaApp } from \"./autometa-app\";\nimport { Class } from \"@autometa/types\";\nimport { AutomationError } from \"@autometa/errors\";\nimport { AutometaWorld } from \".\";\n\nexport function getApp<T extends AutometaApp, K extends AutometaWorld>(\n appType: Class<T>,\n worldType: Class<K>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...instances: { token: any; instance?: any; cls?: Class<any> }[]\n) {\n if (!appType) {\n throw new AutomationError(`A reference to an 'app' and 'world' is required to run tests.\n\nConfigure the app by extending 'AutometaApp' and adding it to your\n'autometa.config.ts' file:\n\n@AppType(MyWorld)\nexport class MyAutometaApp extends AutometaApp {\n ...\n}\ndefineConfig({\n roots: {\n app: './src/apps'\n }\n})`);\n }\n container.registerType(worldType, worldType);\n instances.forEach(({ token, instance, cls }) =>\n instance\n ? child.registerInstance(token, instance)\n : cls\n ? child.registerType(token, cls)\n : null\n );\n\n const child = container.createChildContainer();\n const app = child.resolve(appType);\n app.world = child.resolve(worldType);\n return app;\n}\n","import \"reflect-metadata\";\n\nimport { Class } from \"@autometa/types\";\nimport { scoped, inject, Lifecycle, injectable } from \"tsyringe\";\n/**\n * Marks a class as an injectable fixture. Constructor parameters\n * which are also injectable will be automatically constructed\n * and passed to the constructor.\n *\n * Example fixtures are the `App` which acts as shared\n * entry point for all steps in a test, and the World,\n * which stores persistent data across tests.\n *\n * Fixtures are persistent by default, meaning each class\n * will exist as a singleton for the duration of the test\n * ```ts\n * @Fixture\n * export class World {\n * [key: string]: unknown;\n *\n * declare someExpectedData: MyDataType\n * }\n *\n * @Fixture\n * export class MyClient {\n * constructor(world: MyWorld){}\n *\n * login = async ()=>{\n * this.world.someExpectedData = await fetch(...)\n * }\n * }\n *\n * @Fixture\n * export class App {\n * constructor(\n * world: MyWorld,\n * client: MyClient\n * ){}\n * }\n * ```\n */\nexport function Fixture(scope = Lifecycle.ContainerScoped) {\n return (target: Class<unknown>) => {\n injectable()(target);\n scoped(scope as Lifecycle.ContainerScoped | Lifecycle.ResolutionScoped)(\n target\n );\n };\n}\n\nexport const Inject = inject;\n\n\n","import { Class } from \"@autometa/types\";\nimport { Lifecycle } from \"tsyringe\";\nimport { AutometaWorld } from \"..\";\nimport { Fixture } from \"./fixture\";\n\n\nexport function AppType(\n container: Record<string, { app: unknown; world: unknown; }>,\n world: Class<AutometaWorld>,\n environment = \"default\"\n) {\n const env = environment ?? \"default\";\n return (target: Class<unknown>) => {\n Fixture(Lifecycle.ContainerScoped)(target);\n container[env] = { app: target, world };\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAEO,IAAe,cAAf,MAA2B;AAGlC;;;ACLA,SAAS,oBAAiC;AAGnC,IAAM,gBAAN,MAAoB;AAI3B;AAJa,gBAAN;AAAA,EADN;AAAA,GACY;;;ACHb,SAAS,iBAAiB;AAG1B,SAAS,uBAAuB;AAGzB,SAAS,OACd,SACA,cAEG,WACH;AACA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAa3B;AAAA,EACD;AACA,YAAU,aAAa,WAAW,SAAS;AAC3C,YAAU;AAAA,IAAQ,CAAC,EAAE,OAAO,UAAU,IAAI,MACxC,WACI,MAAM,iBAAiB,OAAO,QAAQ,IACtC,MACA,MAAM,aAAa,OAAO,GAAG,IAC7B;AAAA,EACN;AAEA,QAAM,QAAQ,UAAU,qBAAqB;AAC7C,QAAM,MAAM,MAAM,QAAQ,OAAO;AACjC,MAAI,QAAQ,MAAM,QAAQ,SAAS;AACnC,SAAO;AACT;;;ACzCA,OAAO;AAGP,SAAS,QAAQ,QAAQ,WAAW,kBAAkB;AAsC/C,SAAS,QAAQ,QAAQ,UAAU,iBAAiB;AACzD,SAAO,CAAC,WAA2B;AACjC,eAAW,EAAE,MAAM;AACnB,WAAO,KAA+D;AAAA,MACpE;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,SAAS;;;ACjDtB,SAAS,aAAAA,kBAAiB;AAKnB,SAAS,QACdC,YACA,OACA,cAAc,WACd;AACA,QAAM,MAAM,eAAe;AAC3B,SAAO,CAAC,WAA2B;AACjC,YAAQC,WAAU,eAAe,EAAE,MAAM;AACzC,IAAAD,WAAU,GAAG,IAAI,EAAE,KAAK,QAAQ,MAAM;AAAA,EACxC;AACF;","names":["Lifecycle","container","Lifecycle"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { IFromPhrase } from '@autometa/phrases';
|
|
2
|
+
import { Class } from '@autometa/types';
|
|
3
|
+
import { Lifecycle, inject } from 'tsyringe';
|
|
4
|
+
|
|
5
|
+
interface World {
|
|
6
|
+
}
|
|
7
|
+
interface App {
|
|
8
|
+
world: World;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare abstract class AutometaApp {
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
world: World;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare class AutometaWorld {
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
fromPhrase: IFromPhrase;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare function getApp<T extends AutometaApp, K extends AutometaWorld>(appType: Class<T>, worldType: Class<K>, ...instances: {
|
|
22
|
+
token: any;
|
|
23
|
+
instance?: any;
|
|
24
|
+
cls?: Class<any>;
|
|
25
|
+
}[]): T;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Marks a class as an injectable fixture. Constructor parameters
|
|
29
|
+
* which are also injectable will be automatically constructed
|
|
30
|
+
* and passed to the constructor.
|
|
31
|
+
*
|
|
32
|
+
* Example fixtures are the `App` which acts as shared
|
|
33
|
+
* entry point for all steps in a test, and the World,
|
|
34
|
+
* which stores persistent data across tests.
|
|
35
|
+
*
|
|
36
|
+
* Fixtures are persistent by default, meaning each class
|
|
37
|
+
* will exist as a singleton for the duration of the test
|
|
38
|
+
* ```ts
|
|
39
|
+
* @Fixture
|
|
40
|
+
* export class World {
|
|
41
|
+
* [key: string]: unknown;
|
|
42
|
+
*
|
|
43
|
+
* declare someExpectedData: MyDataType
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* @Fixture
|
|
47
|
+
* export class MyClient {
|
|
48
|
+
* constructor(world: MyWorld){}
|
|
49
|
+
*
|
|
50
|
+
* login = async ()=>{
|
|
51
|
+
* this.world.someExpectedData = await fetch(...)
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* @Fixture
|
|
56
|
+
* export class App {
|
|
57
|
+
* constructor(
|
|
58
|
+
* world: MyWorld,
|
|
59
|
+
* client: MyClient
|
|
60
|
+
* ){}
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare function Fixture(scope?: Lifecycle): (target: Class<unknown>) => void;
|
|
65
|
+
declare const Inject: typeof inject;
|
|
66
|
+
|
|
67
|
+
declare function AppType(container: Record<string, {
|
|
68
|
+
app: unknown;
|
|
69
|
+
world: unknown;
|
|
70
|
+
}>, world: Class<AutometaWorld>, environment?: string): (target: Class<unknown>) => void;
|
|
71
|
+
|
|
72
|
+
export { App, AppType, AutometaApp, AutometaWorld, Fixture, Inject, World, getApp };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
-
|
|
1
|
+
import { IFromPhrase } from '@autometa/phrases';
|
|
2
|
+
import { Class } from '@autometa/types';
|
|
3
|
+
import { Lifecycle, inject } from 'tsyringe';
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
interface World {
|
|
6
|
+
}
|
|
7
|
+
interface App {
|
|
8
|
+
world: World;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare abstract class AutometaApp {
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
world: World;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare class AutometaWorld {
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
fromPhrase: IFromPhrase;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare function getApp<T extends AutometaApp, K extends AutometaWorld>(appType: Class<T>, worldType: Class<K>, ...instances: {
|
|
22
|
+
token: any;
|
|
23
|
+
instance?: any;
|
|
24
|
+
cls?: Class<any>;
|
|
25
|
+
}[]): T;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Marks a class as an injectable fixture. Constructor parameters
|
|
29
|
+
* which are also injectable will be automatically constructed
|
|
30
|
+
* and passed to the constructor.
|
|
31
|
+
*
|
|
32
|
+
* Example fixtures are the `App` which acts as shared
|
|
33
|
+
* entry point for all steps in a test, and the World,
|
|
34
|
+
* which stores persistent data across tests.
|
|
35
|
+
*
|
|
36
|
+
* Fixtures are persistent by default, meaning each class
|
|
37
|
+
* will exist as a singleton for the duration of the test
|
|
38
|
+
* ```ts
|
|
39
|
+
* @Fixture
|
|
40
|
+
* export class World {
|
|
41
|
+
* [key: string]: unknown;
|
|
42
|
+
*
|
|
43
|
+
* declare someExpectedData: MyDataType
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* @Fixture
|
|
47
|
+
* export class MyClient {
|
|
48
|
+
* constructor(world: MyWorld){}
|
|
49
|
+
*
|
|
50
|
+
* login = async ()=>{
|
|
51
|
+
* this.world.someExpectedData = await fetch(...)
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* @Fixture
|
|
56
|
+
* export class App {
|
|
57
|
+
* constructor(
|
|
58
|
+
* world: MyWorld,
|
|
59
|
+
* client: MyClient
|
|
60
|
+
* ){}
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare function Fixture(scope?: Lifecycle): (target: Class<unknown>) => void;
|
|
65
|
+
declare const Inject: typeof inject;
|
|
66
|
+
|
|
67
|
+
declare function AppType(container: Record<string, {
|
|
68
|
+
app: unknown;
|
|
69
|
+
world: unknown;
|
|
70
|
+
}>, world: Class<AutometaWorld>, environment?: string): (target: Class<unknown>) => void;
|
|
71
|
+
|
|
72
|
+
export { App, AppType, AutometaApp, AutometaWorld, Fixture, Inject, World, getApp };
|
package/dist/index.js
CHANGED
|
@@ -16,11 +16,99 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
+
if (decorator = decorators[i])
|
|
23
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
+
if (kind && result)
|
|
25
|
+
__defProp(target, key, result);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
19
28
|
|
|
20
29
|
// src/index.ts
|
|
21
30
|
var src_exports = {};
|
|
22
31
|
__export(src_exports, {
|
|
23
|
-
|
|
32
|
+
AppType: () => AppType,
|
|
33
|
+
AutometaApp: () => AutometaApp,
|
|
34
|
+
AutometaWorld: () => AutometaWorld,
|
|
35
|
+
Fixture: () => Fixture,
|
|
36
|
+
Inject: () => Inject,
|
|
37
|
+
getApp: () => getApp
|
|
24
38
|
});
|
|
25
39
|
module.exports = __toCommonJS(src_exports);
|
|
26
|
-
|
|
40
|
+
|
|
41
|
+
// src/autometa-app.ts
|
|
42
|
+
var AutometaApp = class {
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/autometa-world.ts
|
|
46
|
+
var import_phrases = require("@autometa/phrases");
|
|
47
|
+
var AutometaWorld = class {
|
|
48
|
+
};
|
|
49
|
+
AutometaWorld = __decorateClass([
|
|
50
|
+
import_phrases.PhraseParser
|
|
51
|
+
], AutometaWorld);
|
|
52
|
+
|
|
53
|
+
// src/get-app.ts
|
|
54
|
+
var import_tsyringe = require("tsyringe");
|
|
55
|
+
var import_errors = require("@autometa/errors");
|
|
56
|
+
function getApp(appType, worldType, ...instances) {
|
|
57
|
+
if (!appType) {
|
|
58
|
+
throw new import_errors.AutomationError(`A reference to an 'app' and 'world' is required to run tests.
|
|
59
|
+
|
|
60
|
+
Configure the app by extending 'AutometaApp' and adding it to your
|
|
61
|
+
'autometa.config.ts' file:
|
|
62
|
+
|
|
63
|
+
@AppType(MyWorld)
|
|
64
|
+
export class MyAutometaApp extends AutometaApp {
|
|
65
|
+
...
|
|
66
|
+
}
|
|
67
|
+
defineConfig({
|
|
68
|
+
roots: {
|
|
69
|
+
app: './src/apps'
|
|
70
|
+
}
|
|
71
|
+
})`);
|
|
72
|
+
}
|
|
73
|
+
import_tsyringe.container.registerType(worldType, worldType);
|
|
74
|
+
instances.forEach(
|
|
75
|
+
({ token, instance, cls }) => instance ? child.registerInstance(token, instance) : cls ? child.registerType(token, cls) : null
|
|
76
|
+
);
|
|
77
|
+
const child = import_tsyringe.container.createChildContainer();
|
|
78
|
+
const app = child.resolve(appType);
|
|
79
|
+
app.world = child.resolve(worldType);
|
|
80
|
+
return app;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/decorators/fixture.ts
|
|
84
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
85
|
+
var import_tsyringe2 = require("tsyringe");
|
|
86
|
+
function Fixture(scope = import_tsyringe2.Lifecycle.ContainerScoped) {
|
|
87
|
+
return (target) => {
|
|
88
|
+
(0, import_tsyringe2.injectable)()(target);
|
|
89
|
+
(0, import_tsyringe2.scoped)(scope)(
|
|
90
|
+
target
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
var Inject = import_tsyringe2.inject;
|
|
95
|
+
|
|
96
|
+
// src/decorators/app-type.ts
|
|
97
|
+
var import_tsyringe3 = require("tsyringe");
|
|
98
|
+
function AppType(container2, world, environment = "default") {
|
|
99
|
+
const env = environment ?? "default";
|
|
100
|
+
return (target) => {
|
|
101
|
+
Fixture(import_tsyringe3.Lifecycle.ContainerScoped)(target);
|
|
102
|
+
container2[env] = { app: target, world };
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
AppType,
|
|
108
|
+
AutometaApp,
|
|
109
|
+
AutometaWorld,
|
|
110
|
+
Fixture,
|
|
111
|
+
Inject,
|
|
112
|
+
getApp
|
|
113
|
+
});
|
|
114
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/autometa-app.ts","../src/autometa-world.ts","../src/get-app.ts","../src/decorators/fixture.ts","../src/decorators/app-type.ts"],"sourcesContent":["export * from './autometa-app'\nexport * from './autometa-world'\nexport * from './get-app'\nexport * from './decorators'\nexport * from './fixtures.typings'","import { World } from \"./fixtures.typings\";\n\nexport abstract class AutometaApp {\n [key: string]: unknown;\n world: World\n}\n","import { PhraseParser, IFromPhrase } from \"@autometa/phrases\";\n\n@PhraseParser\nexport class AutometaWorld {\n [key: string]: unknown;\n\n fromPhrase: IFromPhrase;\n}\n","import { container } from \"tsyringe\";\nimport { AutometaApp } from \"./autometa-app\";\nimport { Class } from \"@autometa/types\";\nimport { AutomationError } from \"@autometa/errors\";\nimport { AutometaWorld } from \".\";\n\nexport function getApp<T extends AutometaApp, K extends AutometaWorld>(\n appType: Class<T>,\n worldType: Class<K>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...instances: { token: any; instance?: any; cls?: Class<any> }[]\n) {\n if (!appType) {\n throw new AutomationError(`A reference to an 'app' and 'world' is required to run tests.\n\nConfigure the app by extending 'AutometaApp' and adding it to your\n'autometa.config.ts' file:\n\n@AppType(MyWorld)\nexport class MyAutometaApp extends AutometaApp {\n ...\n}\ndefineConfig({\n roots: {\n app: './src/apps'\n }\n})`);\n }\n container.registerType(worldType, worldType);\n instances.forEach(({ token, instance, cls }) =>\n instance\n ? child.registerInstance(token, instance)\n : cls\n ? child.registerType(token, cls)\n : null\n );\n\n const child = container.createChildContainer();\n const app = child.resolve(appType);\n app.world = child.resolve(worldType);\n return app;\n}\n","import \"reflect-metadata\";\n\nimport { Class } from \"@autometa/types\";\nimport { scoped, inject, Lifecycle, injectable } from \"tsyringe\";\n/**\n * Marks a class as an injectable fixture. Constructor parameters\n * which are also injectable will be automatically constructed\n * and passed to the constructor.\n *\n * Example fixtures are the `App` which acts as shared\n * entry point for all steps in a test, and the World,\n * which stores persistent data across tests.\n *\n * Fixtures are persistent by default, meaning each class\n * will exist as a singleton for the duration of the test\n * ```ts\n * @Fixture\n * export class World {\n * [key: string]: unknown;\n *\n * declare someExpectedData: MyDataType\n * }\n *\n * @Fixture\n * export class MyClient {\n * constructor(world: MyWorld){}\n *\n * login = async ()=>{\n * this.world.someExpectedData = await fetch(...)\n * }\n * }\n *\n * @Fixture\n * export class App {\n * constructor(\n * world: MyWorld,\n * client: MyClient\n * ){}\n * }\n * ```\n */\nexport function Fixture(scope = Lifecycle.ContainerScoped) {\n return (target: Class<unknown>) => {\n injectable()(target);\n scoped(scope as Lifecycle.ContainerScoped | Lifecycle.ResolutionScoped)(\n target\n );\n };\n}\n\nexport const Inject = inject;\n\n\n","import { Class } from \"@autometa/types\";\nimport { Lifecycle } from \"tsyringe\";\nimport { AutometaWorld } from \"..\";\nimport { Fixture } from \"./fixture\";\n\n\nexport function AppType(\n container: Record<string, { app: unknown; world: unknown; }>,\n world: Class<AutometaWorld>,\n environment = \"default\"\n) {\n const env = environment ?? \"default\";\n return (target: Class<unknown>) => {\n Fixture(Lifecycle.ContainerScoped)(target);\n container[env] = { app: target, world };\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAe,cAAf,MAA2B;AAGlC;;;ACLA,qBAA0C;AAGnC,IAAM,gBAAN,MAAoB;AAI3B;AAJa,gBAAN;AAAA,EADN;AAAA,GACY;;;ACHb,sBAA0B;AAG1B,oBAAgC;AAGzB,SAAS,OACd,SACA,cAEG,WACH;AACA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,8BAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAa3B;AAAA,EACD;AACA,4BAAU,aAAa,WAAW,SAAS;AAC3C,YAAU;AAAA,IAAQ,CAAC,EAAE,OAAO,UAAU,IAAI,MACxC,WACI,MAAM,iBAAiB,OAAO,QAAQ,IACtC,MACA,MAAM,aAAa,OAAO,GAAG,IAC7B;AAAA,EACN;AAEA,QAAM,QAAQ,0BAAU,qBAAqB;AAC7C,QAAM,MAAM,MAAM,QAAQ,OAAO;AACjC,MAAI,QAAQ,MAAM,QAAQ,SAAS;AACnC,SAAO;AACT;;;ACzCA,8BAAO;AAGP,IAAAA,mBAAsD;AAsC/C,SAAS,QAAQ,QAAQ,2BAAU,iBAAiB;AACzD,SAAO,CAAC,WAA2B;AACjC,qCAAW,EAAE,MAAM;AACnB,iCAAO,KAA+D;AAAA,MACpE;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,SAAS;;;ACjDtB,IAAAC,mBAA0B;AAKnB,SAAS,QACdC,YACA,OACA,cAAc,WACd;AACA,QAAM,MAAM,eAAe;AAC3B,SAAO,CAAC,WAA2B;AACjC,YAAQ,2BAAU,eAAe,EAAE,MAAM;AACzC,IAAAA,WAAU,GAAG,IAAI,EAAE,KAAK,QAAQ,MAAM;AAAA,EACxC;AACF;","names":["import_tsyringe","import_tsyringe","container"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autometa/app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "App and World container for Autometa",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -14,21 +14,47 @@
|
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"devDependencies": {
|
|
17
|
+
"@autometa/types": "^0.4.0",
|
|
17
18
|
"@types/node": "^18.11.18",
|
|
18
19
|
"@types/uuid": "^9.0.1",
|
|
19
20
|
"@typescript-eslint/eslint-plugin": "^5.54.1",
|
|
20
21
|
"@typescript-eslint/parser": "^5.54.1",
|
|
22
|
+
"@vitest/coverage-istanbul": "^0.31.0",
|
|
23
|
+
"asserters": "link:packages/asserters",
|
|
24
|
+
"autometa": "link:packages/autometa",
|
|
25
|
+
"config": "link:packages/config",
|
|
26
|
+
"coordinator": "link:packages/coordinator",
|
|
27
|
+
"cucumber-expressions": "link:packages/cucumber-expressions",
|
|
28
|
+
"datetime": "link:packages/datetime",
|
|
29
|
+
"errors": "link:packages/errors",
|
|
21
30
|
"eslint": "^8.37.0",
|
|
22
|
-
"eslint-config-custom": "0.
|
|
31
|
+
"eslint-config-custom": "0.6.0",
|
|
23
32
|
"eslint-config-prettier": "^8.3.0",
|
|
33
|
+
"events": "link:packages/events",
|
|
34
|
+
"gherkin": "link:packages/gherkin",
|
|
35
|
+
"jest-executor": "link:packages/jest-executor",
|
|
36
|
+
"jest-transformer": "link:packages/jest-transformer",
|
|
37
|
+
"phrases": "link:packages/phrases",
|
|
38
|
+
"reflect-metadata": "^0.1.13",
|
|
24
39
|
"rimraf": "^4.1.2",
|
|
40
|
+
"scopes": "link:packages/scopes",
|
|
41
|
+
"test-builder": "link:packages/test-builder",
|
|
42
|
+
"test-executor": "link:packages/test-executor",
|
|
25
43
|
"tsconfig": " *",
|
|
26
|
-
"tsup": "^
|
|
44
|
+
"tsup": "^7.2.0",
|
|
45
|
+
"types": "link:packages/types",
|
|
27
46
|
"typescript": "^4.9.5",
|
|
28
|
-
"vitest": "
|
|
47
|
+
"vitest": "0.33.0"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@autometa/asserters": "0.1.0",
|
|
51
|
+
"@autometa/errors": "0.1.0",
|
|
52
|
+
"@autometa/phrases": "0.1.0",
|
|
53
|
+
"tsyringe": "^4.8.0"
|
|
29
54
|
},
|
|
30
55
|
"scripts": {
|
|
31
56
|
"test": "vitest run --passWithNoTests",
|
|
57
|
+
"coverage": "vitest run --coverage",
|
|
32
58
|
"prettify": "prettier --config .prettierrc 'src/**/*.ts' --write",
|
|
33
59
|
"lint": "eslint . --max-warnings 0",
|
|
34
60
|
"lint:fix": "eslint . --fix",
|
package/tsup.config.ts
CHANGED