yeoman-test 8.2.0 → 8.3.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/README.md +15 -38
- package/dist/adapter.d.ts +4 -0
- package/dist/adapter.js +0 -2
- package/dist/run-context.d.ts +2 -1
- package/dist/run-context.js +11 -2
- package/dist/run-result.d.ts +3 -0
- package/dist/run-result.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,17 +22,16 @@ $ npm install --save-dev yeoman-generator@xxx yeoman-environment@xxx
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
-
Usage:
|
|
25
|
+
Usage using the convenience last RunResult instance:
|
|
26
26
|
|
|
27
27
|
```js
|
|
28
|
-
import helpers from 'yeoman-test';
|
|
28
|
+
import helpers, { result } from 'yeoman-test';
|
|
29
29
|
|
|
30
30
|
describe('generator test', () => {
|
|
31
31
|
describe('test', () => {
|
|
32
|
-
let runResult;
|
|
33
32
|
beforeEach(async () => {
|
|
34
|
-
|
|
35
|
-
.
|
|
33
|
+
await helpers
|
|
34
|
+
.run( // instantiates RunContext
|
|
36
35
|
'namespace', // namespace or generator
|
|
37
36
|
{}, // test options
|
|
38
37
|
{} // environment options
|
|
@@ -53,47 +52,25 @@ describe('generator test', () => {
|
|
|
53
52
|
[.withYoRcConfig('generator-foo.bar', { : {} })] // same as above
|
|
54
53
|
[.commitFiles()] // commit mem-fs files to disk
|
|
55
54
|
[.onGenerator(gen => {})] // do something with the generator
|
|
56
|
-
[.onEnvironment(env => {})] // do something with the environment
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
[runContext.generator...] // does something with the generator
|
|
60
|
-
})]
|
|
61
|
-
.run(); // runs the environment, promises a RunResult
|
|
62
|
-
[result.create().run()] // instantiates a new RunContext at the same directory
|
|
55
|
+
[.onEnvironment(env => {})]; // do something with the environment
|
|
56
|
+
|
|
57
|
+
[await result.create('another-generator').run();] // instantiates a new RunContext at the same directory
|
|
63
58
|
);
|
|
64
|
-
|
|
65
|
-
if (runResult) {
|
|
66
|
-
// Optional if context is executed at a temporary folder
|
|
67
|
-
runResult.restore();
|
|
68
|
-
}
|
|
69
|
-
});
|
|
59
|
+
|
|
70
60
|
it('runs correctly', () => {
|
|
71
61
|
// runs assertions using mem-fs.
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
75
|
-
[
|
|
76
|
-
[
|
|
77
|
-
[
|
|
78
|
-
[
|
|
62
|
+
[result.assertFile('file.txt');]
|
|
63
|
+
[result.assertNoFile('file.txt');]
|
|
64
|
+
[result.assertFileContent('file.txt', 'content');]
|
|
65
|
+
[result.assertEqualsFileContent('file.txt', 'content');]
|
|
66
|
+
[result.assertNoFileContent('file.txt', 'content');]
|
|
67
|
+
[result.assertJsonFileContent('file.txt', {});]
|
|
68
|
+
[result.assertNoJsonFileContent('file.txt', {});]
|
|
79
69
|
});
|
|
80
70
|
});
|
|
81
71
|
});
|
|
82
72
|
```
|
|
83
73
|
|
|
84
|
-
Convenience last RunResult instance:
|
|
85
|
-
|
|
86
|
-
```js
|
|
87
|
-
import helpers, { result } from 'yeoman-test';
|
|
88
|
-
|
|
89
|
-
describe('generator test', () => {
|
|
90
|
-
before(() => helpers.run('namespace'));
|
|
91
|
-
it('test', () => {
|
|
92
|
-
result.assert...;
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
```
|
|
96
|
-
|
|
97
74
|
Generator compose:
|
|
98
75
|
|
|
99
76
|
```js
|
package/dist/adapter.d.ts
CHANGED
|
@@ -3,3 +3,7 @@ export declare class TestAdapter extends BaseTestAdapter {
|
|
|
3
3
|
constructor(options?: TestAdapterOptions);
|
|
4
4
|
}
|
|
5
5
|
export { DummyPrompt, type DummyPromptOptions, type DummyPromptCallback, type TestAdapterOptions } from '@yeoman/adapter/testing';
|
|
6
|
+
export type AskedQuestions = Array<{
|
|
7
|
+
name: string;
|
|
8
|
+
answer: any;
|
|
9
|
+
}>;
|
package/dist/adapter.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line n/file-extension-in-import
|
|
2
1
|
import { TestAdapter as BaseTestAdapter } from '@yeoman/adapter/testing';
|
|
3
2
|
import { spy as sinonSpy, stub as sinonStub } from 'sinon';
|
|
4
3
|
export class TestAdapter extends BaseTestAdapter {
|
|
@@ -9,5 +8,4 @@ export class TestAdapter extends BaseTestAdapter {
|
|
|
9
8
|
});
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
|
-
// eslint-disable-next-line n/file-extension-in-import
|
|
13
11
|
export { DummyPrompt } from '@yeoman/adapter/testing';
|
package/dist/run-context.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type MemFsEditorFile, type MemFsEditor } from 'mem-fs-editor';
|
|
|
6
6
|
import type { DefaultGeneratorApi, DefaultEnvironmentApi } from '../types/type-helpers.js';
|
|
7
7
|
import RunResult, { type RunResultOptions } from './run-result.js';
|
|
8
8
|
import { type CreateEnv, type Dependency, type YeomanTest } from './helpers.js';
|
|
9
|
-
import { type DummyPromptOptions, type TestAdapterOptions } from './adapter.js';
|
|
9
|
+
import { type AskedQuestions, type DummyPromptOptions, type TestAdapterOptions } from './adapter.js';
|
|
10
10
|
/**
|
|
11
11
|
* Provides settings for creating a `RunContext`.
|
|
12
12
|
*/
|
|
@@ -48,6 +48,7 @@ export declare class RunContextBase<GeneratorType extends BaseGenerator = Defaul
|
|
|
48
48
|
memFs: Store<MemFsEditorFile>;
|
|
49
49
|
spawnStub?: any;
|
|
50
50
|
mockedGeneratorFactory: MockedGeneratorFactory;
|
|
51
|
+
readonly askedQuestions: AskedQuestions;
|
|
51
52
|
protected environmentPromise?: PromiseRunResult<GeneratorType>;
|
|
52
53
|
private args;
|
|
53
54
|
private options;
|
package/dist/run-context.js
CHANGED
|
@@ -5,7 +5,6 @@ import assert from 'node:assert';
|
|
|
5
5
|
import { EventEmitter } from 'node:events';
|
|
6
6
|
import process from 'node:process';
|
|
7
7
|
import { camelCase, kebabCase, merge as lodashMerge, set as lodashSet } from 'lodash-es';
|
|
8
|
-
// eslint-disable-next-line n/file-extension-in-import
|
|
9
8
|
import { resetFileCommitStates } from 'mem-fs-editor/state';
|
|
10
9
|
import { create as createMemFs } from 'mem-fs';
|
|
11
10
|
import tempDirectory from 'temp-dir';
|
|
@@ -27,6 +26,7 @@ export class RunContextBase extends EventEmitter {
|
|
|
27
26
|
memFs;
|
|
28
27
|
spawnStub;
|
|
29
28
|
mockedGeneratorFactory;
|
|
29
|
+
askedQuestions = [];
|
|
30
30
|
environmentPromise;
|
|
31
31
|
args = [];
|
|
32
32
|
options = {};
|
|
@@ -522,13 +522,21 @@ export class RunContextBase extends EventEmitter {
|
|
|
522
522
|
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
523
523
|
async build() {
|
|
524
524
|
await this.prepare();
|
|
525
|
+
const { askedQuestions, adapterOptions } = this;
|
|
526
|
+
const promptCallback = function (answer, options) {
|
|
527
|
+
const { question } = options;
|
|
528
|
+
if (question.name) {
|
|
529
|
+
askedQuestions.push({ name: question.name, answer });
|
|
530
|
+
}
|
|
531
|
+
return adapterOptions?.callback ? adapterOptions.callback.call(this, answer, options) : answer;
|
|
532
|
+
};
|
|
525
533
|
const testEnv = await this.helpers.createTestEnv(this.envOptions.createEnv, {
|
|
526
534
|
cwd: this.settings.forwardCwd ? this.targetDirectory : undefined,
|
|
527
535
|
sharedFs: this.memFs,
|
|
528
536
|
force: true,
|
|
529
537
|
skipCache: true,
|
|
530
538
|
skipInstall: true,
|
|
531
|
-
adapter: this.helpers.createTestAdapter({ ...this.adapterOptions, mockedAnswers: this.answers }),
|
|
539
|
+
adapter: this.helpers.createTestAdapter({ ...this.adapterOptions, mockedAnswers: this.answers, callback: promptCallback }),
|
|
532
540
|
...this.envOptions,
|
|
533
541
|
});
|
|
534
542
|
this.env = this.envCB ? (await this.envCB(testEnv)) ?? testEnv : testEnv;
|
|
@@ -580,6 +588,7 @@ export class RunContextBase extends EventEmitter {
|
|
|
580
588
|
envOptions: this.envOptions,
|
|
581
589
|
mockedGenerators: this.mockedGenerators,
|
|
582
590
|
helpers: this.helpers,
|
|
591
|
+
askedQuestions: this.askedQuestions,
|
|
583
592
|
};
|
|
584
593
|
}
|
|
585
594
|
/**
|
package/dist/run-result.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { BaseEnvironmentOptions, BaseGenerator, GetGeneratorConstructor } f
|
|
|
4
4
|
import type { DefaultEnvironmentApi, DefaultGeneratorApi } from '../types/type-helpers.js';
|
|
5
5
|
import { type RunContextSettings } from './run-context.js';
|
|
6
6
|
import { type YeomanTest } from './helpers.js';
|
|
7
|
+
import { type AskedQuestions } from './adapter.js';
|
|
7
8
|
/**
|
|
8
9
|
* Provides options for `RunResult`s.
|
|
9
10
|
*/
|
|
@@ -34,6 +35,7 @@ export type RunResultOptions<GeneratorType extends BaseGenerator> = {
|
|
|
34
35
|
spawnStub?: any;
|
|
35
36
|
settings: RunContextSettings;
|
|
36
37
|
helpers: YeomanTest;
|
|
38
|
+
askedQuestions: AskedQuestions;
|
|
37
39
|
};
|
|
38
40
|
/**
|
|
39
41
|
* This class provides utilities for testing generated content.
|
|
@@ -48,6 +50,7 @@ export default class RunResult<GeneratorType extends BaseGenerator = BaseGenerat
|
|
|
48
50
|
mockedGenerators: any;
|
|
49
51
|
options: RunResultOptions<GeneratorType>;
|
|
50
52
|
spawnStub?: any;
|
|
53
|
+
readonly askedQuestions: AskedQuestions;
|
|
51
54
|
constructor(options: RunResultOptions<GeneratorType>);
|
|
52
55
|
/**
|
|
53
56
|
* Create another RunContext reusing the settings.
|
package/dist/run-result.js
CHANGED
|
@@ -24,6 +24,7 @@ export default class RunResult {
|
|
|
24
24
|
mockedGenerators;
|
|
25
25
|
options;
|
|
26
26
|
spawnStub;
|
|
27
|
+
askedQuestions;
|
|
27
28
|
constructor(options) {
|
|
28
29
|
if (options.memFs && !options.cwd) {
|
|
29
30
|
throw new Error('CWD option is required for mem-fs tests');
|
|
@@ -36,6 +37,7 @@ export default class RunResult {
|
|
|
36
37
|
this.fs = this.memFs && createMemFsEditor(this.memFs);
|
|
37
38
|
this.mockedGenerators = options.mockedGenerators || {};
|
|
38
39
|
this.spawnStub = options.spawnStub;
|
|
40
|
+
this.askedQuestions = options.askedQuestions;
|
|
39
41
|
this.options = options;
|
|
40
42
|
}
|
|
41
43
|
/**
|