yeoman-test 8.0.0-alpha.0 → 8.0.0-alpha.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/adapter.d.ts +14 -16
- package/dist/adapter.js +7 -4
- package/dist/helpers.d.ts +17 -19
- package/dist/helpers.js +37 -30
- package/dist/run-context.d.ts +24 -19
- package/dist/run-context.js +17 -13
- package/dist/run-result.d.ts +10 -10
- package/dist/test-context.d.ts +2 -1
- package/package.json +10 -12
package/dist/adapter.d.ts
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type
|
|
3
|
-
import type Logger from 'yeoman-environment/lib/util/log.js';
|
|
1
|
+
import type { PromptAnswers, PromptQuestion, Logger, InputOutputAdapter, PromptQuestions } from '@yeoman/types';
|
|
2
|
+
import { type PromptModule } from 'inquirer';
|
|
4
3
|
export type DummyPromptOptions = {
|
|
5
|
-
callback?: (answers:
|
|
4
|
+
callback?: (answers: PromptAnswers) => PromptAnswers;
|
|
6
5
|
throwOnMissingAnswer?: boolean;
|
|
7
6
|
};
|
|
8
7
|
export declare class DummyPrompt {
|
|
9
|
-
answers:
|
|
10
|
-
question:
|
|
11
|
-
callback: (answers:
|
|
8
|
+
answers: PromptAnswers;
|
|
9
|
+
question: PromptQuestion;
|
|
10
|
+
callback: (answers: PromptAnswers) => PromptAnswers;
|
|
12
11
|
throwOnMissingAnswer: boolean;
|
|
13
|
-
constructor(question:
|
|
14
|
-
run(): Promise<inquirer.Answers>;
|
|
12
|
+
constructor(question: PromptQuestion, _rl: any, answers: PromptAnswers, mockedAnswers?: PromptAnswers, options?: ((answers: PromptAnswers) => PromptAnswers) | DummyPromptOptions);
|
|
13
|
+
run(): Promise<import("inquirer").Answers>;
|
|
15
14
|
}
|
|
16
|
-
export declare class TestAdapter {
|
|
17
|
-
promptModule:
|
|
15
|
+
export declare class TestAdapter implements InputOutputAdapter {
|
|
16
|
+
promptModule: PromptModule;
|
|
18
17
|
diff: any;
|
|
19
|
-
log:
|
|
20
|
-
constructor(mockedAnswers?:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
18
|
+
log: Logger;
|
|
19
|
+
constructor(mockedAnswers?: PromptAnswers);
|
|
20
|
+
close(): void;
|
|
21
|
+
prompt<A extends PromptAnswers = PromptAnswers>(questions: PromptQuestions<A>, initialAnswers?: Partial<A> | undefined): Promise<A>;
|
|
24
22
|
}
|
package/dist/adapter.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable max-params */
|
|
2
2
|
import events from 'node:events';
|
|
3
3
|
import { PassThrough } from 'node:stream';
|
|
4
|
-
import inquirer from 'inquirer';
|
|
5
4
|
import { spy as sinonSpy, stub as sinonStub } from 'sinon';
|
|
5
|
+
import { createPromptModule } from 'inquirer';
|
|
6
6
|
export class DummyPrompt {
|
|
7
7
|
answers;
|
|
8
8
|
question;
|
|
@@ -64,7 +64,7 @@ export class TestAdapter {
|
|
|
64
64
|
diff;
|
|
65
65
|
log;
|
|
66
66
|
constructor(mockedAnswers) {
|
|
67
|
-
this.promptModule =
|
|
67
|
+
this.promptModule = createPromptModule({
|
|
68
68
|
input: new PassThrough(),
|
|
69
69
|
output: new PassThrough(),
|
|
70
70
|
skipTTYChecks: true,
|
|
@@ -98,7 +98,10 @@ export class TestAdapter {
|
|
|
98
98
|
this.log[methodName] = sinonStub().returns(this.log);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
close() {
|
|
102
|
+
// No empty
|
|
103
|
+
}
|
|
104
|
+
async prompt(questions, initialAnswers) {
|
|
105
|
+
return this.promptModule(questions, initialAnswers);
|
|
103
106
|
}
|
|
104
107
|
}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import GeneratorImplementation, { type StorageRecord, type BaseOptions as GeneratorOptions } from 'yeoman-generator';
|
|
2
2
|
import Environment from 'yeoman-environment';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { createEnv } from 'yeoman-environment';
|
|
4
|
+
import type { BaseEnvironmentOptions, BaseGenerator, GetGeneratorConstructor, PromptAnswers } from '@yeoman/types';
|
|
5
5
|
import type { SinonSpiedInstance } from 'sinon';
|
|
6
6
|
import { type DummyPromptOptions } from './adapter.js';
|
|
7
7
|
import RunContext, { BasicRunContext, type RunContextSettings } from './run-context.js';
|
|
8
8
|
/**
|
|
9
9
|
* Dependencies can be path (autodiscovery) or an array [<generator>, <name>]
|
|
10
10
|
*/
|
|
11
|
-
export type Dependency = string | Parameters<Environment['registerStub']
|
|
12
|
-
type
|
|
13
|
-
type GeneratorBuilder<GenParameter extends YeomanGenerator = YeomanGenerator> = (...args: ConstructorParameters<typeof YeomanGenerator<GenParameter['options']>>) => GenParameter;
|
|
14
|
-
export type GeneratorConstructor<GenParameter extends YeomanGenerator = YeomanGenerator> = GeneratorNew<GenParameter> | GeneratorBuilder<GenParameter>;
|
|
11
|
+
export type Dependency = string | Parameters<Environment['registerStub']>;
|
|
12
|
+
export type GeneratorFactory<GenParameter extends BaseGenerator = GeneratorImplementation> = GetGeneratorConstructor<GenParameter> | ((...args: ConstructorParameters<GetGeneratorConstructor<GenParameter>>) => GenParameter);
|
|
15
13
|
/**
|
|
16
14
|
* Collection of unit test helpers. (mostly related to Mocha syntax)
|
|
17
15
|
* @class YeomanTest
|
|
18
16
|
*/
|
|
19
17
|
export declare class YeomanTest {
|
|
20
18
|
settings?: RunContextSettings;
|
|
21
|
-
environmentOptions?:
|
|
19
|
+
environmentOptions?: BaseEnvironmentOptions;
|
|
22
20
|
generatorOptions?: GeneratorOptions;
|
|
23
21
|
/**
|
|
24
22
|
* @deprecated
|
|
@@ -53,28 +51,28 @@ export declare class YeomanTest {
|
|
|
53
51
|
* @example
|
|
54
52
|
* mockPrompt(angular, {'bootstrap': 'Y', 'compassBoostrap': 'Y'});
|
|
55
53
|
*/
|
|
56
|
-
mockPrompt(envOrGenerator:
|
|
54
|
+
mockPrompt(envOrGenerator: BaseGenerator | Environment, mockedAnswers?: PromptAnswers, options?: DummyPromptOptions): void;
|
|
57
55
|
/**
|
|
58
56
|
* @deprecated
|
|
59
57
|
* Restore defaults prompts on a generator.
|
|
60
58
|
* @param generator or environment
|
|
61
59
|
*/
|
|
62
|
-
restorePrompt(envOrGenerator:
|
|
60
|
+
restorePrompt(envOrGenerator: BaseGenerator | Environment): void;
|
|
63
61
|
/**
|
|
64
62
|
* @deprecated
|
|
65
63
|
* Provide mocked values to the config
|
|
66
64
|
* @param generator - a Yeoman generator
|
|
67
65
|
* @param localConfig - localConfig - should look just like if called config.getAll()
|
|
68
66
|
*/
|
|
69
|
-
mockLocalConfig(generator:
|
|
67
|
+
mockLocalConfig(generator: BaseGenerator, localConfig: StorageRecord): void;
|
|
70
68
|
/**
|
|
71
69
|
* Create a mocked generator
|
|
72
70
|
*/
|
|
73
|
-
createMockedGenerator(GeneratorClass?: typeof
|
|
71
|
+
createMockedGenerator(GeneratorClass?: typeof GeneratorImplementation): SinonSpiedInstance<typeof GeneratorImplementation>;
|
|
74
72
|
/**
|
|
75
73
|
* Create a simple, dummy generator
|
|
76
74
|
*/
|
|
77
|
-
createDummyGenerator<GenParameter extends
|
|
75
|
+
createDummyGenerator<GenParameter extends BaseGenerator = GeneratorImplementation>(Generator?: GetGeneratorConstructor<GenParameter>, contents?: Record<string, (...args: any[]) => void>): GenParameter;
|
|
78
76
|
/**
|
|
79
77
|
* Create a generator, using the given dependencies and controller arguments
|
|
80
78
|
* Dependecies can be path (autodiscovery) or an array [{generator}, {name}]
|
|
@@ -94,7 +92,7 @@ export declare class YeomanTest {
|
|
|
94
92
|
* ];
|
|
95
93
|
* var angular = createGenerator('angular:app', deps);
|
|
96
94
|
*/
|
|
97
|
-
createGenerator<GeneratorType extends
|
|
95
|
+
createGenerator<GeneratorType extends BaseGenerator = GeneratorImplementation>(name: string, dependencies: Dependency[], args?: string[], options?: GeneratorOptions, localConfigOnly?: boolean): Promise<GeneratorType>;
|
|
98
96
|
/**
|
|
99
97
|
* @deprecated
|
|
100
98
|
* Register a list of dependent generators into the provided env.
|
|
@@ -122,11 +120,11 @@ export declare class YeomanTest {
|
|
|
122
120
|
/**
|
|
123
121
|
* Creates a test environment.
|
|
124
122
|
*
|
|
125
|
-
* @param {Function}
|
|
126
|
-
* @param {Object}
|
|
123
|
+
* @param {Function} - environment constructor method.
|
|
124
|
+
* @param {Object} - Options to be passed to the environment
|
|
127
125
|
* const env = createTestEnv(require('yeoman-environment').createEnv);
|
|
128
126
|
*/
|
|
129
|
-
createTestEnv(envContructor?: (args
|
|
127
|
+
createTestEnv(envContructor?: (...args: unknown[]) => any, options?: BaseEnvironmentOptions): any;
|
|
130
128
|
/**
|
|
131
129
|
* Get RunContext type
|
|
132
130
|
* @return {RunContext}
|
|
@@ -136,13 +134,13 @@ export declare class YeomanTest {
|
|
|
136
134
|
* Run the provided Generator
|
|
137
135
|
* @param GeneratorOrNamespace - Generator constructor or namespace
|
|
138
136
|
*/
|
|
139
|
-
run<GeneratorType extends
|
|
137
|
+
run<GeneratorType extends BaseGenerator = GeneratorImplementation>(GeneratorOrNamespace: string | GeneratorFactory<GeneratorType>, settings?: RunContextSettings, envOptions?: BaseEnvironmentOptions): RunContext<GeneratorType>;
|
|
140
138
|
/**
|
|
141
139
|
* Prepare a run context
|
|
142
140
|
* @param {String|Function} GeneratorOrNamespace - Generator constructor or namespace
|
|
143
141
|
* @return {RunContext}
|
|
144
142
|
*/
|
|
145
|
-
create<GeneratorType extends
|
|
143
|
+
create<GeneratorType extends BaseGenerator = GeneratorImplementation>(GeneratorOrNamespace: string | GeneratorFactory<GeneratorType>, settings?: RunContextSettings, envOptions?: BaseEnvironmentOptions): RunContext<GeneratorType>;
|
|
146
144
|
/**
|
|
147
145
|
* Prepare temporary dir without generator support.
|
|
148
146
|
* Generator and environment will be undefined.
|
package/dist/helpers.js
CHANGED
|
@@ -4,7 +4,7 @@ import { resolve } from 'node:path';
|
|
|
4
4
|
import process from 'node:process';
|
|
5
5
|
import _ from 'lodash';
|
|
6
6
|
import { spy as sinonSpy, stub as sinonStub } from 'sinon';
|
|
7
|
-
import
|
|
7
|
+
import GeneratorImplementation from 'yeoman-generator';
|
|
8
8
|
import Environment from 'yeoman-environment';
|
|
9
9
|
import { DummyPrompt, TestAdapter } from './adapter.js';
|
|
10
10
|
import RunContext, { BasicRunContext } from './run-context.js';
|
|
@@ -76,6 +76,9 @@ export class YeomanTest {
|
|
|
76
76
|
*/
|
|
77
77
|
mockPrompt(envOrGenerator, mockedAnswers, options) {
|
|
78
78
|
const environment = 'env' in envOrGenerator ? envOrGenerator.env : envOrGenerator;
|
|
79
|
+
if (!environment.adapter) {
|
|
80
|
+
throw new Error('environment is not an Environment instance');
|
|
81
|
+
}
|
|
79
82
|
const { promptModule } = environment.adapter;
|
|
80
83
|
for (const name of Object.keys(promptModule.prompts)) {
|
|
81
84
|
promptModule.registerPrompt(name, class CustomDummyPrompt extends DummyPrompt {
|
|
@@ -106,12 +109,12 @@ export class YeomanTest {
|
|
|
106
109
|
/**
|
|
107
110
|
* Create a mocked generator
|
|
108
111
|
*/
|
|
109
|
-
createMockedGenerator(GeneratorClass = class MockedGenerator extends
|
|
112
|
+
createMockedGenerator(GeneratorClass = class MockedGenerator extends GeneratorImplementation {
|
|
110
113
|
}) {
|
|
111
114
|
const generator = sinonSpy(GeneratorClass);
|
|
112
115
|
for (const methodName of ['run', 'queueTasks', 'runWithOptions', 'queueOwnTasks']) {
|
|
113
116
|
if (GeneratorClass.prototype[methodName]) {
|
|
114
|
-
|
|
117
|
+
GeneratorClass.prototype[methodName] = sinonStub();
|
|
115
118
|
}
|
|
116
119
|
}
|
|
117
120
|
return generator;
|
|
@@ -119,13 +122,24 @@ export class YeomanTest {
|
|
|
119
122
|
/**
|
|
120
123
|
* Create a simple, dummy generator
|
|
121
124
|
*/
|
|
122
|
-
createDummyGenerator(Generator =
|
|
125
|
+
createDummyGenerator(Generator = GeneratorImplementation, contents = {
|
|
126
|
+
test() {
|
|
127
|
+
this.shouldRun = true;
|
|
128
|
+
},
|
|
129
|
+
}) {
|
|
123
130
|
class DummyGenerator extends Generator {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
131
|
+
constructor(...args) {
|
|
132
|
+
args[1].namespace = args[1].namespace ?? 'dummy';
|
|
133
|
+
args[1].resolved = args[1].resolved ?? 'dummy';
|
|
134
|
+
super(...args);
|
|
127
135
|
}
|
|
128
136
|
}
|
|
137
|
+
for (const [propName, propValue] of Object.entries(contents)) {
|
|
138
|
+
Object.defineProperty(DummyGenerator.prototype, propName, {
|
|
139
|
+
value: propValue ?? Object.create(null),
|
|
140
|
+
writable: true,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
129
143
|
return DummyGenerator;
|
|
130
144
|
}
|
|
131
145
|
/**
|
|
@@ -147,17 +161,10 @@ export class YeomanTest {
|
|
|
147
161
|
* ];
|
|
148
162
|
* var angular = createGenerator('angular:app', deps);
|
|
149
163
|
*/
|
|
150
|
-
createGenerator(name, dependencies, args, options, localConfigOnly = true) {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return maybeEnv.then(env => {
|
|
155
|
-
this.registerDependencies(env, dependencies);
|
|
156
|
-
return env.create(name, args, options);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
this.registerDependencies(maybeEnv, dependencies);
|
|
160
|
-
return maybeEnv.create(name, args, options);
|
|
164
|
+
async createGenerator(name, dependencies, args, options, localConfigOnly = true) {
|
|
165
|
+
const env = await this.createEnv([], { sharedOptions: { localConfigOnly } });
|
|
166
|
+
this.registerDependencies(env, dependencies);
|
|
167
|
+
return env.create(name, args, options);
|
|
161
168
|
}
|
|
162
169
|
/**
|
|
163
170
|
* @deprecated
|
|
@@ -202,14 +209,14 @@ export class YeomanTest {
|
|
|
202
209
|
/**
|
|
203
210
|
* Creates a test environment.
|
|
204
211
|
*
|
|
205
|
-
* @param {Function}
|
|
206
|
-
* @param {Object}
|
|
212
|
+
* @param {Function} - environment constructor method.
|
|
213
|
+
* @param {Object} - Options to be passed to the environment
|
|
207
214
|
* const env = createTestEnv(require('yeoman-environment').createEnv);
|
|
208
215
|
*/
|
|
209
216
|
createTestEnv(envContructor = this.createEnv, options = { localConfigOnly: true }) {
|
|
210
|
-
|
|
217
|
+
let envOptions = cloneDeep(this.environmentOptions ?? {});
|
|
211
218
|
if (typeof options === 'boolean') {
|
|
212
|
-
|
|
219
|
+
envOptions = {
|
|
213
220
|
newErrorHandler: true,
|
|
214
221
|
...envOptions,
|
|
215
222
|
sharedOptions: {
|
|
@@ -219,18 +226,18 @@ export class YeomanTest {
|
|
|
219
226
|
};
|
|
220
227
|
}
|
|
221
228
|
else {
|
|
222
|
-
|
|
223
|
-
newErrorHandler: true,
|
|
224
|
-
...envOptions,
|
|
225
|
-
...options,
|
|
226
|
-
};
|
|
227
|
-
options.sharedOptions = {
|
|
229
|
+
envOptions.sharedOptions = {
|
|
228
230
|
localConfigOnly: true,
|
|
229
231
|
...envOptions.sharedOptions,
|
|
230
232
|
...options.sharedOptions,
|
|
231
233
|
};
|
|
234
|
+
envOptions = {
|
|
235
|
+
newErrorHandler: true,
|
|
236
|
+
...envOptions,
|
|
237
|
+
...options,
|
|
238
|
+
};
|
|
232
239
|
}
|
|
233
|
-
return envContructor([],
|
|
240
|
+
return envContructor([], envOptions, new TestAdapter());
|
|
234
241
|
}
|
|
235
242
|
/**
|
|
236
243
|
* Get RunContext type
|
|
@@ -275,7 +282,7 @@ export class YeomanTest {
|
|
|
275
282
|
}
|
|
276
283
|
const defaultHelpers = new YeomanTest();
|
|
277
284
|
export default defaultHelpers;
|
|
278
|
-
export const createHelpers = options => {
|
|
285
|
+
export const createHelpers = (options) => {
|
|
279
286
|
const helpers = new YeomanTest();
|
|
280
287
|
Object.assign(helpers, options);
|
|
281
288
|
return helpers;
|
package/dist/run-context.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import { EventEmitter } from 'node:events';
|
|
3
|
-
import type
|
|
3
|
+
import { type Store } from 'mem-fs';
|
|
4
|
+
import type { BaseEnvironmentOptions, BaseGenerator, GetGeneratorConstructor, GetGeneratorOptions, PromptAnswers } from '@yeoman/types';
|
|
4
5
|
import type Environment from 'yeoman-environment';
|
|
5
|
-
import { type LookupOptions
|
|
6
|
+
import { type LookupOptions } from 'yeoman-environment';
|
|
7
|
+
import type GeneratorImplementation from 'yeoman-generator';
|
|
8
|
+
import type { StorageRecord } from 'yeoman-generator';
|
|
6
9
|
import { type MemFsEditor, type VinylMemFsEditorFile } from 'mem-fs-editor';
|
|
7
|
-
import { type Store } from 'mem-fs';
|
|
8
10
|
import RunResult, { type RunResultOptions } from './run-result.js';
|
|
9
|
-
import { type
|
|
11
|
+
import { type Dependency, type YeomanTest, type GeneratorFactory } from './helpers.js';
|
|
10
12
|
import { type DummyPromptOptions } from './adapter.js';
|
|
11
13
|
/**
|
|
12
14
|
* Provides settings for creating a `RunContext`.
|
|
@@ -32,14 +34,17 @@ export type RunContextSettings = {
|
|
|
32
34
|
*/
|
|
33
35
|
namespace?: string;
|
|
34
36
|
};
|
|
35
|
-
type PromiseRunResult<GeneratorType extends
|
|
36
|
-
type MockedGeneratorFactory = (GeneratorClass?:
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
type PromiseRunResult<GeneratorType extends BaseGenerator> = Promise<RunResult<GeneratorType>>;
|
|
38
|
+
type MockedGeneratorFactory = <GenParameter extends BaseGenerator = GeneratorImplementation>(GeneratorClass?: GetGeneratorConstructor<GenParameter>) => GenParameter;
|
|
39
|
+
type EnvOptions = BaseEnvironmentOptions & {
|
|
40
|
+
createEnv?: any;
|
|
41
|
+
};
|
|
42
|
+
export declare class RunContextBase<GeneratorType extends BaseGenerator = GeneratorImplementation> extends EventEmitter {
|
|
43
|
+
readonly mockedGenerators: Record<string, BaseGenerator>;
|
|
39
44
|
env: Environment;
|
|
40
45
|
generator: GeneratorType;
|
|
41
46
|
readonly settings: RunContextSettings;
|
|
42
|
-
readonly envOptions:
|
|
47
|
+
readonly envOptions: EnvOptions;
|
|
43
48
|
completed: boolean;
|
|
44
49
|
targetDirectory?: string;
|
|
45
50
|
editor: MemFsEditor;
|
|
@@ -73,7 +78,7 @@ export declare class RunContextBase<GeneratorType extends Generator = Generator>
|
|
|
73
78
|
* @param settings
|
|
74
79
|
* @return {this}
|
|
75
80
|
*/
|
|
76
|
-
constructor(generatorType?: string |
|
|
81
|
+
constructor(generatorType?: string | GeneratorFactory<GeneratorType>, settings?: RunContextSettings, envOptions?: EnvOptions, helpers?: YeomanTest);
|
|
77
82
|
/**
|
|
78
83
|
* Run the generator on the environment and promises a RunResult instance.
|
|
79
84
|
* @return {PromiseRunResult} Promise a RunResult instance.
|
|
@@ -159,7 +164,7 @@ export declare class RunContextBase<GeneratorType extends Generator = Generator>
|
|
|
159
164
|
* @param {Object} options - command line options (e.g. `--opt-one=foo`)
|
|
160
165
|
* @return {this}
|
|
161
166
|
*/
|
|
162
|
-
withOptions(options:
|
|
167
|
+
withOptions(options: Partial<Omit<GetGeneratorOptions<GeneratorType>, 'env' | 'namespace' | 'resolved'>>): this;
|
|
163
168
|
/**
|
|
164
169
|
* @deprecated
|
|
165
170
|
* Mock the prompt with dummy answers
|
|
@@ -169,14 +174,14 @@ export declare class RunContextBase<GeneratorType extends Generator = Generator>
|
|
|
169
174
|
* @param {Boolean} [options.throwOnMissingAnswer] - Throw if a answer is missing.
|
|
170
175
|
* @return {this}
|
|
171
176
|
*/
|
|
172
|
-
withPrompts(answers:
|
|
177
|
+
withPrompts(answers: PromptAnswers, options?: DummyPromptOptions): this;
|
|
173
178
|
/**
|
|
174
179
|
* Mock answers for prompts
|
|
175
180
|
* @param answers - Answers to the prompt questions
|
|
176
181
|
* @param options - Options or callback.
|
|
177
182
|
* @return {this}
|
|
178
183
|
*/
|
|
179
|
-
withAnswers(answers:
|
|
184
|
+
withAnswers(answers: PromptAnswers, options?: DummyPromptOptions): this;
|
|
180
185
|
/**
|
|
181
186
|
* Provide dependent generators
|
|
182
187
|
* @param {Array} dependencies - paths to the generators dependencies
|
|
@@ -216,7 +221,7 @@ export declare class RunContextBase<GeneratorType extends Generator = Generator>
|
|
|
216
221
|
* Mock the local configuration with the provided config
|
|
217
222
|
* @param localConfig - should look just like if called config.getAll()
|
|
218
223
|
*/
|
|
219
|
-
withLocalConfig(localConfig:
|
|
224
|
+
withLocalConfig(localConfig: StorageRecord): this;
|
|
220
225
|
/**
|
|
221
226
|
* Don't reset mem-fs state cleared to aggregate snapshots from multiple runs.
|
|
222
227
|
*/
|
|
@@ -269,7 +274,7 @@ export declare class RunContextBase<GeneratorType extends Generator = Generator>
|
|
|
269
274
|
* Build the generator and the environment.
|
|
270
275
|
* @return {RunContext|false} this
|
|
271
276
|
*/
|
|
272
|
-
|
|
277
|
+
build(): Promise<void>;
|
|
273
278
|
/**
|
|
274
279
|
* Return a promise representing the generator run process
|
|
275
280
|
* @return Promise resolved on end or rejected on error
|
|
@@ -289,10 +294,10 @@ export declare class RunContextBase<GeneratorType extends Generator = Generator>
|
|
|
289
294
|
*/
|
|
290
295
|
private setDir;
|
|
291
296
|
}
|
|
292
|
-
export default class RunContext<GeneratorType extends
|
|
293
|
-
then<TResult1 = RunResult<GeneratorType>, TResult2 = never>(onfulfilled?: ((value: RunResult<GeneratorType>) => TResult1 | PromiseLike<TResult1>) | undefined
|
|
294
|
-
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined
|
|
295
|
-
finally(onfinally?: (() => void) | undefined
|
|
297
|
+
export default class RunContext<GeneratorType extends BaseGenerator = GeneratorImplementation> extends RunContextBase<GeneratorType> implements Promise<RunResult<GeneratorType>> {
|
|
298
|
+
then<TResult1 = RunResult<GeneratorType>, TResult2 = never>(onfulfilled?: ((value: RunResult<GeneratorType>) => TResult1 | PromiseLike<TResult1>) | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined): Promise<TResult1 | TResult2>;
|
|
299
|
+
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined): Promise<RunResult<GeneratorType> | TResult>;
|
|
300
|
+
finally(onfinally?: (() => void) | undefined): Promise<RunResult<GeneratorType>>;
|
|
296
301
|
get [Symbol.toStringTag](): string;
|
|
297
302
|
}
|
|
298
303
|
export declare class BasicRunContext extends RunContext {
|
package/dist/run-context.js
CHANGED
|
@@ -5,11 +5,11 @@ import assert from 'node:assert';
|
|
|
5
5
|
import { EventEmitter } from 'node:events';
|
|
6
6
|
import process from 'node:process';
|
|
7
7
|
import _ from 'lodash';
|
|
8
|
-
import tempDirectory from 'temp-dir';
|
|
9
|
-
import { create as createMemFsEditor } from 'mem-fs-editor';
|
|
10
8
|
// eslint-disable-next-line n/file-extension-in-import
|
|
11
9
|
import { resetFileCommitStates } from 'mem-fs-editor/state';
|
|
12
10
|
import { create as createMemFs } from 'mem-fs';
|
|
11
|
+
import tempDirectory from 'temp-dir';
|
|
12
|
+
import { create as createMemFsEditor } from 'mem-fs-editor';
|
|
13
13
|
import RunResult from './run-result.js';
|
|
14
14
|
import defaultHelpers from './helpers.js';
|
|
15
15
|
import testContext from './test-context.js';
|
|
@@ -60,11 +60,6 @@ export class RunContextBase extends EventEmitter {
|
|
|
60
60
|
};
|
|
61
61
|
this.Generator = generatorType;
|
|
62
62
|
this.envOptions = envOptions;
|
|
63
|
-
this.withOptions({
|
|
64
|
-
force: true,
|
|
65
|
-
skipCache: true,
|
|
66
|
-
skipInstall: true,
|
|
67
|
-
});
|
|
68
63
|
this.oldCwd = this.settings.oldCwd;
|
|
69
64
|
if (this.settings.cwd) {
|
|
70
65
|
this.cd(this.settings.cwd);
|
|
@@ -217,10 +212,11 @@ export class RunContextBase extends EventEmitter {
|
|
|
217
212
|
* @param lookups - lookup to run.
|
|
218
213
|
*/
|
|
219
214
|
withLookups(lookups) {
|
|
220
|
-
return this.onEnvironment(env => {
|
|
215
|
+
return this.onEnvironment(async (env) => {
|
|
221
216
|
lookups = Array.isArray(lookups) ? lookups : [lookups];
|
|
222
217
|
for (const lookup of lookups) {
|
|
223
|
-
|
|
218
|
+
// eslint-disable-next-line no-await-in-loop
|
|
219
|
+
await env.lookup(lookup);
|
|
224
220
|
}
|
|
225
221
|
});
|
|
226
222
|
}
|
|
@@ -301,7 +297,7 @@ export class RunContextBase extends EventEmitter {
|
|
|
301
297
|
for (const dependency of dependencies) {
|
|
302
298
|
if (Array.isArray(dependency)) {
|
|
303
299
|
if (typeof dependency[0] === 'string') {
|
|
304
|
-
// eslint-disable-next-line no-await-in-loop
|
|
300
|
+
// eslint-disable-next-line no-await-in-loop
|
|
305
301
|
await env.register(...dependency);
|
|
306
302
|
}
|
|
307
303
|
else {
|
|
@@ -309,7 +305,7 @@ export class RunContextBase extends EventEmitter {
|
|
|
309
305
|
}
|
|
310
306
|
}
|
|
311
307
|
else {
|
|
312
|
-
// eslint-disable-next-line no-await-in-loop
|
|
308
|
+
// eslint-disable-next-line no-await-in-loop
|
|
313
309
|
await env.register(dependency);
|
|
314
310
|
}
|
|
315
311
|
}
|
|
@@ -470,11 +466,15 @@ export class RunContextBase extends EventEmitter {
|
|
|
470
466
|
* Build the generator and the environment.
|
|
471
467
|
* @return {RunContext|false} this
|
|
472
468
|
*/
|
|
469
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
473
470
|
async build() {
|
|
474
471
|
await this.prepare();
|
|
475
472
|
const testEnv = await this.helpers.createTestEnv(this.envOptions.createEnv, {
|
|
476
473
|
cwd: this.settings.forwardCwd ? this.targetDirectory : undefined,
|
|
477
474
|
sharedFs: this.memFs,
|
|
475
|
+
force: true,
|
|
476
|
+
skipCache: true,
|
|
477
|
+
skipInstall: true,
|
|
478
478
|
...this.options,
|
|
479
479
|
...this.envOptions,
|
|
480
480
|
});
|
|
@@ -492,8 +492,12 @@ export class RunContextBase extends EventEmitter {
|
|
|
492
492
|
const { resolved } = this.settings;
|
|
493
493
|
this.env.registerStub(this.Generator, namespace, resolved);
|
|
494
494
|
}
|
|
495
|
-
|
|
496
|
-
|
|
495
|
+
this.generator = await this.env.create(namespace, this.args, {
|
|
496
|
+
force: true,
|
|
497
|
+
skipCache: true,
|
|
498
|
+
skipInstall: true,
|
|
499
|
+
...this.options,
|
|
500
|
+
});
|
|
497
501
|
for (const onGeneratorCallback of this.onGeneratorCallbacks) {
|
|
498
502
|
// eslint-disable-next-line no-await-in-loop
|
|
499
503
|
await onGeneratorCallback.call(this, this.generator);
|
package/dist/run-result.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { type MemFsEditor } from 'mem-fs-editor';
|
|
2
1
|
import type { Store } from 'mem-fs';
|
|
3
|
-
import type
|
|
4
|
-
import type
|
|
2
|
+
import { type MemFsEditor } from 'mem-fs-editor';
|
|
3
|
+
import type { BaseEnvironment, BaseEnvironmentOptions, BaseGenerator } from '@yeoman/types';
|
|
4
|
+
import type GeneratorImplementation from 'yeoman-generator';
|
|
5
5
|
import { type RunContextSettings } from './run-context.js';
|
|
6
|
-
import { type YeomanTest } from './helpers.js';
|
|
6
|
+
import { type GeneratorFactory, type YeomanTest } from './helpers.js';
|
|
7
7
|
/**
|
|
8
8
|
* Provides options for `RunResult`s.
|
|
9
9
|
*/
|
|
10
|
-
export type RunResultOptions<GeneratorType extends
|
|
10
|
+
export type RunResultOptions<GeneratorType extends BaseGenerator> = {
|
|
11
11
|
generator: GeneratorType;
|
|
12
12
|
/**
|
|
13
13
|
* The environment of the generator.
|
|
14
14
|
*/
|
|
15
|
-
env:
|
|
16
|
-
envOptions:
|
|
15
|
+
env: BaseEnvironment;
|
|
16
|
+
envOptions: BaseEnvironmentOptions;
|
|
17
17
|
/**
|
|
18
18
|
* The working directory after running the generator.
|
|
19
19
|
*/
|
|
@@ -30,14 +30,14 @@ export type RunResultOptions<GeneratorType extends Generator> = {
|
|
|
30
30
|
/**
|
|
31
31
|
* The mocked generators of the context.
|
|
32
32
|
*/
|
|
33
|
-
mockedGenerators: Record<string,
|
|
33
|
+
mockedGenerators: Record<string, BaseGenerator>;
|
|
34
34
|
settings: RunContextSettings;
|
|
35
35
|
helpers: YeomanTest;
|
|
36
36
|
};
|
|
37
37
|
/**
|
|
38
38
|
* This class provides utilities for testing generated content.
|
|
39
39
|
*/
|
|
40
|
-
export default class RunResult<GeneratorType extends
|
|
40
|
+
export default class RunResult<GeneratorType extends BaseGenerator = GeneratorImplementation> {
|
|
41
41
|
env: any;
|
|
42
42
|
generator: GeneratorType;
|
|
43
43
|
cwd: string;
|
|
@@ -51,7 +51,7 @@ export default class RunResult<GeneratorType extends Generator = Generator> {
|
|
|
51
51
|
* Create another RunContext reusing the settings.
|
|
52
52
|
* See helpers.create api
|
|
53
53
|
*/
|
|
54
|
-
create(GeneratorOrNamespace:
|
|
54
|
+
create<GeneratorType extends BaseGenerator = GeneratorImplementation>(GeneratorOrNamespace: string | GeneratorFactory<GeneratorType>, settings?: RunContextSettings, envOptions?: BaseEnvironmentOptions): import("./run-context.js").default<GeneratorType>;
|
|
55
55
|
/**
|
|
56
56
|
* Return an object with fs changes.
|
|
57
57
|
* @param {Function} filter - parameter forwarded to mem-fs-editor#dump
|
package/dist/test-context.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { BaseGenerator } from '@yeoman/types';
|
|
1
2
|
import type RunContext from './run-context.js';
|
|
2
3
|
import type RunResult from './run-result.js';
|
|
3
4
|
declare class TestContext {
|
|
4
|
-
runResult?: RunResult
|
|
5
|
+
runResult?: RunResult<BaseGenerator>;
|
|
5
6
|
private runContext?;
|
|
6
7
|
startNewContext(runContext?: RunContext<any>): void;
|
|
7
8
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yeoman-test",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.2",
|
|
4
4
|
"description": "Test utilities for Yeoman generators",
|
|
5
5
|
"homepage": "http://yeoman.io/authoring/testing.html",
|
|
6
6
|
"author": "The Yeoman Team",
|
|
@@ -37,25 +37,23 @@
|
|
|
37
37
|
"prettier": "^2.2.1",
|
|
38
38
|
"prettier-plugin-packagejson": "^2.3.0",
|
|
39
39
|
"tui-jsdoc-template": "^1.2.2",
|
|
40
|
-
"typescript": "^
|
|
41
|
-
"xo": "^0.
|
|
42
|
-
"yeoman-environment": "^3.
|
|
43
|
-
"yeoman-generator": "^5.7.0"
|
|
40
|
+
"typescript": "^5.0.4",
|
|
41
|
+
"xo": "^0.54.2",
|
|
42
|
+
"yeoman-environment": "^3.16.1"
|
|
44
43
|
},
|
|
45
44
|
"dependencies": {
|
|
46
|
-
"@types/inquirer": "^
|
|
47
|
-
"@types
|
|
48
|
-
"
|
|
49
|
-
"inquirer": "^8.2.5",
|
|
45
|
+
"@types/inquirer": "^9.0.3",
|
|
46
|
+
"@yeoman/types": "^0.1.2",
|
|
47
|
+
"inquirer": "^9.2.2",
|
|
50
48
|
"lodash": "^4.17.21",
|
|
51
49
|
"mem-fs": "^3.0.0",
|
|
52
50
|
"mem-fs-editor": "^10.0.1",
|
|
53
51
|
"sinon": "^14.0.2",
|
|
54
|
-
"temp-dir": "^3.0.0"
|
|
52
|
+
"temp-dir": "^3.0.0",
|
|
53
|
+
"yeoman-generator": "^6.0.0-alpha.2"
|
|
55
54
|
},
|
|
56
55
|
"peerDependencies": {
|
|
57
|
-
"yeoman-environment": "^3.13.0"
|
|
58
|
-
"yeoman-generator": "*"
|
|
56
|
+
"yeoman-environment": "^3.13.0 || ^4.0.0-alpha.0"
|
|
59
57
|
},
|
|
60
58
|
"scripts": {
|
|
61
59
|
"test": "c8 esmocha",
|