@tsed/cli-testing 6.0.0-beta.1 → 6.0.0-beta.2

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.
@@ -1,4 +1,4 @@
1
- import { CliCore, CliExeca, CliFs, CliHttpClient, CliService, createInjector, DITest, Env, getCommandMetadata, InjectorService, ProjectPackageJson, resolveConfiguration } from "@tsed/cli-core";
1
+ import { $emit, CliCore, CliExeca, CliFs, CliHttpClient, CliService, configuration, createInjector, DITest, Env, getCommandMetadata, injector, InjectorService, logger, ProjectPackageJson, resolveConfiguration } from "@tsed/cli-core";
2
2
  import { Type } from "@tsed/core";
3
3
  import { DIContext, runInContext } from "@tsed/di";
4
4
  import { v4 } from "uuid";
@@ -17,8 +17,8 @@ export class CliPlatformTest extends DITest {
17
17
  },
18
18
  ...options
19
19
  });
20
- DITest.injector = CliPlatformTest.createInjector(options);
21
- DITest.injector
20
+ CliPlatformTest.createInjector(options);
21
+ injector()
22
22
  .addProvider(CliHttpClient, {
23
23
  useClass: FakeCliHttpClient
24
24
  })
@@ -29,9 +29,9 @@ export class CliPlatformTest extends DITest {
29
29
  useClass: FakeCliExeca
30
30
  })
31
31
  .addProvider(CliCore);
32
- await DITest.injector.load();
33
- await DITest.injector.emit("$onReady");
34
- await DITest.injector.emit("$loadPackageJson");
32
+ await injector().load();
33
+ await $emit("$onReady");
34
+ await $emit("$loadPackageJson");
35
35
  CliPlatformTest.get(CliService).load();
36
36
  }
37
37
  static async create(options = {}, rootModule = CliCore) {
@@ -39,11 +39,11 @@ export class CliPlatformTest extends DITest {
39
39
  name: "tsed",
40
40
  ...options
41
41
  });
42
- DITest.injector = CliPlatformTest.createInjector(options);
43
- DITest.injector.addProvider(CliCore, {
42
+ CliPlatformTest.createInjector(options);
43
+ injector().addProvider(CliCore, {
44
44
  useClass: rootModule
45
45
  });
46
- await DITest.injector.load();
46
+ await injector().load();
47
47
  }
48
48
  /**
49
49
  * Create a new injector with the right default services
@@ -65,30 +65,6 @@ export class CliPlatformTest extends DITest {
65
65
  injector.settings.env = Env.TEST;
66
66
  return injector;
67
67
  }
68
- /**
69
- * It injects services into the test function where you can alter, spy on, and manipulate them.
70
- *
71
- * The inject function has two parameters
72
- *
73
- * * an array of Service dependency injection tokens,
74
- * * a test function whose parameters correspond exactly to each item in the injection token array.
75
- *
76
- * @param targets
77
- * @param func
78
- */
79
- static inject(targets, func) {
80
- return async () => {
81
- if (!DITest.hasInjector()) {
82
- await CliPlatformTest.create();
83
- }
84
- const injector = DITest.injector;
85
- const deps = [];
86
- for (const target of targets) {
87
- deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));
88
- }
89
- return func(...deps);
90
- };
91
- }
92
68
  static setPackageJson(pkg) {
93
69
  const projectPackageJson = CliPlatformTest.get(ProjectPackageJson);
94
70
  projectPackageJson.setRaw(pkg);
@@ -101,10 +77,10 @@ export class CliPlatformTest extends DITest {
101
77
  static exec(cmdName, initialData) {
102
78
  const $ctx = new DIContext({
103
79
  id: v4(),
104
- injector: this.injector,
105
- logger: this.injector.logger
80
+ injector: injector(),
81
+ logger: logger()
106
82
  });
107
- const metadata = this.injector.settings
83
+ const metadata = configuration()
108
84
  .get("commands")
109
85
  .map((token) => getCommandMetadata(token))
110
86
  .find((commandOpts) => cmdName === commandOpts.name);
@@ -1,9 +1,5 @@
1
- import { DITest, InjectorService, type TokenProvider } from "@tsed/cli-core";
1
+ import { DITest, InjectorService } from "@tsed/cli-core";
2
2
  import { Type } from "@tsed/core";
3
- export interface InvokeOptions {
4
- token: TokenProvider;
5
- use: any;
6
- }
7
3
  export declare class CliPlatformTest extends DITest {
8
4
  static bootstrap(options?: Partial<TsED.Configuration>): Promise<void>;
9
5
  static create(options?: Partial<TsED.Configuration>, rootModule?: Type): Promise<void>;
@@ -11,23 +7,11 @@ export declare class CliPlatformTest extends DITest {
11
7
  * Create a new injector with the right default services
12
8
  */
13
9
  static createInjector(options?: Partial<TsED.Configuration>): InjectorService;
14
- /**
15
- * It injects services into the test function where you can alter, spy on, and manipulate them.
16
- *
17
- * The inject function has two parameters
18
- *
19
- * * an array of Service dependency injection tokens,
20
- * * a test function whose parameters correspond exactly to each item in the injection token array.
21
- *
22
- * @param targets
23
- * @param func
24
- */
25
- static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T>;
26
10
  static setPackageJson(pkg: any): void;
27
11
  /**
28
12
  * Invoke command with a new context without running prompts
29
13
  * @param cmdName
30
14
  * @param initialData
31
15
  */
32
- static exec(cmdName: string, initialData: any): Promise<any>;
16
+ static exec(cmdName: string, initialData: any): Promise<Promise<any>>;
33
17
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tsed/cli-testing",
3
3
  "description": "Utils to test you CLI based on Ts.ED CLI",
4
- "version": "6.0.0-beta.1",
4
+ "version": "6.0.0-beta.2",
5
5
  "type": "module",
6
6
  "main": "./lib/esm/index.js",
7
7
  "source": "./src/index.ts",
@@ -29,11 +29,11 @@
29
29
  "decorators"
30
30
  ],
31
31
  "dependencies": {
32
- "@tsed/cli-core": "6.0.0-beta.1",
32
+ "@tsed/cli-core": "6.0.0-beta.2",
33
33
  "tslib": "2.7.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@tsed/typescript": "6.0.0-beta.1",
36
+ "@tsed/typescript": "6.0.0-beta.2",
37
37
  "cross-env": "7.0.3",
38
38
  "typescript": "5.6.2",
39
39
  "vitest": "2.1.1"