# yeoman-test

> Test utilities for Yeoman generators

Latest version **11.8.2** (published 2026-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install yeoman-test
pnpm add yeoman-test
yarn add yeoman-test
bun add yeoman-test
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 11.8.2 |
| Published | 2026-09-07 |
| First published | 2015-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^20.6.1 \|\| >=22 |
| Dependencies | 4 |
| Unpacked size | 89.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 45 |
| Author | The Yeoman Team |
| Maintainers | sboudrias, mischah, ulisesgascon, mshima, joshuakgoldberg, eddiemonge, arthurvr |
| Keywords | yeoman, unit test |

## Links

- npm: https://www.npmjs.com/package/yeoman-test
- Repository: https://github.com/yeoman/yeoman-test
- Homepage: http://yeoman.io/authoring/testing.html
- Issues: https://github.com/yeoman/yeoman-test/issues
- npm.io page: https://npm.io/package/yeoman-test

## Dependencies (4)

- [lodash-es](https://npm.io/package/lodash-es.md) ^4.18.1
- [type-fest](https://npm.io/package/type-fest.md) ^5.6.0
- [signal-exit](https://npm.io/package/signal-exit.md) ^4.1.0
- [mem-fs-editor](https://npm.io/package/mem-fs-editor.md) ^12.0.3

## Recent versions

- 11.8.2 (latest) — 2026-09-07
- 11.0.0-0 (next) — 2025-09-23
- 4.0.0-beta.0 (next-4) — 2020-11-18
- 11.8.1 — 2026-09-06
- 11.8.0 — 2026-09-06
- 11.7.0 — 2026-09-02
- 11.6.0 — 2026-06-13
- 11.5.3 — 2026-06-09
- 11.5.2 — 2026-05-07
- 11.5.1 — 2026-05-06
- 11.5.0 — 2026-05-06
- 11.4.2 — 2026-04-30
- 11.4.1 — 2026-04-30
- 11.4.0 — 2026-04-30
- 11.3.1 — 2026-02-28
- … 71 more at https://npm.io/package/yeoman-test/versions

## README

# yeoman-test

[![NPM version][npm-image]][npm-url]
[![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)
[![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)
[![Dependency Status][daviddm-image]][daviddm-url]
[![Coverage percentage][coveralls-image]][coveralls-url]

> Test utilities for Yeoman generators

## Installation

```sh
$ npm install --save-dev yeoman-test
```

Install target environment and generator:

```sh
$ npm install --save-dev yeoman-generator@xxx yeoman-environment@xxx
```

## Usage

Usage using the convenience last RunResult instance:

```js
import helpers, { result } from 'yeoman-test';

describe('generator test', () => {
  describe('test', () => {
    beforeEach(async () => {
      await helpers
        .run(                   // instantiates RunContext
          'namespace',             // namespace or generator
          {},                      // test options
          {}                       // environment options
        )
        [.cd(dir)]                  // runs the test inside a non temporary dir
        [.onTargetDirectory(dir => {})        // prepares the test dir
        [.withGenerators([])]       // registers additional generators
        [.withLookups({})]          // runs Environment lookups
        [.withOptions({})]          // passes options to the generator
        [.withLocalConfig({})]      // sets the generator config as soon as it is instantiated
        [.withAnswers()]            // simulates the prompt answers
        [.withMockedGenerators(['namespace', ...])]      // adds a mocked generator to the namespaces
        [.withFiles({
          'foo.txt': 'bar',
          'test.json', { content: true },
        })]                         // add files to mem-fs
        [.withYoRc({ 'generator-foo': { bar: {} } })]    // add config to .yo-rc.json
        [.withYoRcConfig('generator-foo.bar', { : {} })] // same as above
        [.commitFiles()]            // commit mem-fs files to disk
        [.onGenerator(gen => {})]   // do something with the generator
        [.onEnvironment(env => {})]; // do something with the environment

      [await result.create('another-generator').run();] // instantiates a new RunContext at the same directory
    );

    it('runs correctly', () => {
      // runs assertions using mem-fs.
      [result.assertFile('file.txt');]
      [result.assertNoFile('file.txt');]
      [result.assertFileContent('file.txt', 'content');]
      [result.assertEqualsFileContent('file.txt', 'content');]
      [result.assertNoFileContent('file.txt', 'content');]
      [result.assertJsonFileContent('file.txt', {});]
      [result.assertNoJsonFileContent('file.txt', {});]
    });
  });
});
```

Generator compose:

```js
import assert from 'assert';
import helpers, { result } from 'yeoman-test';

describe('my-gen', () => {
  before(() => helpers.run('my-gen').withMockedGenerator(['composed-gen']));
  it('should compose with composed-gen', () => {
    assert(result.mockedGenerators['composed-gen'].calledOnce);
  });
});
```

Generic test folder:

```js
import helpers, { result } from 'yeoman-test';

describe('generic test', () => {
  before(() => helpers.prepareTemporaryDir());
  it('test', () => {
    result.assert...;
  });
});
```

[See our api documentation](https://yeoman.github.io/yeoman-test) for latest yeoman-test release.

[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.

[See our api documentation](https://yeoman.github.io/yeoman-test/2.x) for yeoman-test 2.x.

[See our documentation](http://yeoman.io/authoring/testing.html) for yeoman-test 2.x.

## License

MIT © [The Yeoman Team](http://yeoman.io)

[npm-image]: https://badge.fury.io/js/yeoman-test.svg
[npm-url]: https://npmjs.org/package/yeoman-test
[travis-image]: https://travis-ci.org/yeoman/yeoman-test.svg?branch=master
[travis-url]: https://travis-ci.org/yeoman/yeoman-test
[daviddm-image]: https://david-dm.org/yeoman/yeoman-test.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/yeoman/yeoman-test
[coveralls-image]: https://coveralls.io/repos/yeoman/yeoman-test/badge.svg
[coveralls-url]: https://coveralls.io/r/yeoman/yeoman-test

---
_Source: https://npm.io/package/yeoman-test · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
