yeoman-test 8.0.0-beta.1 → 8.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.
package/dist/helpers.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { BaseEnvironmentOptions, BaseGenerator, BaseGeneratorOptions, GetGeneratorConstructor, GetGeneratorOptions, PromptAnswers } from '@yeoman/types';
1
+ import type { BaseEnvironment, BaseEnvironmentOptions, BaseGenerator, BaseGeneratorOptions, GetGeneratorConstructor, GetGeneratorOptions, PromptAnswers } from '@yeoman/types';
2
2
  import type { SinonSpiedInstance } from 'sinon';
3
3
  import { type DummyPromptOptions } from './adapter.js';
4
4
  import RunContext, { BasicRunContext, type RunContextSettings } from './run-context.js';
@@ -6,7 +6,7 @@ import type { DefaultEnvironmentApi, DefaultGeneratorApi } from './type-helpers.
6
6
  /**
7
7
  * Dependencies can be path (autodiscovery) or an array [<generator>, <name>]
8
8
  */
9
- export type Dependency = string | Parameters<DefaultEnvironmentApi['registerStub']>;
9
+ export type Dependency = Parameters<DefaultEnvironmentApi['register']> | Parameters<DefaultEnvironmentApi['registerStub']>;
10
10
  export type GeneratorFactory<GenParameter extends BaseGenerator = DefaultGeneratorApi> = GetGeneratorConstructor<GenParameter> | ((...args: ConstructorParameters<GetGeneratorConstructor<GenParameter>>) => GenParameter);
11
11
  /**
12
12
  * Collection of unit test helpers. (mostly related to Mocha syntax)
@@ -66,11 +66,11 @@ export declare class YeomanTest {
66
66
  /**
67
67
  * Create a mocked generator
68
68
  */
69
- createMockedGenerator(GeneratorClass: any): Promise<SinonSpiedInstance<DefaultGeneratorApi>>;
69
+ createMockedGenerator(GeneratorClass?: any): SinonSpiedInstance<DefaultGeneratorApi>;
70
70
  /**
71
71
  * Create a simple, dummy generator
72
72
  */
73
- createDummyGenerator<GenParameter extends BaseGenerator = DefaultGeneratorApi>(Generator?: GetGeneratorConstructor<GenParameter>, contents?: Record<string, (...args: any[]) => void>): Promise<new (...args: any[]) => GenParameter>;
73
+ createDummyGenerator<GenParameter extends BaseGenerator = DefaultGeneratorApi>(Generator?: GetGeneratorConstructor<GenParameter>, contents?: Record<string, (...args: any[]) => void>): new (...args: any[]) => GenParameter;
74
74
  /**
75
75
  * Create a generator, using the given dependencies and controller arguments
76
76
  * Dependecies can be path (autodiscovery) or an array [{generator}, {name}]
@@ -122,7 +122,7 @@ export declare class YeomanTest {
122
122
  * @param {Object} - Options to be passed to the environment
123
123
  * const env = createTestEnv(require('yeoman-environment').createEnv);
124
124
  */
125
- createTestEnv(envContructor?: (...args: any[]) => Promise<import("@yeoman/types").BaseEnvironment>, options?: BaseEnvironmentOptions): Promise<import("@yeoman/types").BaseEnvironment>;
125
+ createTestEnv(envContructor?: (...args: any[]) => Promise<BaseEnvironment>, options?: BaseEnvironmentOptions): Promise<BaseEnvironment>;
126
126
  /**
127
127
  * Get RunContext type
128
128
  * @return {RunContext}
package/dist/helpers.js CHANGED
@@ -7,6 +7,12 @@ import { spy as sinonSpy, stub as sinonStub } from 'sinon';
7
7
  import { DummyPrompt, TestAdapter } from './adapter.js';
8
8
  import RunContext, { BasicRunContext } from './run-context.js';
9
9
  import testContext from './test-context.js';
10
+ let GeneratorImplementation;
11
+ try {
12
+ const GeneratorImport = await import('yeoman-generator');
13
+ GeneratorImplementation = GeneratorImport.default ?? GeneratorImport;
14
+ }
15
+ catch { }
10
16
  const { cloneDeep } = _;
11
17
  /**
12
18
  * Collection of unit test helpers. (mostly related to Mocha syntax)
@@ -107,11 +113,7 @@ export class YeomanTest {
107
113
  /**
108
114
  * Create a mocked generator
109
115
  */
