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 |
|
15 | Install target environment and generator:
|
16 |
|
17 | ```sh
|
18 | $ npm install --save-dev yeoman-generator@xxx yeoman-environment@xxx
|
19 | ```
|
20 |
|
21 | ## Usage
|
22 |
|
23 | Usage:
|
24 |
|
25 | ```
|
26 | describe('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)
|
70 | [See our api documentation](https://yeoman.github.io/yeoman-test/2.x) for yeoman-test 2.x.
|
71 |
|
72 | [See our documentation](http://yeoman.io/authoring/testing.html) for yeoman-test 2.x.
|
73 |
|
74 | ## License
|
75 |
|
76 | MIT © [The Yeoman Team](http://yeoman.io)
|
77 |
|
78 |
|
79 | [npm-image]: https://badge.fury.io/js/yeoman-test.svg
|
80 | [npm-url]: https://npmjs.org/package/yeoman-test
|
81 | [travis-image]: https://travis-ci.org/yeoman/yeoman-test.svg?branch=master
|
82 | [travis-url]: https://travis-ci.org/yeoman/yeoman-test
|
83 | [daviddm-image]: https://david-dm.org/yeoman/yeoman-test.svg?theme=shields.io
|
84 | [daviddm-url]: https://david-dm.org/yeoman/yeoman-test
|
85 | [coveralls-image]: https://coveralls.io/repos/yeoman/yeoman-test/badge.svg
|
86 | [coveralls-url]: https://coveralls.io/r/yeoman/yeoman-test
|