Skip to content

Commit

Permalink
Replace gulp/mocha/mockery/istanbul with Jest (#187)
Browse files Browse the repository at this point in the history
* Replace gulp/mocha/mockery/istanbul with Jest

… and add a yarn lock file.

* Fix test mocks

* Fix eslint ignore path

* Match generator-node

* Ignore templates when running tests

* Add .eslintignore

* Rename test directory in `USAGE`
  • Loading branch information
mischah authored Mar 28, 2017
1 parent f811a17 commit f6cc9ba
Show file tree
Hide file tree
Showing 10 changed files with 3,867 additions and 115 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app/templates
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_js:
- node
- 6
- 4
after_script: 'cat ./coverage/lcov.info | coveralls'
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ Scaffolds out a complete generator directory structure for you:
├── .travis.yml
├── .yo-rc.json
├── package.json
├── gulpfile.js
├── README.md
├── LICENSE
└── test/
└── __tests__/
└── app.js
```

Expand Down
25 changes: 4 additions & 21 deletions test/app.js → __tests__/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,14 @@
const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');
const mockery = require('mockery');
const generatorGeneratorPkg = require('../package.json');

describe('generator:app', () => {
before(() => {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false
});

mockery.registerMock('superb', () => {
return 'cat\'s meow';
});

mockery.registerMock('npm-name', () => {
return Promise.resolve(true);
});
});

after(() => {
mockery.disable();
});
jest.mock('superb', () => () => 'cat\'s meow');
jest.mock('npm-name', () => () => Promise.resolve(true));

describe('generator:app', () => {
describe('defaults', () => {
before(() => {
beforeEach(() => {
return helpers.run(path.join(__dirname, '../app'))
.withPrompts({
name: 'generator-temp',
Expand Down
18 changes: 3 additions & 15 deletions test/subgenerator.js → __tests__/subgenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@ const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');
const fs = require('fs');
const mockery = require('mockery');

describe('generator:subgenerator', () => {
before(() => {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false
});

mockery.registerMock('superb', () => {
return 'cat\'s meow';
});
jest.mock('superb', () => () => 'cat\'s meow');

describe('generator:subgenerator', () => {
beforeEach(() => {
return helpers.run(path.join(__dirname, '../subgenerator'))
.withArguments(['foo'])
.withOptions({
Expand All @@ -29,10 +21,6 @@ describe('generator:subgenerator', () => {
});
});

after(() => {
mockery.disable();
});

it('creates files', () => {
assert.file([
'generators/foo/index.js',
Expand Down
2 changes: 1 addition & 1 deletion app/USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Example:

generator/app/index.js: Main generator script
generator/app/templates/: Templates for files created by your generator
test/: Unit tests for your generator
__test__/: Unit tests for your generator
3 changes: 3 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ module.exports = class extends Generator {
devDependencies: {
'yeoman-test': generatorGeneratorPkg.devDependencies['yeoman-test'],
'yeoman-assert': generatorGeneratorPkg.devDependencies['yeoman-assert']
},
jest: {
testPathIgnorePatterns: ['templates']
}
});
pkg.keywords = pkg.keywords || [];
Expand Down
61 changes: 0 additions & 61 deletions gulpfile.js

This file was deleted.

31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
],
"repository": "yeoman/generator-generator",
"scripts": {
"test": "gulp",
"prepublish": "gulp prepublish"
"test": "jest",
"pretest": "eslint . --ignore-path .gitignore --fix",
"prepublish": "nsp check"
},
"engines": {
"node": ">=4.0.0"
Expand All @@ -36,27 +37,27 @@
"yosay": "^2.0.0"
},
"devDependencies": {
"eslint": "^3.15.0",
"coveralls": "^2.12.0",
"eslint": "^3.18.0",
"eslint-config-xo-space": "^0.16.0",
"gulp": "^3.9.1",
"gulp-coveralls": "^0.1.4",
"gulp-eslint": "^3.0.1",
"gulp-exclude-gitignore": "^1.1.1",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^3.0.1",
"gulp-nsp": "^2.4.2",
"gulp-plumber": "^1.1.0",
"mocha": "^3.2.0",
"mockery": "^2.0.0",
"jest": "^19.0.2",
"jest-cli": "^19.0.2",
"nsp": "^2.6.3",
"yeoman-assert": "^3.0.0",
"yeoman-test": "^1.6.0"
},
"eslintConfig": {
"extends": "xo-space",
"env": {
"mocha": true,
"jest": true
"jest": true,
"node": true
}
},
"jest": {
"testEnvironment": "node",
"testPathIgnorePatterns": [
"templates"
]
},
"license": "MIT"
}
Loading

0 comments on commit f6cc9ba

Please sign in to comment.