110
- async createMockedGenerator(GeneratorClass) {
111
- if (!GeneratorClass) {
112
- const GeneratorImplementation = await import('yeoman-generator');
113
- GeneratorClass = (GeneratorImplementation.default ?? GeneratorImplementation);
114
- }
116
+ createMockedGenerator(GeneratorClass = GeneratorImplementation) {
115
117
  class MockedGenerator extends GeneratorClass {
116
118
  }
117
119
  const generator = sinonSpy(MockedGenerator);
@@ -125,17 +127,12 @@ export class YeomanTest {
125
127
  /**
126
128
  * Create a simple, dummy generator
127
129
  */
128
- async createDummyGenerator(Generator, contents = {
130
+ createDummyGenerator(Generator = GeneratorImplementation, contents = {
129
131
  test() {
130
132
  this.shouldRun = true;
131
133
  },
132
134
  }) {
133
- if (!Generator) {
134
- const GeneratorImplementation = await import('yeoman-generator');
135
- Generator = (GeneratorImplementation.default ?? GeneratorImplementation);
136
- }
137
- const GeneratorConstructor = Generator;
138
- class DummyGenerator extends GeneratorConstructor {
135
+ class DummyGenerator extends Generator {
139
136
  constructor(...args) {
140
137
  const optIndex = Array.isArray(args[0]) ? 1 : 0;
141
138
  args[optIndex] = args[optIndex] ?? {};
@@ -33,7 +33,7 @@ export type RunContextSettings = {
33
33
  namespace?: string;
34
34
  };
35
35
  type PromiseRunResult<GeneratorType extends BaseGenerator> = Promise<RunResult<GeneratorType>>;
36
- type MockedGeneratorFactory<GenParameter extends BaseGenerator = DefaultGeneratorApi> = (GeneratorClass?: GetGeneratorConstructor<GenParameter>) => Promise<GenParameter>;
36
+ type MockedGeneratorFactory<GenParameter extends BaseGenerator = DefaultGeneratorApi> = (GeneratorClass?: GetGeneratorConstructor<GenParameter>) => GenParameter;
37
37
  type EnvOptions = BaseEnvironmentOptions & {
38
38
  createEnv?: any;
39
39
  };
@@ -332,13 +332,10 @@ export class RunContextBase extends EventEmitter {
332
332
  */
333
333
  withMockedGenerators(namespaces) {
334
334
  assert(Array.isArray(namespaces), 'namespaces should be an array');
335
- return this.onBeforePrepare(async () => {
336
- const MockedGenerator = await this.mockedGeneratorFactory();
337
- const dependencies = namespaces.map(namespace => [MockedGenerator, namespace]);
338
- const entries = dependencies.map(([generator, namespace]) => [namespace, generator]);
339
- Object.assign(this.mockedGenerators, Object.fromEntries(entries));
340
- this.withGenerators(dependencies);
341
- });
335
+ const dependencies = namespaces.map(namespace => [this.mockedGeneratorFactory(), namespace]);
336
+ const entries = dependencies.map(([generator, namespace]) => [namespace, generator]);
337
+ Object.assign(this.mockedGenerators, Object.fromEntries(entries));
338
+ return this.withGenerators(dependencies);
342
339
  }
343
340
  /**
344
341
  * Mock the local configuration with the provided config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-test",
3
- "version": "8.0.0-beta.1",
3
+ "version": "8.0.0-beta.2",
4
4
  "description": "Test utilities for Yeoman generators",
5
5
  "keywords": [
6
6
  "yeoman",
@@ -49,7 +49,7 @@
49
49
  "@types/sinon": "^10.0.13",
50
50
  "c8": "^7.13.0",
51
51
  "coveralls": "^3.1.1",
52
- "esmocha": "^0.1.4",
52
+ "esmocha": "^1.0.1",
53
53
  "husky": "^8.0.2",
54
54
  "jsdoc": "^3.6.10",
55
55
  "lint-staged": "^13.0.3",
@@ -59,7 +59,7 @@
59
59
  "typescript": "^5.0.4",
60
60
  "xo": "^0.54.2",
61
61
  "yeoman-environment": "^3.16.1",
62
- "yeoman-generator": "^6.0.0-beta.1"
62
+ "yeoman-generator": "^5.8.0"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "@yeoman/types": "^0.3.0",