UNPKG

3.62 kBMarkdownView Raw
1# yeoman-test
2[![NPM version][npm-image]][npm-url]
3[![NPM Test](https://github.com/yeoman/yeoman-test/workflows/NPM%20Test/badge.svg)](https://github.com/yeoman/yeoman-test/actions?query=workflow%3A%22NPM+Test%22)
4[![Integration Build](https://github.com/yeoman/yeoman-test/workflows/Integration%20Build/badge.svg)](https://github.com/yeoman/yeoman-test/actions?query=workflow%3A%22Integration+Build%22)
5[![Dependency Status][daviddm-image]][daviddm-url]
6[![Coverage percentage][coveralls-image]][coveralls-url]
7> Test utilities for Yeoman generators
8
9## Installation
10
11```sh
12$ npm install --save-dev yeoman-test
13```
14
15Install target environment and generator:
16
17```sh
18$ npm install --save-dev yeoman-generator@xxx yeoman-environment@xxx
19```
20
21## Usage
22
23Usage:
24
25```js
26describe('generator test', () => {
27 describe('test', () => {
28 let runResult;
29 beforeEach(async () => {
30 runResult = await helpers
31 .create( // instantiates RunContext
32 'namespace', // namespace or generator
33 {}, // test options
34 {} // environment options
35 )
36 [.cd(dir)] // runs the test inside a non temporary dir
37 [.doInDir(dir => {}) // prepares the test dir
38 [.withGenerators([])] // registers additional generators
39 [.withLookups({})] // runs Environment lookups
40 [.withOptions({})] // passes options to the generator
41 [.withLocalConfig({})] // sets the generator config as soon as it is instantiated
42 [.withPrompts()] // simulates the prompt answers
43 [.build(runContext => { // instantiates Environment/Generator
44 [runContext.env...] // does something with the environment
45 [runContext.generator...] // does something with the generator
46 })]
47 .run(); // runs the environment, promises a RunResult
48 [result.create().run()] // instantiates a new RunContext at the same directory
49 );
50 afterEach(() => {
51 if (runResult) {
52 runResult.restore();
53 }
54 });
55 it('runs correctly', () => {
56 // runs assertions using mem-fs.
57 [runResult.assertFile('file.txt');]
58 [runResult.assertNoFile('file.txt');]
59 [runResult.assertFileContent('file.txt', 'content');]
60 [runResult.assertEqualsFileContent('file.txt', 'content');]
61 [runResult.assertNoFileContent('file.txt', 'content');]
62 [runResult.assertJsonFileContent('file.txt', {});]
63 [runResult.assertNoJsonFileContent('file.txt', {});]
64 });
65 });
66});
67```
68
69[See our api documentation](https://yeoman.github.io/yeoman-test) for latest yeoman-test release.
70
71[See our api documentation](https://yeoman.github.io/yeoman-test/5.0.1) for yeoman-test 5.0.1. Use 5.x for yeoman-environment 2.x support.
72
73[See our api documentation](https://yeoman.github.io/yeoman-test/2.x) for yeoman-test 2.x.
74
75[See our documentation](http://yeoman.io/authoring/testing.html) for yeoman-test 2.x.
76
77## License
78
79MIT © [The Yeoman Team](http://yeoman.io)
80
81
82[npm-image]: https://badge.fury.io/js/yeoman-test.svg
83[npm-url]: https://npmjs.org/package/yeoman-test
84[travis-image]: https://travis-ci.org/yeoman/yeoman-test.svg?branch=master
85[travis-url]: https://travis-ci.org/yeoman/yeoman-test
86[daviddm-image]: https://david-dm.org/yeoman/yeoman-test.svg?theme=shields.io
87[daviddm-url]: https://david-dm.org/yeoman/yeoman-test
88[coveralls-image]: https://coveralls.io/repos/yeoman/yeoman-test/badge.svg
89[coveralls-url]: https://coveralls.io/r/yeoman/yeoman-test