Skip to content

Commit d0dbd70

Browse files
committed
feat(test): run e2e of generated project (#490)
1 parent 187770f commit d0dbd70

File tree

4 files changed

+96
-5
lines changed

4 files changed

+96
-5
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
sudo: false
1+
dist: trusty
2+
sudo: required
23
env:
34
- NODE_VERSION=5 SCRIPT=lint
45
- NODE_VERSION=5 SCRIPT=test

addon/ng2/tasks/e2e.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ module.exports = Task.extend({
88
var ui = this.ui;
99

1010
return new Promise((resolve) => {
11-
exec(`npm run e2e -- ${this.project.ngConfig.e2e.protractor.config}`, (err, stdout) => {
11+
exec(`npm run e2e -- ${this.project.ngConfig.e2e.protractor.config}`, (err, stdout, stderr) => {
1212
ui.writeLine(stdout);
1313
if (err) {
14+
ui.writeLine(stderr);
1415
ui.writeLine(chalk.red('Some end-to-end tests failed, see above.'));
1516
} else {
1617
ui.writeLine(chalk.green('All end-to-end tests pass.'));

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"sinon": "^1.17.3",
7474
"through": "^2.3.8",
7575
"tslint": "^3.8.1",
76+
"tree-kill": "^1.0.0",
7677
"walk-sync": "^0.2.6"
7778
}
7879
}

tests/e2e/e2e_workflow.spec.js

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ var chai = require('chai');
77
var expect = chai.expect;
88
var conf = require('ember-cli/tests/helpers/conf');
99
var sh = require('shelljs');
10+
var treeKill = require('tree-kill');
11+
var child_process = require('child_process');
1012
var ng = require('../helpers/ng');
1113
var root = path.join(process.cwd(), 'tmp');
1214

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

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

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

117+
it('Serve and run e2e tests after initial build', function () {
118+
this.timeout(240000);
119+
120+
var ngServePid;
121+
122+
function executor(resolve, reject) {
123+
var serveProcess = child_process.exec(`${ngBin} serve`);
124+
var startedProtractor = false;
125+
ngServePid = serveProcess.pid;
126+
127+
serveProcess.stdout.on('data', (data) => {
128+
if (/Build successful/.test(data) && !startedProtractor) {
129+
startedProtractor = true;
130+
child_process.exec(`${ngBin} e2e`, (error, stdout, stderr) => {
131+
if (error !== null) {
132+
reject(stderr)
133+
} else {
134+
resolve();
135+
}
136+
});
137+
} else if (/ failed with:/.test(data)) {
138+
reject(data);
139+
}
140+
});
141+
142+
serveProcess.stderr.on('data', (data) => {
143+
reject(data);
144+
});
145+
serveProcess.on('close', (code) => {
146+
code === 0 ? resolve() : reject('ng serve command closed with error')
147+
});
148+
}
149+
150+
return new Promise(executor)
151+
.then(() => {
152+
if (ngServePid) treeKill(ngServePid);
153+
})
154+
.catch((msg) => {
155+
if (ngServePid) treeKill(ngServePid);
156+
throw new Error(msg);
157+
});
158+
});
159+
115160
it('Can create a test component using `ng generate component test-component`', function () {
116161
this.timeout(10000);
117162
return ng(['generate', 'component', 'test-component']).then(function () {
@@ -370,4 +415,47 @@ describe('Basic end-to-end Workflow', function () {
370415
expect('build failed where it should have succeeded').to.equal('');
371416
});
372417
});
418+
419+
it('Serve and run e2e tests after all other commands', function () {
420+
this.timeout(240000);
421+
422+
var ngServePid;
423+
424+
function executor(resolve, reject) {
425+
var serveProcess = child_process.exec(`${ngBin} serve`);
426+
var startedProtractor = false;
427+
ngServePid = serveProcess.pid;
428+
429+
serveProcess.stdout.on('data', (data) => {
430+
if (/Build successful/.test(data) && !startedProtractor) {
431+
startedProtractor = true;
432+
child_process.exec(`${ngBin} e2e`, (error, stdout, stderr) => {
433+
if (error !== null) {
434+
reject(stderr)
435+
} else {
436+
resolve();
437+
}
438+
});
439+
} else if (/ failed with:/.test(data)) {
440+
reject(data);
441+
}
442+
});
443+
444+
serveProcess.stderr.on('data', (data) => {
445+
reject(data);
446+
});
447+
serveProcess.on('close', (code) => {
448+
code === 0 ? resolve() : reject('ng serve command closed with error')
449+
});
450+
}
451+
452+
return new Promise(executor)
453+
.then(() => {
454+
if (ngServePid) treeKill(ngServePid);
455+
})
456+
.catch((msg) => {
457+
if (ngServePid) treeKill(ngServePid);
458+
throw new Error(msg);
459+
});
460+
});
373461
});

0 commit comments

Comments
 (0)