yeoman-test 9.0.0 → 9.2.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/dist/run-context.d.ts +8 -0
- package/dist/run-context.js +13 -1
- package/dist/run-result.d.ts +35 -2
- package/dist/run-result.js +51 -0
- package/package.json +1 -1
package/dist/run-context.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ export declare class RunContextBase<GeneratorType extends BaseGenerator = Defaul
|
|
|
69
69
|
private ran;
|
|
70
70
|
private errored;
|
|
71
71
|
private readonly beforePrepareCallbacks;
|
|
72
|
+
private environmentRun?;
|
|
72
73
|
/**
|
|
73
74
|
* This class provide a run context object to façade the complexity involved in setting
|
|
74
75
|
* up a generator for testing
|
|
@@ -153,6 +154,13 @@ export declare class RunContextBase<GeneratorType extends BaseGenerator = Defaul
|
|
|
153
154
|
* @return {this} run context instance
|
|
154
155
|
*/
|
|
155
156
|
withEnvironment(callback: any): this;
|
|
157
|
+
/**
|
|
158
|
+
* Customize enviroment run method.
|
|
159
|
+
*
|
|
160
|
+
* @param callback
|
|
161
|
+
* @return {this} run context instance
|
|
162
|
+
*/
|
|
163
|
+
withEnvironmentRun(callback: (this: this, env: DefaultEnvironmentApi, gen: GeneratorType) => void): this;
|
|
156
164
|
/**
|
|
157
165
|
* Run lookup on the environment.
|
|
158
166
|
*
|
package/dist/run-context.js
CHANGED
|
@@ -46,6 +46,7 @@ export class RunContextBase extends EventEmitter {
|
|
|
46
46
|
ran = false;
|
|
47
47
|
errored = false;
|
|
48
48
|
beforePrepareCallbacks = [];
|
|
49
|
+
environmentRun;
|
|
49
50
|
/**
|
|
50
51
|
* This class provide a run context object to façade the complexity involved in setting
|
|
51
52
|
* up a generator for testing
|
|
@@ -81,7 +82,8 @@ export class RunContextBase extends EventEmitter {
|
|
|
81
82
|
await this.build();
|
|
82
83
|
}
|
|
83
84
|
try {
|
|
84
|
-
|
|
85
|
+
const environmentRun = this.environmentRun ?? ((env, generator) => env.runGenerator(generator));
|
|
86
|
+
await environmentRun.call(this, this.env, this.generator);
|
|
85
87
|
}
|
|
86
88
|
finally {
|
|
87
89
|
this.helpers.restorePrompt(this.env);
|
|
@@ -215,6 +217,16 @@ export class RunContextBase extends EventEmitter {
|
|
|
215
217
|
this.envCB = callback;
|
|
216
218
|
return this;
|
|
217
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Customize enviroment run method.
|
|
222
|
+
*
|
|
223
|
+
* @param callback
|
|
224
|
+
* @return {this} run context instance
|
|
225
|
+
*/
|
|
226
|
+
withEnvironmentRun(callback) {
|
|
227
|
+
this.environmentRun = callback;
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
218
230
|
/**
|
|
219
231
|
* Run lookup on the environment.
|
|
220
232
|
*
|
package/dist/run-result.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { type mock } from 'node:test';
|
|
1
2
|
import type { Store } from 'mem-fs';
|
|
2
3
|
import { type MemFsEditor, type MemFsEditorFile } from 'mem-fs-editor';
|
|
3
4
|
import type { BaseEnvironmentOptions, BaseGenerator, GetGeneratorConstructor } from '@yeoman/types';
|
|
4
|
-
import type { DefaultEnvironmentApi
|
|
5
|
+
import type { DefaultEnvironmentApi } from '../types/type-helpers.js';
|
|
5
6
|
import { type RunContextSettings } from './run-context.js';
|
|
6
7
|
import { type YeomanTest } from './helpers.js';
|
|
7
8
|
import { type AskedQuestions } from './adapter.js';
|
|
@@ -56,7 +57,7 @@ export default class RunResult<GeneratorType extends BaseGenerator = BaseGenerat
|
|
|
56
57
|
* Create another RunContext reusing the settings.
|
|
57
58
|
* See helpers.create api
|
|
58
59
|
*/
|
|
59
|
-
create<
|
|
60
|
+
create<G extends BaseGenerator = GeneratorType>(GeneratorOrNamespace: string | GetGeneratorConstructor<G>, settings?: RunContextSettings, environmentOptions?: BaseEnvironmentOptions): import("./run-context.js").default<G>;
|
|
60
61
|
getSpawnArgsUsingDefaultImplementation(): unknown[][];
|
|
61
62
|
/**
|
|
62
63
|
* Return an object with fs changes.
|
|
@@ -218,4 +219,36 @@ export default class RunResult<GeneratorType extends BaseGenerator = BaseGenerat
|
|
|
218
219
|
* @param content An object of key/values the file should not contain
|
|
219
220
|
*/
|
|
220
221
|
assertNoJsonFileContent(filename: string, content: Record<string, any>): void;
|
|
222
|
+
/**
|
|
223
|
+
* Get the generator mock
|
|
224
|
+
* @param generator - the namespace of the mocked generator
|
|
225
|
+
* @returns the generator mock
|
|
226
|
+
*/
|
|
227
|
+
getGeneratorMock(generator: string): ReturnType<typeof mock.fn>['mock'];
|
|
228
|
+
/**
|
|
229
|
+
* Get the number of times a mocked generator was composed
|
|
230
|
+
* @param generator - the namespace of the mocked generator
|
|
231
|
+
* @returns the number of times the generator was composed
|
|
232
|
+
*/
|
|
233
|
+
getGeneratorComposeCount(generator: string): number;
|
|
234
|
+
/**
|
|
235
|
+
* Assert that a generator was composed
|
|
236
|
+
* @param generator - the namespace of the mocked generator
|
|
237
|
+
*/
|
|
238
|
+
assertGeneratorComposed(generator: string): void;
|
|
239
|
+
/**
|
|
240
|
+
* Assert that a generator was composed
|
|
241
|
+
* @param generator - the namespace of the mocked generator
|
|
242
|
+
*/
|
|
243
|
+
assertGeneratorNotComposed(generator: string): void;
|
|
244
|
+
/**
|
|
245
|
+
* Assert that a generator was composed only once
|
|
246
|
+
* @param generator - the namespace of the mocked generator
|
|
247
|
+
*/
|
|
248
|
+
assertGeneratorComposedOnce(generator: string): void;
|
|
249
|
+
/**
|
|
250
|
+
* Assert that a generator was composed multiple times
|
|
251
|
+
* @returns an array of the names of the mocked generators that were composed
|
|
252
|
+
*/
|
|
253
|
+
getComposedGenerators(): string[];
|
|
221
254
|
}
|
package/dist/run-result.js
CHANGED
|
@@ -262,4 +262,55 @@ export default class RunResult {
|
|
|
262
262
|
assertNoJsonFileContent(filename, content) {
|
|
263
263
|
this.assertNoObjectContent(this._readFile(filename, true), content);
|
|
264
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Get the generator mock
|
|
267
|
+
* @param generator - the namespace of the mocked generator
|
|
268
|
+
* @returns the generator mock
|
|
269
|
+
*/
|
|
270
|
+
getGeneratorMock(generator) {
|
|
271
|
+
const mockedGenerator = this.mockedGenerators[generator];
|
|
272
|
+
if (!mockedGenerator) {
|
|
273
|
+
throw new Error(`Generator ${generator} is not mocked`);
|
|
274
|
+
}
|
|
275
|
+
return mockedGenerator.mock;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Get the number of times a mocked generator was composed
|
|
279
|
+
* @param generator - the namespace of the mocked generator
|
|
280
|
+
* @returns the number of times the generator was composed
|
|
281
|
+
*/
|
|
282
|
+
getGeneratorComposeCount(generator) {
|
|
283
|
+
return this.getGeneratorMock(generator).callCount();
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Assert that a generator was composed
|
|
287
|
+
* @param generator - the namespace of the mocked generator
|
|
288
|
+
*/
|
|
289
|
+
assertGeneratorComposed(generator) {
|
|
290
|
+
assert.ok(this.getGeneratorComposeCount(generator) > 0, `Generator ${generator} is not composed`);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Assert that a generator was composed
|
|
294
|
+
* @param generator - the namespace of the mocked generator
|
|
295
|
+
*/
|
|
296
|
+
assertGeneratorNotComposed(generator) {
|
|
297
|
+
const composeCount = this.getGeneratorComposeCount(generator);
|
|
298
|
+
assert.ok(composeCount === 0, `Generator ${generator} is composed ${composeCount}`);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Assert that a generator was composed only once
|
|
302
|
+
* @param generator - the namespace of the mocked generator
|
|
303
|
+
*/
|
|
304
|
+
assertGeneratorComposedOnce(generator) {
|
|
305
|
+
assert.ok(this.getGeneratorComposeCount(generator) === 1, `Generator ${generator} is not composed`);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Assert that a generator was composed multiple times
|
|
309
|
+
* @returns an array of the names of the mocked generators that were composed
|
|
310
|
+
*/
|
|
311
|
+
getComposedGenerators() {
|
|
312
|
+
return Object.entries(this.mockedGenerators)
|
|
313
|
+
.filter(([_generator, mockedGenerator]) => mockedGenerator.mock.callCount() > 0)
|
|
314
|
+
.map(([generator]) => generator);
|
|
315
|
+
}
|
|
265
316
|
}
|