yeoman-test 8.0.0-rc.1 → 8.0.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.
@@ -46,6 +46,7 @@ export declare class RunContextBase<GeneratorType extends BaseGenerator = Defaul
46
46
  targetDirectory?: string;
47
47
  editor: MemFsEditor;
48
48
  memFs: Store<MemFsEditorFile>;
49
+ spawnStub?: any;
49
50
  mockedGeneratorFactory: MockedGeneratorFactory;
50
51
  protected environmentPromise?: PromiseRunResult<GeneratorType>;
51
52
  private args;
@@ -202,6 +203,7 @@ export declare class RunContextBase<GeneratorType extends BaseGenerator = Defaul
202
203
  * });
203
204
  */
204
205
  withGenerators(dependencies: Dependency[]): this;
206
+ withSpawnMock(stub?: import("sinon").SinonStub<any[], any>): this;
205
207
  withMockedGeneratorFactory(mockedGeneratorFactory: MockedGeneratorFactory): this;
206
208
  /**
207
209
  * Create mocked generators
@@ -9,10 +9,12 @@ import { camelCase, kebabCase, merge as lodashMerge, set as lodashSet } from 'lo
9
9
  import { resetFileCommitStates } from 'mem-fs-editor/state';
10
10
  import { create as createMemFs } from 'mem-fs';
11
11
  import tempDirectory from 'temp-dir';
12
+ import { stub as sinonStub } from 'sinon';
12
13
  import { create as createMemFsEditor } from 'mem-fs-editor';
13
14
  import RunResult from './run-result.js';
14
15
  import defaultHelpers from './helpers.js';
15
16
  import testContext from './test-context.js';
17
+ // eslint-disable-next-line unicorn/prefer-event-target
16
18
  export class RunContextBase extends EventEmitter {
17
19
  mockedGenerators = {};
18
20
  env;
@@ -23,6 +25,7 @@ export class RunContextBase extends EventEmitter {
23
25
  targetDirectory;
24
26
  editor;
25
27
  memFs;
28
+ spawnStub;
26
29
  mockedGeneratorFactory;
27
30
  environmentPromise;
28
31
  args = [];
@@ -308,6 +311,23 @@ export class RunContextBase extends EventEmitter {
308
311
  }
309
312
  });
310
313
  }
314
+ withSpawnMock(stub = sinonStub()) {
315
+ if (this.spawnStub) {
316
+ throw new Error('Multiple withSpawnMock calls');
317
+ }
318
+ this.spawnStub = stub;
319
+ return this.onEnvironment(env => {
320
+ env.on('compose', (_namespace, generator) => {
321
+ const createCallback = method => function (...args) {
322
+ stub.call(this, method, ...args);
323
+ };
324
+ generator.spawnCommand = createCallback('spawnCommand');
325
+ generator.spawnCommandSync = createCallback('spawnCommandSync');
326
+ generator.spawn = createCallback('spawn');
327
+ generator.spawnSync = createCallback('spawnSync');
328
+ });
329
+ });
330
+ }
311
331
  withMockedGeneratorFactory(mockedGeneratorFactory) {
312
332
  this.mockedGeneratorFactory = mockedGeneratorFactory;
313
333
  return this;
@@ -534,6 +554,7 @@ export class RunContextBase extends EventEmitter {
534
554
  settings: {
535
555
  ...this.settings,
536
556
  },
557
+ spawnStub: this.spawnStub,
537
558
  oldCwd: this.oldCwd,
538
559
  cwd: this.targetDirectory,
539
560
  envOptions: this.envOptions,
@@ -31,6 +31,7 @@ export type RunResultOptions<GeneratorType extends BaseGenerator> = {
31
31
  * The mocked generators of the context.
32
32
  */
33
33
  mockedGenerators: Record<string, BaseGenerator>;
34
+ spawnStub?: any;
34
35
  settings: RunContextSettings;
35
36
  helpers: YeomanTest;
36
37
  };
@@ -46,12 +47,14 @@ export default class RunResult<GeneratorType extends BaseGenerator = BaseGenerat
46
47
  fs: MemFsEditor;
47
48
  mockedGenerators: any;
48
49
  options: RunResultOptions<GeneratorType>;
50
+ spawnStub?: any;
49
51
  constructor(options: RunResultOptions<GeneratorType>);
50
52
  /**
51
53
  * Create another RunContext reusing the settings.
52
54
  * See helpers.create api
53
55
  */
