Upgrade yeoman-test to 2.0

This adds support for resolved and namespace options in run method, and sets some callback functions to optional.
This commit is contained in:
Rémi Alvergnat
2018-12-03 23:20:38 +01:00
parent d202969f89
commit e6830ebd66
2 changed files with 40 additions and 9 deletions
+35 -9
View File
@@ -1,4 +1,4 @@
// Type definitions for yeoman-test 1.7
// Type definitions for yeoman-test 2.0
// Project: https://github.com/yeoman/yeoman-test
// Definitions by: Ika <https://github.com/ikatyang>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -10,10 +10,17 @@ import Generator = require('yeoman-generator');
export interface Dictionary<T> {
[key: string]: T;
}
export interface Constructor<T> {
new (...args: any[]): T;
}
// Environment from yeoman-environment
export interface Env extends EventEmitter {
queues: string[];
enforceUpdate(env: Env): this;
}
/**
* Dependecies can be path (autodiscovery) or an array [<generator>, <name>]
*/
@@ -37,7 +44,7 @@ export function setUpTestDirectory(dir: string): (done: (...args: any[]) => void
* @param options - Grunt configuration
* @param done - callback to call on completion
*/
export function gruntfile(options: Dictionary<any>, done: (...args: any[]) => void): void;
export function gruntfile(options: Dictionary<any>, done?: (...args: any[]) => void): void;
/**
* Clean-up the test directory and cd into it.
@@ -49,7 +56,7 @@ export function gruntfile(options: Dictionary<any>, done: (...args: any[]) => vo
* fs.writeFileSync('testfile', 'Roses are red.');
* });
*/
export function testDirectory(dir: string, cb: (error?: any) => void): void;
export function testDirectory(dir: string, cb?: (error?: any) => void): void;
/**
* Answer prompt questions for the passed-in generator
@@ -60,7 +67,7 @@ export function testDirectory(dir: string, cb: (error?: any) => void): void;
* @example
* mockPrompt(angular, {'bootstrap': 'Y', 'compassBoostrap': 'Y'});
*/
export function mockPrompt(generator: Generator, answers: Dictionary<any>): void;
export function mockPrompt(generator: Generator, answers: Generator.Answers): void;
/**
* Restore defaults prompts on a generator.
@@ -105,7 +112,7 @@ export function createGenerator(name: string, dependencies: Dependency[], args?:
*
* @param dependencies - paths to the generators dependencies
*/
export function registerDependencies(env: any, dependencies: Dependency[]): void;
export function registerDependencies(env: Env, dependencies: Dependency[]): void;
/**
* Run the provided Generator
@@ -118,7 +125,18 @@ export interface RunContextSettings {
* Automatically run this generator in a tmp dir
* @default true
*/
tmpdir: boolean;
tmpdir?: boolean;
/**
* File path to the generator (only used if Generator is a constructor)
*/
resolved?: string;
/**
* Namespace (only used if Generator is a constructor)
* @default 'gen:test'
*/
namespace?: string;
}
export interface RunContextConstructor {
@@ -132,7 +150,15 @@ export interface RunContextConstructor {
new (Generator: string | Constructor<Generator>, settings?: RunContextSettings): RunContext;
}
export interface RunContext extends EventEmitter {
export interface RunContext extends RunContextConstructor, EventEmitter {
ran: boolean;
inDirSet: boolean;
args: string[];
options: {};
answers: Generator.Answers;
localConfig: {};
dependencies: Dependency[];
/**
* Hold the execution until the returned callback is triggered
* @return Callback to notify the normal execution can resume
@@ -162,7 +188,7 @@ export interface RunContext extends EventEmitter {
* @param [cb] - callback who'll receive the folder path as argument
* @return run context instance
*/
inDir(dirPath: string, cb: (folderPath: string) => void): this;
inDir(dirPath: string, cb?: (folderPath: string) => void): this;
/**
* Change directory without deleting directory content.
@@ -204,7 +230,7 @@ export interface RunContext extends EventEmitter {
* Mock the prompt with dummy answers
* @param answers - Answers to the prompt questions
*/
withPrompts(answers: Dictionary<any>): this;
withPrompts(answers: Generator.Answers): this;
/**
* Provide dependent generators
+5
View File
@@ -57,6 +57,11 @@ helpers.run(path.join(__dirname, '../app')).withGenerators([
[helpers.createDummyGenerator(), 'karma:app'],
]);
helpers.run(Generator, {
resolved: '../app',
namespace: 'custom:generator'
});
before(done => {
helpers.run(path.join(__dirname, '../app'))
.on('error', error => { /* ... */ })