Skip to content

Commit 3136a3b

Browse files
authored
Speedup build and CI testing (tensorflow#1624)
Speedup our travis CI build and testing by 2X. This run took: 8 min 33 sec [link](https://travis-ci.org/tensorflow/tfjs-core/builds/506838185) Yesterday's run took: 16min 53 sec [link](https://travis-ci.org/tensorflow/tfjs-core/builds/506570451) **Details** - We used to re-compile our codebase 10 times over (every time you call `ts-node` and `karma`) - Now we compile it only once (`yarn build`) and run `node` and `karma` using the `browserify` plugin, which circumvents the typescript compilation - Also speedup the vscode `build` task by 1.5X by passing `--noEmit` to typescript to skip generating build artifacts. DEV
1 parent b9ea664 commit 3136a3b

File tree

6 files changed

+440
-47
lines changed

6 files changed

+440
-47
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"command": "yarn",
1919
"label": "build",
2020
"type": "shell",
21-
"args": ["build", "--pretty", "false"],
21+
"args": ["build", "--pretty", "false", "--noEmit"],
2222
"problemMatcher": [
2323
"$tsc"
2424
]

karma.conf.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ if (coverageEnabled) {
3131
karmaTypescriptConfig.reports = {html: 'coverage', 'text-summary': ''};
3232
}
3333

34+
const devConfig = {
35+
frameworks: ['jasmine', 'karma-typescript'],
36+
files: [{pattern: 'src/**/*.ts'}],
37+
exclude: ['src/test_node.ts'],
38+
preprocessors: {'**/*.ts': ['karma-typescript']},
39+
karmaTypescriptConfig,
40+
reporters: ['dots', 'karma-typescript'],
41+
};
42+
43+
const browserstackConfig = {
44+
frameworks: ['browserify', 'jasmine'],
45+
files: [{pattern: 'dist/**/*_test.js'}],
46+
exclude: ['dist/test_node.js'],
47+
preprocessors: {'dist/**/*_test.js': ['browserify']},
48+
browserify: {debug: false},
49+
reporters: ['dots', 'BrowserStack'],
50+
singleRun: true,
51+
hostname: 'bs-local.com',
52+
};
53+
3454
module.exports = function(config) {
3555
const args = [];
3656
if (config.backend) {
@@ -42,14 +62,10 @@ module.exports = function(config) {
4262
if (config.features) {
4363
args.push('--features', config.features);
4464
}
65+
const extraConfig = config.browserstack ? browserstackConfig : devConfig;
4566

4667
config.set({
47-
frameworks: ['jasmine', 'karma-typescript'],
48-
files: [{pattern: 'src/**/*.ts'}],
49-
exclude: ['src/test_node.ts'],
50-
preprocessors: {'**/*.ts': ['karma-typescript']},
51-
karmaTypescriptConfig,
52-
reporters: ['dots', 'karma-typescript'],
68+
...extraConfig,
5369
browsers: ['Chrome'],
5470
browserStack: {
5571
username: process.env.BROWSERSTACK_USERNAME,
@@ -59,6 +75,8 @@ module.exports = function(config) {
5975
reportSlowerThan: 500,
6076
browserNoActivityTimeout: 180000,
6177
customLaunchers: {
78+
// For browserstack configs see:
79+
// https://www.browserstack.com/automate/node
6280
bs_chrome_mac: {
6381
base: 'BrowserStack',
6482
browser: 'chrome',

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
"devDependencies": {
2121
"@types/jasmine": "~2.5.53",
2222
"@types/node": "~9.6.0",
23+
"browserify": "~16.2.3",
2324
"clang-format": "~1.2.4",
2425
"jasmine": "~3.1.0",
2526
"jasmine-core": "~3.1.0",
2627
"karma": "~4.0.0",
28+
"karma-browserify": "~6.0.0",
2729
"karma-browserstack-launcher": "~1.4.0",
2830
"karma-chrome-launcher": "~2.2.0",
2931
"karma-jasmine": "~1.1.0",
@@ -49,9 +51,9 @@
4951
"lint": "tslint -p . -t verbose",
5052
"coverage": "KARMA_COVERAGE=1 karma start --browsers='Chrome' --singleRun",
5153
"test": "karma start",
52-
"run-browserstack": "karma start --singleRun --reporters='dots,karma-typescript,BrowserStack' --hostname='bs-local.com'",
54+
"run-browserstack": "karma start --browserstack",
5355
"test-benchmark": "cd integration_tests/benchmarks && yarn benchmark-travis && cd ../../",
54-
"test-node": "ts-node src/test_node.ts",
56+
"test-node": "node dist/test_node.js",
5557
"test-integration": "./scripts/test-integration.sh",
5658
"test-travis": "./scripts/test-travis.sh"
5759
},

scripts/build-npm.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ yarn
2222
yarn build
2323
rollup -c
2424
echo "Stored standalone library at dist/tf-core(.min).js"
25-
npm pack

src/test_node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ setTestEnvs(
2828
[{name: 'node', factory: () => new MathBackendCPU(), features: {}}]);
2929

3030
const runner = new jasmine();
31-
runner.loadConfig({spec_files: ['src/**/**_test.ts'], random: false});
31+
runner.loadConfig({spec_files: ['dist/**/**_test.js'], random: false});
3232
runner.execute();

0 commit comments

Comments
 (0)