Skip to content

Commit

Permalink
Ava added yeoman#759
Browse files Browse the repository at this point in the history
- Updated generator tests
- Added Ava sample test based in main.js' greetings function
  • Loading branch information
UlisesGascon committed Jun 5, 2019
1 parent c58037c commit f20f1bf
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 12 deletions.
4 changes: 4 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ module.exports = class extends Generator {
copy('demo_jest.js', '__test__/main.test.js');
}

if (this.includeUnit && this.unitTestFramework === 'ava') {
copy('demo_ava.js', '__test__/main.test.js');
}

let cssFile = `main.${this.includeSass ? 'scss' : 'css'}`;
copyTpl(cssFile, `app/styles/${cssFile}`, templateData);
}
Expand Down
24 changes: 24 additions & 0 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<%_ } -%>
},
"devDependencies": {
<%_ if (includeUnit && unitTestFramework === 'ava') { -%>
"ava": "^2.0.0",
<%_ } -%>
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"autoprefixer": "^9.4.4",
Expand All @@ -25,6 +28,9 @@
"cypress": "^3.3.1",
<%_ } -%>
"del": "^3.0.0",
<%_ if (includeUnit && unitTestFramework === 'ava') { -%>
"esm": "^3.2.25"
<%_ } -%>
"gulp": "^4.0.0",
"gulp-babel": "^8.0.0",
"gulp-cli": "^2.0.1",
Expand All @@ -51,12 +57,30 @@
<%_ if (includeModernizr) { -%>
"mkdirp": "^0.5.1",
<%_ } -%>
<%_ if (includeUnit && unitTestFramework === 'ava') { -%>
"nyc": "^14.1.1",
<%_ } -%>
<%_ if (includeE2e) { -%>
"start-server-and-test": "^1.9.1",
<%_ } -%>
"yargs": "12.0.5"
},
<%_ if (includeUnit && unitTestFramework === 'ava') { -%>
"ava": {
"files": [
"__test__/**/*.js"
],
"require": [
"esm"
]
},
<%_ } -%>
"scripts": {
<%_ if (includeUnit && unitTestFramework === "ava") { -%>
"test:unit": "ava --verbose",
"test:unit-coverage": "nyc ava",
"test:unit-watch": "ava --verbose --watch",
<%_ } -%>
<%_ if (includeUnit && unitTestFramework === "jest") { -%>
"test:unit": "jest",
"test:unit-coverage": "jest --coverage",
Expand Down
6 changes: 6 additions & 0 deletions app/templates/demo_ava.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import test from 'ava';
import { greeting } from '../app/scripts/main.js'

test('Say Allo!', t => {
t.is(greeting(), '\'Allo \'Allo!');
});
48 changes: 36 additions & 12 deletions test/tests-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@ const path = require('path');
const helpers = require('yeoman-test');
const assert = require('yeoman-assert');

function avaPresent() {
assert.fileContent('package.json', '"test:unit": "ava --verbose"');
assert.fileContent('package.json', '"test:unit-coverage": "nyc ava"');
assert.fileContent(
'package.json',
'"test:unit-watch": "ava --verbose --watch"'
);
assert.fileContent('package.json', '"ava": ');
assert.fileContent('package.json', '"nyc": ');
assert.fileContent('package.json', '"esm": ');
assert.fileContent('package.json', '"ava": {');
assert.file('__test__/main.test.js');
}

function avaNotPresent() {
assert.noFileContent('package.json', '"test:unit": "ava"');
assert.noFileContent('package.json', '"test:unit-coverage": "nyc ava"');
assert.noFileContent('package.json', '"test:unit-watch": "ava --watchAll"');
assert.noFileContent('package.json', '"ava": ');
assert.noFileContent('package.json', '"nyc": ');
assert.noFileContent('package.json', '"esm": ');
assert.noFileContent('package.json', '"ava": {');
}

function jestPresent() {
assert.fileContent('package.json', '"test:unit": "jest"');
assert.fileContent('package.json', '"test:unit-coverage": "jest --coverage"');
Expand All @@ -18,7 +42,6 @@ function jestNotPresent() {
);
assert.noFileContent('package.json', '"test:unit-watch": "jest --watchAll"');
assert.noFileContent('package.json', '"jest": ');
assert.noFile('__test__/main.test.js');
}

function unitPresent() {
Expand All @@ -31,6 +54,7 @@ function unitNotPresent() {
assert.noFileContent('app/index.html', 'type="module" src="scripts/main.js"');
assert.noFileContent('app/scripts/main.js', 'export function greeting');
assert.noFileContent('package.json', '"test:unit": "');
assert.noFile('__test__/main.test.js');
}

function e2ePresent() {
Expand Down Expand Up @@ -130,7 +154,7 @@ describe('Test handler', () => {
e2ePresent();
});

it.skip('Should add unit tests Basics', () => {
it('Should add unit tests Basics', () => {
unitPresent();
});

Expand All @@ -141,8 +165,8 @@ describe('Test handler', () => {
);
});

it.skip('Should add unit tests for Ava', () => {
//@TODO
it('Should add unit tests for Ava', () => {
avaPresent();
});

it('Should not add unit tests for Jest', () => {
Expand Down Expand Up @@ -186,8 +210,8 @@ describe('Test handler', () => {
jestPresent();
});

it.skip('Should not add unit tests for Ava', () => {
//@TODO
it('Should not add unit tests for Ava', () => {
avaNotPresent();
});

it.skip('Should not add unit tests for Jasmine', () => {
Expand Down Expand Up @@ -231,8 +255,8 @@ describe('Test handler', () => {
jestNotPresent();
});

it.skip('Should not add unit tests for Ava', () => {
//@TODO
it('Should not add unit tests for Ava', () => {
avaNotPresent();
});

it.skip('Should not add unit tests for Mocha (TDD)', () => {
Expand Down Expand Up @@ -276,8 +300,8 @@ describe('Test handler', () => {
jestNotPresent();
});

it.skip('Should not add unit tests for Ava', () => {
//@TODO
it('Should not add unit tests for Ava', () => {
avaNotPresent();
});

it.skip('Should not add unit tests for Mocha (BDD)', () => {
Expand Down Expand Up @@ -321,8 +345,8 @@ describe('Test handler', () => {
jestNotPresent();
});

it.skip('Should not add unit tests for Ava', () => {
//@TODO
it('Should not add unit tests for Ava', () => {
avaNotPresent();
});
});
});

0 comments on commit f20f1bf

Please sign in to comment.