From e6830ebd665443275d1f60d926f4df159d21362c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Alvergnat?= Date: Sat, 17 Nov 2018 19:11:58 +0100 Subject: [PATCH] Upgrade yeoman-test to 2.0 This adds support for resolved and namespace options in run method, and sets some callback functions to optional. --- types/yeoman-test/index.d.ts | 44 ++++++++++++++++++++------ types/yeoman-test/yeoman-test-tests.ts | 5 +++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/types/yeoman-test/index.d.ts b/types/yeoman-test/index.d.ts index d6b2d50a09..abaad9ddb3 100644 --- a/types/yeoman-test/index.d.ts +++ b/types/yeoman-test/index.d.ts @@ -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 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -10,10 +10,17 @@ import Generator = require('yeoman-generator'); export interface Dictionary { [key: string]: T; } + export interface Constructor { 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 [, ] */ @@ -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, done: (...args: any[]) => void): void; +export function gruntfile(options: Dictionary, done?: (...args: any[]) => void): void; /** * Clean-up the test directory and cd into it. @@ -49,7 +56,7 @@ export function gruntfile(options: Dictionary, 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): 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, 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): this; + withPrompts(answers: Generator.Answers): this; /** * Provide dependent generators diff --git a/types/yeoman-test/yeoman-test-tests.ts b/types/yeoman-test/yeoman-test-tests.ts index c5136c6089..2dba4923a2 100644 --- a/types/yeoman-test/yeoman-test-tests.ts +++ b/types/yeoman-test/yeoman-test-tests.ts @@ -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 => { /* ... */ })