diff --git a/app/index.js b/app/index.js index 8d96fa21..5a6feeef 100644 --- a/app/index.js +++ b/app/index.js @@ -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); } diff --git a/app/templates/_package.json b/app/templates/_package.json index 64491a41..2448f8c3 100644 --- a/app/templates/_package.json +++ b/app/templates/_package.json @@ -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", @@ -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", @@ -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", diff --git a/app/templates/demo_ava.js b/app/templates/demo_ava.js new file mode 100644 index 00000000..aafd702f --- /dev/null +++ b/app/templates/demo_ava.js @@ -0,0 +1,6 @@ +import test from 'ava'; +import { greeting } from '../app/scripts/main.js' + +test('Say Allo!', t => { + t.is(greeting(), '\'Allo \'Allo!'); +}); \ No newline at end of file diff --git a/test/tests-handler.js b/test/tests-handler.js index b66acc1a..23558d81 100644 --- a/test/tests-handler.js +++ b/test/tests-handler.js @@ -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"'); @@ -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() { @@ -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() { @@ -130,7 +154,7 @@ describe('Test handler', () => { e2ePresent(); }); - it.skip('Should add unit tests Basics', () => { + it('Should add unit tests Basics', () => { unitPresent(); }); @@ -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', () => { @@ -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', () => { @@ -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)', () => { @@ -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)', () => { @@ -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(); }); }); });