@tsed/cli-testing 3.14.1 → 3.17.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/lib/CliPlatformTest.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { InjectorService, TokenProvider
|
|
1
|
+
import { DITest, InjectorService, TokenProvider } from "@tsed/cli-core";
|
|
2
2
|
import { Type } from "@tsed/core";
|
|
3
3
|
export interface InvokeOptions {
|
|
4
4
|
token: TokenProvider;
|
|
5
5
|
use: any;
|
|
6
6
|
}
|
|
7
7
|
export declare class CliPlatformTest extends DITest {
|
|
8
|
-
static bootstrap(options?: Partial<TsED.Configuration
|
|
8
|
+
static bootstrap(options?: Partial<TsED.Configuration>): Promise<void>;
|
|
9
9
|
static create(options?: Partial<TsED.Configuration>, rootModule?: Type): Promise<void>;
|
|
10
10
|
/**
|
|
11
11
|
* Create a new injector with the right default services
|
package/lib/CliPlatformTest.js
CHANGED
|
@@ -7,7 +7,7 @@ const FakeCliFs_1 = require("./FakeCliFs");
|
|
|
7
7
|
const FakeCliHttpClient_1 = require("./FakeCliHttpClient");
|
|
8
8
|
const di_1 = require("@tsed/di");
|
|
9
9
|
class CliPlatformTest extends cli_core_1.DITest {
|
|
10
|
-
static async bootstrap(options = {}
|
|
10
|
+
static async bootstrap(options = {}) {
|
|
11
11
|
cli_core_1.DITest.injector = CliPlatformTest.createInjector({
|
|
12
12
|
name: "tsed",
|
|
13
13
|
project: {
|
|
@@ -18,12 +18,18 @@ class CliPlatformTest extends cli_core_1.DITest {
|
|
|
18
18
|
},
|
|
19
19
|
...options
|
|
20
20
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
cli_core_1.DITest.injector
|
|
22
|
+
.addProvider(cli_core_1.CliHttpClient, {
|
|
23
|
+
useClass: FakeCliHttpClient_1.FakeCliHttpClient
|
|
24
|
+
})
|
|
25
|
+
.addProvider(cli_core_1.CliFs, {
|
|
26
|
+
useClass: FakeCliFs_1.FakeCliFs
|
|
27
|
+
})
|
|
28
|
+
.addProvider(cli_core_1.CliExeca, {
|
|
29
|
+
useClass: FakeCliExeca_1.FakeCliExeca
|
|
30
|
+
})
|
|
31
|
+
.addProvider(cli_core_1.CliCore);
|
|
32
|
+
await cli_core_1.DITest.injector.load();
|
|
27
33
|
await cli_core_1.DITest.injector.emit("$onReady");
|
|
28
34
|
CliPlatformTest.get(cli_core_1.CliService).load();
|
|
29
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CliPlatformTest.js","sourceRoot":"","sources":["../src/CliPlatformTest.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"CliPlatformTest.js","sourceRoot":"","sources":["../src/CliPlatformTest.ts"],"names":[],"mappings":";;;AAAA,6CAWwB;AAExB,iDAA4C;AAC5C,2CAAsC;AACtC,2DAAsD;AACtD,iCAAyC;AAOzC,MAAa,eAAgB,SAAQ,iBAAM;IACzC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,UAAuC,EAAE;QAC9D,iBAAM,CAAC,QAAQ,GAAG,eAAe,CAAC,cAAc,CAAC;YAC/C,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE;gBACP,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,gBAAgB;gBAC5C,MAAM,EAAE,KAAK;gBACb,UAAU,EAAE,SAAS;gBACrB,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;aAC3B;YACD,GAAG,OAAO;SACX,CAAC,CAAC;QAEH,iBAAM,CAAC,QAAQ;aACZ,WAAW,CAAC,wBAAa,EAAE;YAC1B,QAAQ,EAAE,qCAAiB;SAC5B,CAAC;aACD,WAAW,CAAC,gBAAK,EAAE;YAClB,QAAQ,EAAE,qBAAS;SACpB,CAAC;aACD,WAAW,CAAC,mBAAQ,EAAE;YACrB,QAAQ,EAAE,2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AAM,QAAQ,GAAoB,iBAAM,CAAC,QAAQ,CAAC;YAClD,MAAM,IAAI,GAAG,EAAE,CAAC;YAEhB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;gBAC5B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;aACxF;YAED,OAAO,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAC7B,CAAC,CAAC;IACJ,CAAC;CACF;AAzFD,0CAyFC","sourcesContent":["import {\n CliCore,\n CliExeca,\n CliFs,\n CliHttpClient,\n CliService,\n createInjector,\n DITest,\n Env,\n InjectorService,\n TokenProvider\n} from \"@tsed/cli-core\";\nimport {Type} from \"@tsed/core\";\nimport {FakeCliExeca} from \"./FakeCliExeca\";\nimport {FakeCliFs} from \"./FakeCliFs\";\nimport {FakeCliHttpClient} from \"./FakeCliHttpClient\";\nimport {createContainer} from \"@tsed/di\";\n\nexport interface InvokeOptions {\n token: TokenProvider;\n use: any;\n}\n\nexport class CliPlatformTest extends DITest {\n static async bootstrap(options: Partial<TsED.Configuration> = {}) {\n DITest.injector = CliPlatformTest.createInjector({\n name: \"tsed\",\n project: {\n rootDir: options.rootDir || \"./project-name\",\n srcDir: \"src\",\n scriptsDir: \"scripts\",\n ...(options.project || {})\n },\n ...options\n });\n\n DITest.injector\n .addProvider(CliHttpClient, {\n useClass: FakeCliHttpClient\n })\n .addProvider(CliFs, {\n useClass: FakeCliFs\n })\n .addProvider(CliExeca, {\n useClass: FakeCliExeca\n })\n .addProvider(CliCore);\n\n await DITest.injector.load();\n await DITest.injector.emit(\"$onReady\");\n\n CliPlatformTest.get(CliService).load();\n }\n\n static async create(options: Partial<TsED.Configuration> = {}, rootModule: Type = CliCore) {\n DITest.injector = CliPlatformTest.createInjector({\n name: \"tsed\",\n ...options\n });\n const container = createContainer();\n await DITest.injector.load(container, rootModule);\n }\n\n /**\n * Create a new injector with the right default services\n */\n static createInjector(options: Partial<TsED.Configuration> = {}): InjectorService {\n const injector = createInjector({\n ...options,\n pkg: {\n name: \"@tsed/cli-testing\",\n version: \"1.0.0\"\n } as any,\n project: {\n rootDir: \"./tmp\",\n srcDir: \"src\",\n ...(options.project || {})\n }\n });\n\n injector.settings.env = Env.TEST;\n\n return injector;\n }\n\n /**\n * It injects services into the test function where you can alter, spy on, and manipulate them.\n *\n * The inject function has two parameters\n *\n * * an array of Service dependency injection tokens,\n * * a test function whose parameters correspond exactly to each item in the injection token array.\n *\n * @param targets\n * @param func\n */\n static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T> {\n return async (): Promise<T> => {\n if (!DITest.hasInjector()) {\n await CliPlatformTest.create();\n }\n\n const injector: InjectorService = DITest.injector;\n const deps = [];\n\n for (const target of targets) {\n deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));\n }\n\n return await func(...deps);\n };\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/cli-testing",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.0",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"typings": "./lib/index.d.ts",
|
|
6
6
|
"description": "Utils to test you CLI based on Ts.ED CLI",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"decorators"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@tsed/cli-core": "3.
|
|
18
|
+
"@tsed/cli-core": "3.17.0",
|
|
19
19
|
"tslib": "2.3.1"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|