Skip to content

Commit 9ce843f

Browse files
committed
test: add benchmark tests
Adds `tools/bench` allowing the benchmark of commands via the `ngbench` binary in development environments.
1 parent 9760ef9 commit 9ce843f

File tree

17 files changed

+558
-3
lines changed

17 files changed

+558
-3
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ matrix:
1212
allow_failures:
1313
- env: NODE_SCRIPT="tests/run_e2e.js --nightly"
1414
- env: NODE_SCRIPT="tests/run_e2e.js --ng2"
15+
- env: NODE_SCRIPT="tests/run_e2e.js --glob=benchmarks/**"
1516
- node_js: "7"
1617
include:
1718
- node_js: "6"
@@ -40,6 +41,9 @@ matrix:
4041
- node_js: "6"
4142
os: linux
4243
env: NODE_SCRIPT="tests/run_e2e.js --nightly"
44+
- node_js: "6"
45+
os: linux
46+
env: NODE_SCRIPT="tests/run_e2e.js --glob=benchmarks/**"
4347
- node_js: "7"
4448
os: linux
4549
env: NODE_SCRIPT=tests/run_e2e.js

bin/ngbench

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
// Provide a title to the process in `ps`
5+
process.title = 'bench';
6+
7+
require('../lib/bootstrap-local');
8+
require('../tools/bench/bin/ngbench');

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "packages/@angular/cli/lib/cli/index.js",
66
"trackingCode": "UA-8594346-19",
77
"bin": {
8-
"ng": "./bin/ng"
8+
"ng": "./bin/ng",
9+
"ngbench": "./bin/ngbench"
910
},
1011
"keywords": [],
1112
"scripts": {
@@ -87,18 +88,21 @@
8788
"silent-error": "^1.0.0",
8889
"source-map": "^0.5.6",
8990
"source-map-loader": "^0.2.0",
91+
"strip-ansi": "^3.0.1",
9092
"style-loader": "^0.13.1",
9193
"stylus": "^0.54.5",
9294
"stylus-loader": "^3.0.1",
9395
"temp": "0.8.3",
9496
"typescript": "~2.3.1",
97+
"tree-kill": "^1.1.0",
9598
"url-loader": "^0.5.7",
9699
"walk-sync": "^0.3.1",
97100
"webpack": "~2.4.0",
98101
"webpack-dev-middleware": "^1.10.2",
99102
"webpack-dev-server": "~2.4.5",
100103
"webpack-merge": "^2.4.0",
101-
"zone.js": "^0.8.4"
104+
"zone.js": "^0.8.4",
105+
"yargs": "^6.6.0"
102106
},
103107
"ember-addon": {
104108
"paths": [
@@ -126,6 +130,7 @@
126130
"@types/semver": "^5.3.30",
127131
"@types/source-map": "^0.5.0",
128132
"@types/webpack": "^2.2.15",
133+
"@types/yargs": "^6.5.0",
129134
"chai": "^3.5.0",
130135
"conventional-changelog": "^1.1.0",
131136
"dtsgenerator": "^0.9.1",
@@ -146,7 +151,7 @@
146151
"sinon": "^1.17.3",
147152
"spdx-satisfies": "^0.1.3",
148153
"through": "^2.3.6",
149-
"tree-kill": "^1.0.0",
154+
"tree-kill": "^1.1.0",
150155
"ts-node": "^2.0.0",
151156
"tslint": "^5.1.0"
152157
},

tests/e2e/benchmarks/build.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ngbench } from '../utils/process';
2+
3+
4+
export default function () {
5+
return ngbench('--command', 'ng build');
6+
}

tests/e2e/benchmarks/serve/css.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { ngbench } from '../../utils/process';
2+
import { replaceInFile, moveFile } from '../../utils/fs';
3+
import { updateJsonFile } from '../../utils/project';
4+
5+
6+
export default function () {
7+
const extensions = ['css', 'scss', 'less', 'styl'];
8+
let promise = Promise.resolve();
9+
10+
extensions.forEach(ext => {
11+
promise = promise.then(() => {
12+
// change files to use preprocessor
13+
return updateJsonFile('.angular-cli.json', configJson => {
14+
const app = configJson['apps'][0];
15+
app['styles'] = [`styles.${ext}`];
16+
})
17+
.then(() => replaceInFile('src/app/app.component.ts',
18+
'./app.component.css', `./app.component.${ext}`))
19+
.then(() => moveFile('src/styles.css', `src/styles.${ext}`))
20+
.then(() => moveFile('src/app/app.component.css', `src/app/app.component.${ext}`))
21+
// run benchmarks
22+
.then(() => ngbench(
23+
'--comment', 'component styles',
24+
'--match-edit-file', `src/app/app.component.${ext}`,
25+
'--match-edit-string', 'h1{color:blue}'
26+
))
27+
.then(() => ngbench(
28+
'--comment', `.${ext} CSS extension`,
29+
'--match-edit-file', `src/styles.${ext}`,
30+
'--match-edit-string', 'h1{color:blue}'
31+
))
32+
// change files back
33+
.then(() => replaceInFile('src/app/app.component.ts',
34+
`./app.component.${ext}`, './app.component.css'))
35+
.then(() => moveFile(`src/styles.${ext}`, 'src/styles.css'))
36+
.then(() => moveFile(`src/app/app.component.${ext}`, 'src/app/app.component.css'));
37+
38+
});
39+
});
40+
41+
return promise;
42+
}

tests/e2e/benchmarks/serve/html.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ngbench } from '../../utils/process';
2+
3+
4+
export default function () {
5+
return ngbench(
6+
'--match-edit-file', 'src/app/app.component.html',
7+
'--match-edit-string', '<div></div>'
8+
);
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ngbench } from '../../utils/process';
2+
import { writeFile } from '../../utils/fs';
3+
import { updateJsonFile } from '../../utils/project';
4+
5+
6+
export default function () {
7+
return updateJsonFile('.angular-cli.json', configJson => {
8+
const app = configJson['apps'][0];
9+
app['scripts'] = ['scripts.js'];
10+
})
11+
.then(() => writeFile('src/scripts.js', ''))
12+
.then(() => ngbench(
13+
'--match-edit-file', 'src/scripts.js',
14+
'--match-edit-string', 'console.log(1);'
15+
));
16+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ngbench } from '../../utils/process';
2+
3+
4+
export default function () {
5+
return ngbench('--extra-args=--aot');
6+
}

tests/e2e/benchmarks/version.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ngbench } from '../utils/process';
2+
3+
4+
export default function () {
5+
return ngbench('--command', 'ng version');
6+
}

tests/e2e/utils/process.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as child_process from 'child_process';
22
import {blue, yellow} from 'chalk';
3+
import {join} from 'path';
34
import {getGlobalVariable} from './env';
45
import {rimraf, writeFile} from './fs';
56
const treeKill = require('tree-kill');
@@ -185,3 +186,8 @@ export function git(...args: string[]) {
185186
export function silentGit(...args: string[]) {
186187
return _exec({silent: true}, 'git', args);
187188
}
189+
190+
export function ngbench(...args: string[]) {
191+
const ngbenchBin = join(__dirname, '../../../bin/ngbench');
192+
return _exec({}, ngbenchBin, args);
193+
}

0 commit comments

Comments
 (0)