Skip to content

Commit

Permalink
feat(test): run e2e of generated project (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed May 20, 2016
1 parent 187770f commit d0dbd70
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
sudo: false
dist: trusty
sudo: required
env:
- NODE_VERSION=5 SCRIPT=lint
- NODE_VERSION=5 SCRIPT=test
Expand Down
3 changes: 2 additions & 1 deletion addon/ng2/tasks/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ module.exports = Task.extend({
var ui = this.ui;

return new Promise((resolve) => {
exec(`npm run e2e -- ${this.project.ngConfig.e2e.protractor.config}`, (err, stdout) => {
exec(`npm run e2e -- ${this.project.ngConfig.e2e.protractor.config}`, (err, stdout, stderr) => {
ui.writeLine(stdout);
if (err) {
ui.writeLine(stderr);
ui.writeLine(chalk.red('Some end-to-end tests failed, see above.'));
} else {
ui.writeLine(chalk.green('All end-to-end tests pass.'));
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"sinon": "^1.17.3",
"through": "^2.3.8",
"tslint": "^3.8.1",
"tree-kill": "^1.0.0",
"walk-sync": "^0.2.6"
}
}
94 changes: 91 additions & 3 deletions tests/e2e/e2e_workflow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var chai = require('chai');
var expect = chai.expect;
var conf = require('ember-cli/tests/helpers/conf');
var sh = require('shelljs');
var treeKill = require('tree-kill');
var child_process = require('child_process');
var ng = require('../helpers/ng');
var root = path.join(process.cwd(), 'tmp');

Expand Down Expand Up @@ -57,12 +59,12 @@ describe('Basic end-to-end Workflow', function () {
expect(path.basename(process.cwd())).to.equal('test-project');
});

it('Supports production builds via `ng build --environment=production`', function() {
it('Supports production builds via `ng build -prod`', function() {
this.timeout(420000);

// Can't user the `ng` helper because somewhere the environment gets
// Can't use the `ng` helper because somewhere the environment gets
// stuck to the first build done
sh.exec(`${ngBin} build --environment=production`);
sh.exec(`${ngBin} build -prod`);
expect(existsSync(path.join(process.cwd(), 'dist'))).to.be.equal(true);
var appBundlePath = path.join(process.cwd(), 'dist', 'app', 'index.js');
var appBundleContent = fs.readFileSync(appBundlePath, { encoding: 'utf8' });
Expand Down Expand Up @@ -112,6 +114,49 @@ describe('Basic end-to-end Workflow', function () {
});
});

it('Serve and run e2e tests after initial build', function () {
this.timeout(240000);

var ngServePid;

function executor(resolve, reject) {
var serveProcess = child_process.exec(`${ngBin} serve`);
var startedProtractor = false;
ngServePid = serveProcess.pid;

serveProcess.stdout.on('data', (data) => {
if (/Build successful/.test(data) && !startedProtractor) {
startedProtractor = true;
child_process.exec(`${ngBin} e2e`, (error, stdout, stderr) => {
if (error !== null) {
reject(stderr)
} else {
resolve();
}
});
} else if (/ failed with:/.test(data)) {
reject(data);
}
});

serveProcess.stderr.on('data', (data) => {
reject(data);
});
serveProcess.on('close', (code) => {
code === 0 ? resolve() : reject('ng serve command closed with error')
});
}

return new Promise(executor)
.then(() => {
if (ngServePid) treeKill(ngServePid);
})
.catch((msg) => {
if (ngServePid) treeKill(ngServePid);
throw new Error(msg);
});
});

it('Can create a test component using `ng generate component test-component`', function () {
this.timeout(10000);
return ng(['generate', 'component', 'test-component']).then(function () {
Expand Down Expand Up @@ -370,4 +415,47 @@ describe('Basic end-to-end Workflow', function () {
expect('build failed where it should have succeeded').to.equal('');
});
});

it('Serve and run e2e tests after all other commands', function () {
this.timeout(240000);

var ngServePid;

function executor(resolve, reject) {
var serveProcess = child_process.exec(`${ngBin} serve`);
var startedProtractor = false;
ngServePid = serveProcess.pid;

serveProcess.stdout.on('data', (data) => {
if (/Build successful/.test(data) && !startedProtractor) {
startedProtractor = true;
child_process.exec(`${ngBin} e2e`, (error, stdout, stderr) => {
if (error !== null) {
reject(stderr)
} else {
resolve();
}
});
} else if (/ failed with:/.test(data)) {
reject(data);
}
});

serveProcess.stderr.on('data', (data) => {
reject(data);
});
serveProcess.on('close', (code) => {
code === 0 ? resolve() : reject('ng serve command closed with error')
});
}

return new Promise(executor)
.then(() => {
if (ngServePid) treeKill(ngServePid);
})
.catch((msg) => {
if (ngServePid) treeKill(ngServePid);
throw new Error(msg);
});
});
});

0 comments on commit d0dbd70

Please sign in to comment.