54
56
  create<GeneratorType extends BaseGenerator = DefaultGeneratorApi>(GeneratorOrNamespace: string | GetGeneratorConstructor<GeneratorType>, settings?: RunContextSettings, envOptions?: BaseEnvironmentOptions): import("./run-context.js").default<GeneratorType>;
57
+ getSpawnArgsUsingDefaultImplementation(): any;
55
58
  /**
56
59
  * Return an object with fs changes.
57
60
  * @param {Function} filter - parameter forwarded to mem-fs-editor#dump
@@ -23,6 +23,7 @@ export default class RunResult {
23
23
  fs;
24
24
  mockedGenerators;
25
25
  options;
26
+ spawnStub;
26
27
  constructor(options) {
27
28
  if (options.memFs && !options.cwd) {
28
29
  throw new Error('CWD option is required for mem-fs tests');
@@ -34,6 +35,7 @@ export default class RunResult {
34
35
  this.memFs = options.memFs;
35
36
  this.fs = this.memFs && createMemFsEditor(this.memFs);
36
37
  this.mockedGenerators = options.mockedGenerators || {};
38
+ this.spawnStub = options.spawnStub;
37
39
  this.options = options;
38
40
  }
39
41
  /**
@@ -50,6 +52,12 @@ export default class RunResult {
50
52
  autoCleanup: false,
51
53
  }, { ...this.options.envOptions, ...envOptions });
52
54
  }
55
+ getSpawnArgsUsingDefaultImplementation() {
56
+ if (!this.spawnStub) {
57
+ throw new Error('Spawn stub was not found');
58
+ }
59
+ return this.spawnStub.getCalls().map(call => call.args);
60
+ }
53
61
  /**
54
62
  * Return an object with fs changes.
55
63
  * @param {Function} filter - parameter forwarded to mem-fs-editor#dump
@@ -208,7 +216,7 @@ export default class RunResult {
208
216
  * result.assertTextEqual('I have a yellow cat', 'I have a yellow cat');
209
217
  */
210
218
  assertTextEqual(value, expected) {
211
- const eol = string => string.replace(/\r\n/g, '\n');
219
+ const eol = string => string.replaceAll('\r\n', '\n');
212
220
  assert.equal(eol(value), eol(expected));
213
221
  }
214
222
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-test",
3
- "version": "8.0.0-rc.1",
3
+ "version": "8.0.0",
4
4
  "description": "Test utilities for Yeoman generators",
5
5
  "keywords": [
6
6
  "yeoman",
@@ -41,33 +41,33 @@
41
41
  "lodash-es": "^4.17.21",
42
42
  "mem-fs": "^3.0.0",
43
43
  "mem-fs-editor": "^10.0.2",
44
- "sinon": "^15.1.0",
44
+ "sinon": "^16.0.0",
45
45
  "temp-dir": "^3.0.0",
46
- "type-fest": "^3.10.0"
46
+ "type-fest": "^4.3.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/inquirer": "^9.0.3",
50
50
  "@types/lodash": "^4.14.195",
51
51
  "@types/node": "^16.18.19",
52
52
  "@types/sinon": "^10.0.13",
53
- "c8": "^7.13.0",
53
+ "c8": "^8.0.0",
54
54
  "coveralls": "^3.1.1",
55
55
  "esmocha": "^1.0.1",
56
56
  "husky": "^8.0.2",
57
57
  "jsdoc": "^4.0.2",
58
- "lint-staged": "^13.0.3",
59
- "prettier": "^2.2.1",
58
+ "lint-staged": "^14.0.1",
59
+ "prettier": "^3.0.3",
60
60
  "prettier-plugin-packagejson": "^2.3.0",
61
61
  "tui-jsdoc-template": "^1.2.2",
62
- "typescript": "^5.0.4",
63
- "xo": "^0.54.2",
62
+ "typescript": "~5.2.2",
63
+ "xo": "0.56.0",
64
64
  "yeoman-environment": "^3.18.3",
65
65
  "yeoman-generator": "^5.9.0"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "@yeoman/types": "^1.0.1",
69
69
  "yeoman-environment": "^3.18.3 || ^4.0.0-alpha.6",
70
- "yeoman-generator": "^5.9.0 || ^6.0.0-beta.4"
70
+ "yeoman-generator": "^5.9.0 || ^6.0.0"
71
71
  },
72
72
  "peerDependenciesMeta": {
73
73
  "yeoman-environment": {