yeoman-test 8.1.0 → 8.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 +5 -1
- package/dist/run-context.js +22 -2
- package/package.json +1 -1
package/dist/run-context.d.ts
CHANGED
|
@@ -203,7 +203,11 @@ export declare class RunContextBase<GeneratorType extends BaseGenerator = Defaul
|
|
|
203
203
|
* });
|
|
204
204
|
*/
|
|
205
205
|
withGenerators(dependencies: Dependency[]): this;
|
|
206
|
-
withSpawnMock(
|
|
206
|
+
withSpawnMock(options?: ((...args: any[]) => any) | {
|
|
207
|
+
stub?: (...args: any[]) => any;
|
|
208
|
+
registerSinonDefaults?: boolean;
|
|
209
|
+
callback?: (stub: any) => void | Promise<void>;
|
|
210
|
+
}): this;
|
|
207
211
|
withMockedGeneratorFactory(mockedGeneratorFactory: MockedGeneratorFactory): this;
|
|
208
212
|
/**
|
|
209
213
|
* Create mocked generators
|
package/dist/run-context.js
CHANGED
|
@@ -311,15 +311,35 @@ export class RunContextBase extends EventEmitter {
|
|
|
311
311
|
}
|
|
312
312
|
});
|
|
313
313
|
}
|
|
314
|
-
withSpawnMock(
|
|
314
|
+
withSpawnMock(options) {
|
|
315
315
|
if (this.spawnStub) {
|
|
316
316
|
throw new Error('Multiple withSpawnMock calls');
|
|
317
317
|
}
|
|
318
|
+
const stub = typeof options === 'function' ? options : options?.stub ?? sinonStub();
|
|
319
|
+
const registerSinonDefaults = typeof options === 'function' ? false : options?.registerSinonDefaults ?? true;
|
|
320
|
+
const callback = typeof options === 'function' ? undefined : options?.callback;
|
|
321
|
+
if (registerSinonDefaults) {
|
|
322
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
323
|
+
const defaultChild = { stdout: { on() { } }, stderr: { on() { } } };
|
|
324
|
+
const defaultReturn = { exitCode: 0, stdout: '', stderr: '' };
|
|
325
|
+
const stubFn = stub;
|
|
326
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
327
|
+
stubFn.withArgs('spawnCommand').callsFake(() => Object.assign(Promise.resolve({ ...defaultReturn }), defaultChild));
|
|
328
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
329
|
+
stubFn.withArgs('spawn').callsFake(() => Object.assign(Promise.resolve({ ...defaultReturn }), defaultChild));
|
|
330
|
+
stubFn.withArgs('spawnCommandSync').callsFake(() => ({ ...defaultReturn }));
|
|
331
|
+
stubFn.withArgs('spawnSync').callsFake(() => ({ ...defaultReturn }));
|
|
332
|
+
}
|
|
333
|
+
if (callback) {
|
|
334
|
+
this.onBeforePrepare(async () => {
|
|
335
|
+
await callback(stub);
|
|
336
|
+
});
|
|
337
|
+
}
|
|
318
338
|
this.spawnStub = stub;
|
|
319
339
|
return this.onEnvironment(env => {
|
|
320
340
|
env.on('compose', (_namespace, generator) => {
|
|
321
341
|
const createCallback = method => function (...args) {
|
|
322
|
-
stub.call(this, method, ...args);
|
|
342
|
+
return stub.call(this, method, ...args);
|
|
323
343
|
};
|
|
324
344
|
generator.spawnCommand = createCallback('spawnCommand');
|
|
325
345
|
generator.spawnCommandSync = createCallback('spawnCommandSync');
|