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