diff --git a/.travis.yml b/.travis.yml index 6508fbd3cb15..1483e447d760 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ -sudo: false +dist: trusty +sudo: required env: - NODE_VERSION=5 SCRIPT=lint - NODE_VERSION=5 SCRIPT=test diff --git a/addon/ng2/tasks/e2e.ts b/addon/ng2/tasks/e2e.ts index 16618f21d629..3d377db6ba80 100644 --- a/addon/ng2/tasks/e2e.ts +++ b/addon/ng2/tasks/e2e.ts @@ -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.')); diff --git a/package.json b/package.json index 861b29545dea..2e40130cc93a 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/tests/e2e/e2e_workflow.spec.js b/tests/e2e/e2e_workflow.spec.js index d05c94939cc2..f4ecf891a517 100644 --- a/tests/e2e/e2e_workflow.spec.js +++ b/tests/e2e/e2e_workflow.spec.js @@ -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'); @@ -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' }); @@ -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 () { @@ -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); + }); + }); });