yeoman-test 11.5.0 → 11.5.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/helpers.d.ts +6 -5
- package/dist/helpers.js +5 -2
- package/dist/run-context.d.ts +2 -2
- package/dist/run-context.js +6 -3
- package/dist/run-result.d.ts +2 -2
- package/package.json +2 -2
- package/types/type-helpers.d.ts +3 -11
package/dist/helpers.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type Dependency = string | Parameters<DefaultEnvironmentApi['register']>;
|
|
|
21
21
|
export declare class YeomanTest {
|
|
22
22
|
settings?: RunContextSettings;
|
|
23
23
|
environmentOptions?: EnvironmentOptions;
|
|
24
|
-
generatorOptions?: GeneratorOptions
|
|
24
|
+
generatorOptions?: Partial<Omit<GeneratorOptions, 'env' | 'resolved' | 'namespace'>>;
|
|
25
25
|
adapterOptions?: Omit<TestAdapterOptions, 'mockedAnswers'>;
|
|
26
26
|
defaultGenerator?: string;
|
|
27
27
|
importMeta?: Pick<ImportMeta, 'resolve'>;
|
|
@@ -126,7 +126,7 @@ export declare class YeomanTest {
|
|
|
126
126
|
* @param {Object} - Options to be passed to the environment
|
|
127
127
|
* const env = createTestEnv(require('yeoman-environment').createEnv);
|
|
128
128
|
*/
|
|
129
|
-
createTestEnv(environmentContructor?: CreateEnv, options?: EnvironmentOptions): Promise<
|
|
129
|
+
createTestEnv(environmentContructor?: CreateEnv, options?: EnvironmentOptions): Promise<DefaultEnvironmentApi>;
|
|
130
130
|
/**
|
|
131
131
|
* Creates a TestAdapter using helpers default options.
|
|
132
132
|
*/
|
|
@@ -136,21 +136,22 @@ export declare class YeomanTest {
|
|
|
136
136
|
* @return {RunContext}
|
|
137
137
|
*/
|
|
138
138
|
getRunContextType(): typeof RunContext;
|
|
139
|
+
createRunContext<GeneratorType extends BaseGenerator = DefaultGeneratorApi>(GeneratorOrNamespace: string | GetGeneratorConstructor<GeneratorType>, settings?: RunContextSettings, environmentOptions?: EnvironmentOptions): RunContext<GeneratorType>;
|
|
139
140
|
/**
|
|
140
141
|
* Run the provided Generator
|
|
141
142
|
* @param GeneratorOrNamespace - Generator constructor or namespace
|
|
142
143
|
*/
|
|
143
|
-
run<GeneratorType extends BaseGenerator = DefaultGeneratorApi>(GeneratorOrNamespace: string | GetGeneratorConstructor<GeneratorType>, settings?: RunContextSettings, environmentOptions?: EnvironmentOptions):
|
|
144
|
+
run<GeneratorType extends BaseGenerator = DefaultGeneratorApi>(GeneratorOrNamespace: string | GetGeneratorConstructor<GeneratorType>, settings?: RunContextSettings, environmentOptions?: EnvironmentOptions): ReturnType<typeof this.createRunContext<GeneratorType>>;
|
|
144
145
|
/**
|
|
145
146
|
* Run the default generator
|
|
146
147
|
*/
|
|
147
|
-
runDefault<GeneratorType extends BaseGenerator = BaseGenerator>(settings?: RunContextSettings, environmentOptions?: EnvironmentOptions):
|
|
148
|
+
runDefault<GeneratorType extends BaseGenerator = BaseGenerator>(settings?: RunContextSettings, environmentOptions?: EnvironmentOptions): ReturnType<typeof this.createRunContext<GeneratorType>>;
|
|
148
149
|
/**
|
|
149
150
|
* Prepare a run context
|
|
150
151
|
* @param {String|Function} GeneratorOrNamespace - Generator constructor or namespace
|
|
151
152
|
* @return {RunContext}
|
|
152
153
|
*/
|
|
153
|
-
create<GeneratorType extends BaseGenerator = DefaultGeneratorApi>(GeneratorOrNamespace: string | GetGeneratorConstructor<GeneratorType>, settings?: RunContextSettings, environmentOptions?: EnvironmentOptions):
|
|
154
|
+
create<GeneratorType extends BaseGenerator = DefaultGeneratorApi>(GeneratorOrNamespace: string | GetGeneratorConstructor<GeneratorType>, settings?: RunContextSettings, environmentOptions?: EnvironmentOptions): ReturnType<typeof this.createRunContext<GeneratorType>>;
|
|
154
155
|
/**
|
|
155
156
|
* Prepare temporary dir without generator support.
|
|
156
157
|
* Generator and environment will be undefined.
|
package/dist/helpers.js
CHANGED
|
@@ -249,6 +249,10 @@ export class YeomanTest {
|
|
|
249
249
|
getRunContextType() {
|
|
250
250
|
return RunContext;
|
|
251
251
|
}
|
|
252
|
+
createRunContext(GeneratorOrNamespace, settings, environmentOptions) {
|
|
253
|
+
const RunContext = this.getRunContextType();
|
|
254
|
+
return new RunContext(GeneratorOrNamespace, settings, environmentOptions, this);
|
|
255
|
+
}
|
|
252
256
|
/**
|
|
253
257
|
* Run the provided Generator
|
|
254
258
|
* @param GeneratorOrNamespace - Generator constructor or namespace
|
|
@@ -256,7 +260,6 @@ export class YeomanTest {
|
|
|
256
260
|
run(GeneratorOrNamespace, settings, environmentOptions) {
|
|
257
261
|
const contextSettings = cloneDeep(this.settings ?? {});
|
|
258
262
|
const generatorOptions = cloneDeep(this.generatorOptions ?? {});
|
|
259
|
-
const RunContext = this.getRunContextType();
|
|
260
263
|
if (typeof GeneratorOrNamespace === 'string') {
|
|
261
264
|
if (GeneratorOrNamespace.startsWith('.')) {
|
|
262
265
|
if (!this.importMeta) {
|
|
@@ -268,7 +271,7 @@ export class YeomanTest {
|
|
|
268
271
|
GeneratorOrNamespace = fileURLToPath(GeneratorOrNamespace);
|
|
269
272
|
}
|
|
270
273
|
}
|
|
271
|
-
const runContext =
|
|
274
|
+
const runContext = this.createRunContext(GeneratorOrNamespace, { ...contextSettings, ...settings }, environmentOptions).withOptions(generatorOptions);
|
|
272
275
|
if (settings?.autoCleanup !== false) {
|
|
273
276
|
testContext.startNewContext(runContext);
|
|
274
277
|
}
|
package/dist/run-context.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export declare class RunContextBase<GeneratorType extends BaseGenerator = Defaul
|
|
|
53
53
|
private args;
|
|
54
54
|
private options;
|
|
55
55
|
private answers?;
|
|
56
|
-
private readonly adapterOptions
|
|
56
|
+
private readonly adapterOptions;
|
|
57
57
|
private keepFsState?;
|
|
58
58
|
private readonly onGeneratorCallbacks;
|
|
59
59
|
private readonly onTargetDirectoryCallbacks;
|
|
@@ -153,7 +153,7 @@ export declare class RunContextBase<GeneratorType extends BaseGenerator = Defaul
|
|
|
153
153
|
* @param {Function} [cb] - callback who'll receive the folder path as argument
|
|
154
154
|
* @return {this} run context instance
|
|
155
155
|
*/
|
|
156
|
-
withEnvironment(callback:
|
|
156
|
+
withEnvironment(callback: (this: this, environment: DefaultEnvironmentApi) => DefaultEnvironmentApi | void): this;
|
|
157
157
|
/**
|
|
158
158
|
* Customize enviroment run method.
|
|
159
159
|
*
|
package/dist/run-context.js
CHANGED
|
@@ -263,9 +263,10 @@ export class RunContextBase extends EventEmitter {
|
|
|
263
263
|
}
|
|
264
264
|
// Add options as both kebab and camel case. This is to stay backward compatibles with
|
|
265
265
|
// the switch we made to meow for options parsing.
|
|
266
|
+
const optionsAny = options;
|
|
266
267
|
for (const key of Object.keys(options)) {
|
|
267
|
-
|
|
268
|
-
|
|
268
|
+
optionsAny[camelCase(key)] = optionsAny[key];
|
|
269
|
+
optionsAny[kebabCase(key)] = optionsAny[key];
|
|
269
270
|
}
|
|
270
271
|
this.options = { ...this.options, ...options };
|
|
271
272
|
return this;
|
|
@@ -290,7 +291,9 @@ export class RunContextBase extends EventEmitter {
|
|
|
290
291
|
*/
|
|
291
292
|
withAnswers(answers, options) {
|
|
292
293
|
this.answers = { ...this.answers, ...answers };
|
|
293
|
-
|
|
294
|
+
if (options) {
|
|
295
|
+
this.withAdapterOptions(options);
|
|
296
|
+
}
|
|
294
297
|
return this;
|
|
295
298
|
}
|
|
296
299
|
/**
|
package/dist/run-result.d.ts
CHANGED
|
@@ -44,13 +44,13 @@ export type RunResultOptions<GeneratorType extends BaseGenerator> = {
|
|
|
44
44
|
* This class provides utilities for testing generated content.
|
|
45
45
|
*/
|
|
46
46
|
export default class RunResult<GeneratorType extends BaseGenerator = BaseGenerator> {
|
|
47
|
-
env:
|
|
47
|
+
env: DefaultEnvironmentApi;
|
|
48
48
|
generator: GeneratorType;
|
|
49
49
|
cwd: string;
|
|
50
50
|
oldCwd: string;
|
|
51
51
|
memFs: Store<MemFsEditorFile>;
|
|
52
52
|
fs: MemFsEditor;
|
|
53
|
-
mockedGenerators:
|
|
53
|
+
mockedGenerators: Record<string, BaseGenerator>;
|
|
54
54
|
options: RunResultOptions<GeneratorType>;
|
|
55
55
|
spawnStub?: any;
|
|
56
56
|
readonly askedQuestions: AskedQuestions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yeoman-test",
|
|
3
|
-
"version": "11.5.
|
|
3
|
+
"version": "11.5.2",
|
|
4
4
|
"description": "Test utilities for Yeoman generators",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yeoman",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"fix": "prettier . --write && eslint . --fix",
|
|
41
41
|
"precommit": "lint-staged",
|
|
42
42
|
"prepare": "npm run build && husky",
|
|
43
|
-
"pretest": "eslint .",
|
|
43
|
+
"pretest": "eslint . && tsc -p tsconfig.spec.json",
|
|
44
44
|
"test": "vitest run --coverage"
|
|
45
45
|
},
|
|
46
46
|
"config": {
|
package/types/type-helpers.d.ts
CHANGED
|
@@ -3,15 +3,7 @@ import type GeneratorImplementation from 'yeoman-generator';
|
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
import type EnvironmentImplementation from 'yeoman-environment';
|
|
6
|
-
import type {
|
|
6
|
+
import type { IsAny } from 'type-fest';
|
|
7
7
|
|
|
8
|
-
export type DefaultGeneratorApi =
|
|
9
|
-
|
|
10
|
-
BaseGenerator,
|
|
11
|
-
typeof GeneratorImplementation extends BaseGenerator ? typeof GeneratorImplementation : BaseGenerator
|
|
12
|
-
>;
|
|
13
|
-
export type DefaultEnvironmentApi = IfAny<
|
|
14
|
-
typeof EnvironmentImplementation,
|
|
15
|
-
BaseEnvironment,
|
|
16
|
-
typeof EnvironmentImplementation extends BaseEnvironment ? typeof EnvironmentImplementation : BaseEnvironment
|
|
17
|
-
>;
|
|
8
|
+
export type DefaultGeneratorApi = IsAny<GeneratorImplementation> extends true ? BaseGenerator : GeneratorImplementation;
|
|
9
|
+
export type DefaultEnvironmentApi = IsAny<EnvironmentImplementation> extends true ? BaseEnvironment : EnvironmentImplementation;
|