Skip to content

Commit

Permalink
Add examples of snapshot assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
elementsweb committed Feb 25, 2018
1 parent 4b5c9eb commit 74411d6
Show file tree
Hide file tree
Showing 13 changed files with 6,208 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
example/
docs/
20 changes: 17 additions & 3 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# CHANGELOG
# Changelog
All notable changes to this project will be documented in this file.

## v1.0.0 (30 October 2017)
Initial release
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.0.1] - 2018-02-25
### Added
- Example in `/example` to demonstrate how snapshot assertion works
- Image of assertion test in README

### Changed
- Changelog format
- Upgraded to Jest 22 for testing

## [1.0.0] - 2017-10-30
### Added
- Initial release
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Assertion module for Yeoman generators, include comparing file with snapshot.

Extends the `yeoman-assert` module, which itself extends the native `assert` module. You only therefore need to import this assertion library to get all the functionality required for testing your Yeoman generator.

You can see an example of what a failed snapshot assertion looks like below:

![AssertionError for README.md:1 with expected and actual results](./docs/j154004-yeoman-assert.png)

## Install
```
npm install --save-dev @j154004/yeoman-assert
Expand All @@ -14,8 +18,11 @@ npm install --save-dev @j154004/yeoman-assert
## Usage
```
const assert = require('@j154004/yeoman-assert');
const path = require('path');
```

See the example generator in `/example` to see how to structure your tests and to see an example output from a failing test.

## API
### `snapshotContent`
* __filePath__ (String) Path to generated file.
Expand All @@ -35,4 +42,4 @@ Snapshot files should be stored in a `snapshot` directory where your tests are r
## Licence
[BSD license](/LICENSE) Copyright (c) elementsweb

`yeoman-assert` is licensed under BSD-2-Clause Copyright (c) Google
`yeoman-assert` is licensed under BSD-2-Clause Copyright (c) Google
Binary file added docs/j154004-yeoman-assert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @j154004/yeoman-assert example
A simple generator using `@j154004/yeoman-assert` in tests to check output file against a snapshot file.

## Usage
Run the tests (1 is designed to purposefully fail) with `npm t` to see the snapshot comparison output.
32 changes: 32 additions & 0 deletions example/generators/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';
const Generator = require('yeoman-generator');

module.exports = class extends Generator {
prompting() {
const prompts = [{
name: 'projectName',
message: 'Name for the project',
}];

return this.prompt(prompts).then(function (props) {
this.props = props;
}.bind(this));
}

writing() {
this.fs.copyTpl(
this.templatePath('README.md'),
this.destinationPath('README.md'),
{
projectName: this.props.projectName,
},
);
}

install() {
this.installDependencies({
bower: false,
npm: true,
});
}
}
1 change: 1 addition & 0 deletions example/generators/app/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# <%= projectName %>
Loading

0 comments on commit 74411d6

Please sign in to comment.