Skip to content

Commit

Permalink
Added e2e testing with Cypress
Browse files Browse the repository at this point in the history
- Added test
- Added tasks and dependencies to generated project
- Added copy tasks to main writing task
  • Loading branch information
UlisesGascon committed Jun 5, 2019
1 parent 6bf3174 commit f541cd6
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 50 deletions.
4 changes: 4 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ module.exports = class extends Generator {
copy('modernizr.json', 'modernizr.json');
}

if (this.includeE2e) {
copy('demo_cypress.js', 'cypress/integration/index_spec.js');
}

let cssFile = `main.${this.includeSass ? 'scss' : 'css'}`;
copyTpl(cssFile, `app/styles/${cssFile}`, templateData);
}
Expand Down
15 changes: 13 additions & 2 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"browser-sync": "^2.2.1",
"cross-env": "^5.2.0",
"cssnano": "^4.1.7",
<%_ if (includeE2e) { -%>
"cypress": "^3.3.1",
<%_ } -%>
"del": "^3.0.0",
"gulp": "^4.0.0",
"gulp-babel": "^8.0.0",
Expand All @@ -45,15 +48,23 @@
<%_ if (includeModernizr) { -%>
"mkdirp": "^0.5.1",
<%_ } -%>
"mocha": "^5.2.0",
<%_ if (includeE2e) { -%>
"start-server-and-test": "^1.9.1",
<%_ } -%>
"yargs": "12.0.5"
},
"scripts": {
<%_ if (includeE2e) { -%>
"test:e2e-open": "cypress open",
"test:e2e": "start-server-and-test start http://localhost:9000 test:e2e-open",
<%_ } -%>
"serve:test": "cross-env NODE_ENV=test gulp serve",
"serve:dist": "cross-env NODE_ENV=production gulp serve",
"start": "gulp serve",
"build": "cross-env NODE_ENV=production gulp",
"test": "npm run serve:test",
<%_ if (includeE2e) { -%>
"test": "npm run test:e2e",
<%_ } -%>
"tasks": "gulp --tasks"
},
"browserslist": [
Expand Down
14 changes: 14 additions & 0 deletions app/templates/demo_cypress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe('My First Test', function() {
beforeEach(() => {
cy.visit('http://localhost:9000')
})
it('Should body exist', function() {
cy.get('body')
.should('be.visible')
})

it('Should contains title', function(){
cy.get("h1")
.should('have.text', `'Allo, 'Allo!`)
})
})
1 change: 0 additions & 1 deletion test/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe('general', () => {
assert.fileContent('package.json', '"serve:dist"');
assert.fileContent('package.json', '"start"');
assert.fileContent('package.json', '"build"');
assert.fileContent('package.json', '"test"');
assert.fileContent('package.json', '"tasks"');
});

Expand Down
108 changes: 61 additions & 47 deletions test/tests-handler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
const path = require('path');
const helpers = require('yeoman-test');
//const assert = require('yeoman-assert');

describe.skip('Test handler', () => {
const assert = require('yeoman-assert');

function e2ePresent() {
assert.fileContent('package.json', '"cypress": "');
assert.fileContent('package.json', '"start-server-and-test": "');
assert.fileContent('package.json', '"test:e2e-open": "');
assert.fileContent('package.json', '"test:e2e": "');
}

function e2eNotPresent() {
assert.noFileContent('package.json', '"cypress": "');
assert.noFileContent('package.json', '"start-server-and-test": "');
assert.noFileContent('package.json', '"test:e2e-open": "');
assert.noFileContent('package.json', '"test:e2e": "');
}

describe('Test handler', () => {
describe('When user refused unit and e2e tests directly', () => {
before(done => {
helpers
Expand All @@ -11,50 +25,50 @@ describe.skip('Test handler', () => {
.on('end', done);
});

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

it('Should not add e2e tests', () => {
//@TODO
e2eNotPresent();
});
});

describe.skip('When user agrees to add test but avoid to pick unit and e2e test', () => {
describe('When user agrees to add test but avoid to pick unit and e2e test', () => {
before(done => {
helpers
.run(path.join(__dirname, '../app'))
.withPrompts({ includeTest: true, testsWanted: [] })
.on('end', done);
});

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

it('Should not add e2e tests', () => {
//@TODO
e2eNotPresent();
});
});

describe.skip('When user agrees to test only e2e', () => {
describe('When user agrees to test only e2e', () => {
before(done => {
helpers
.run(path.join(__dirname, '../app'))
.withPrompts({ includeTest: true, testsWanted: [] })
.withPrompts({ includeTest: true, testsWanted: ['includeE2e'] })
.on('end', done);
});

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

it('Should add e2e tests', () => {
//@TODO
e2ePresent();
});
});

describe.skip('When user agrees to e2e testing add Unit Testing (Ava)', () => {
describe('When user agrees to e2e testing add Unit Testing (Ava)', () => {
before(done => {
helpers
.run(path.join(__dirname, '../app'))
Expand All @@ -67,31 +81,31 @@ describe.skip('Test handler', () => {
});

it('Should add e2e tests', () => {
//@TODO
e2ePresent();
});

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

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

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

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

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

describe.skip('When user agrees to add only Unit Testing (Jest)', () => {
describe('When user agrees to add only Unit Testing (Jest)', () => {
before(done => {
helpers
.run(path.join(__dirname, '../app'))
Expand All @@ -104,31 +118,31 @@ describe.skip('Test handler', () => {
});

it('Should not add e2e tests', () => {
//@TODO
e2eNotPresent();
});

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

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

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

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

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

describe.skip('When user agrees to add only Unit Testing (Jasmine)', () => {
describe('When user agrees to add only Unit Testing (Jasmine)', () => {
before(done => {
helpers
.run(path.join(__dirname, '../app'))
Expand All @@ -141,31 +155,31 @@ describe.skip('Test handler', () => {
});

it('Should not add e2e tests', () => {
//@TODO
e2eNotPresent();
});

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

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

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

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

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

describe.skip('When user agrees to add only Unit Testing for Mocha (TDD)', () => {
describe('When user agrees to add only Unit Testing for Mocha (TDD)', () => {
before(done => {
helpers
.run(path.join(__dirname, '../app'))
Expand All @@ -178,31 +192,31 @@ describe.skip('Test handler', () => {
});

it('Should not add e2e tests', () => {
//@TODO
e2eNotPresent();
});

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

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

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

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

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

describe.skip('When user agrees to add only Unit Testing for Mocha (BDD)', () => {
describe('When user agrees to add only Unit Testing for Mocha (BDD)', () => {
before(done => {
helpers
.run(path.join(__dirname, '../app'))
Expand All @@ -215,26 +229,26 @@ describe.skip('Test handler', () => {
});

it('Should not add e2e tests', () => {
//@TODO
e2eNotPresent();
});

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

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

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

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

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

0 comments on commit f541cd6

Please sign in to comment.