Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Commit 8361f6a

Browse files
authored
Make node web worker test not need a bundle. (#1857)
DEV
1 parent ab6b88d commit 8361f6a

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

karma.conf.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const devConfig = {
3838
'src/worker_node_test.ts',
3939
'src/worker_test.ts',
4040
'src/test_node.ts',
41-
'src/test_async_backends.ts'
41+
'src/test_async_backends.ts',
4242
],
4343
preprocessors: {'**/*.ts': ['karma-typescript']},
4444
karmaTypescriptConfig,
@@ -52,7 +52,7 @@ const browserstackConfig = {
5252
'dist/worker_node_test.js',
5353
'dist/worker_test.js',
5454
'dist/test_node.js',
55-
'dist/test_async_backends.js'
55+
'dist/test_async_backends.js',
5656
],
5757
preprocessors: {'dist/**/*_test.js': ['browserify']},
5858
browserify: {debug: false},
@@ -66,8 +66,9 @@ const webworkerConfig = {
6666
files: [
6767
'dist/setup_test.js',
6868
'dist/worker_test.js',
69-
// Serve dist/tf-core.js as a static resource, but do not include in the test runner
70-
{pattern: 'dist/tf-core.js', included: false}
69+
// Serve dist/tf-core.min.js as a static resource, but do not include in the
70+
// test runner
71+
{pattern: 'dist/tf-core.min.js', included: false},
7172
],
7273
exclude: [],
7374
port: 12345

scripts/test-ci.sh

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,18 @@ yarn test-node-ci
2222

2323
# Run the first karma separately so it can download the BrowserStack binary
2424
# without conflicting with others.
25-
yarn run-browserstack --browsers=bs_safari_mac --testEnv webgl1 --flags '{"WEBGL_CPU_FORWARD": false, "WEBGL_SIZE_UPLOAD_UNIFORM": 0}'
25+
yarn run-browserstack --browsers=bs_safari_mac,bs_ios_11 --testEnv webgl1 --flags '{"WEBGL_CPU_FORWARD": false, "WEBGL_SIZE_UPLOAD_UNIFORM": 0}'
2626

2727
# Run the rest of the karma tests in parallel. These runs will reuse the
2828
# already downloaded binary.
2929
npm-run-all -p -c --aggregate-output \
30-
"run-browserstack --browsers=bs_safari_mac --flags '{\"HAS_WEBGL\": false}' --testEnv cpu" \
31-
"run-browserstack --browsers=win_10_chrome --testEnv webgl2 --flags '{\"WEBGL_CPU_FORWARD\": false, \"WEBGL_SIZE_UPLOAD_UNIFORM\": 0}'" \
32-
"run-browserstack --browsers=bs_ios_11 --testEnv webgl1 --flags '{\"WEBGL_CPU_FORWARD\": false, \"WEBGL_SIZE_UPLOAD_UNIFORM\": 0}'" \
33-
"run-browserstack --browsers=bs_ios_11 --flags '{\"HAS_WEBGL\": false}' --testEnv cpu" \
34-
"run-browserstack --browsers=bs_firefox_mac" \
35-
"run-browserstack --browsers=bs_chrome_mac" \
36-
"run-browserstack --browsers=bs_chrome_mac --testEnv webgl2 --flags '{\"WEBGL_CPU_FORWARD\": true}'" \
37-
"run-browserstack --browsers=bs_chrome_mac --testEnv webgl2 --flags '{\"WEBGL_CPU_FORWARD\": false}'"
30+
"run-browserstack --browsers=bs_safari_mac,bs_ios_11 --flags '{\"HAS_WEBGL\": false}' --testEnv cpu" \
31+
"run-browserstack --browsers=bs_firefox_mac,bs_chrome_mac" \
32+
"run-browserstack --browsers=bs_chrome_mac,win_10_chrome --testEnv webgl2 --flags '{\"WEBGL_CPU_FORWARD\": false, \"WEBGL_SIZE_UPLOAD_UNIFORM\": 0}'"
3833

39-
# Build dist/tf-core.js which is used by the webworker test
40-
yarn build-npm
41-
# Run under webworker environment
42-
yarn test-webworker --browsers=bs_safari_mac
34+
### The next section tests TF.js in a webworker.
35+
# Make a dist/tf-core.min.js file to be imported by the web worker.
36+
yarn rollup -c --ci
37+
# Safari doesn't have offscreen canvas so test cpu in a webworker.
38+
# Chrome has offscreen canvas, so test webgl in a webworker.
39+
yarn test-webworker --browsers=bs_safari_mac,bs_chrome_mac

src/worker_node_test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
* =============================================================================
1616
*/
1717

18-
import {HAS_NODE_WORKER, describeWithFlags} from './jasmine_util';
18+
import {describeWithFlags, HAS_NODE_WORKER} from './jasmine_util';
1919
import {expectArraysClose} from './test_util';
20+
// tslint:disable:no-require-imports
2021

2122
const fn2String = (fn: Function): string => {
22-
const funcStr = '('+fn.toString()+')()';
23+
const funcStr = '(' + fn.toString() + ')()';
2324
return funcStr;
2425
};
2526

2627
// The source code of a web worker.
2728
const workerTestNode = () => {
28-
const tf = require(`${process.cwd()}/dist/tf-core.js`);
29-
// tslint:disable-next-line:no-require-imports
29+
// Web worker scripts in node live relative to the CWD, not to the dir of the
30+
// file that spawned them.
31+
const tf = require('./dist/index.js');
3032
const {parentPort} = require('worker_threads');
3133
let a = tf.tensor1d([1, 2, 3]);
3234
const b = tf.tensor1d([3, 2, 1]);
@@ -36,7 +38,6 @@ const workerTestNode = () => {
3638

3739
describeWithFlags('computation in worker (node env)', HAS_NODE_WORKER, () => {
3840
it('tensor in worker', (done) => {
39-
// tslint:disable-next-line:no-require-imports
4041
const {Worker} = require('worker_threads');
4142
const worker = new Worker(fn2String(workerTestNode), {eval: true});
4243
// tslint:disable-next-line:no-any

src/worker_test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
* =============================================================================
1616
*/
1717

18-
import {HAS_WORKER, describeWithFlags} from './jasmine_util';
19-
import {expectArraysClose} from './test_util';
2018
import * as tf from './index';
19+
import {describeWithFlags, HAS_WORKER} from './jasmine_util';
20+
import {expectArraysClose} from './test_util';
2121

2222
const fn2workerURL = (fn: Function): string => {
2323
const blob =
24-
new Blob(['('+fn.toString()+')()'], {type: 'application/javascript'});
24+
new Blob(['(' + fn.toString() + ')()'], {type: 'application/javascript'});
2525
return URL.createObjectURL(blob);
2626
};
2727

2828
// The source code of a web worker.
2929
const workerTest = () => {
3030
//@ts-ignore
31-
importScripts('http://bs-local.com:12345/base/dist/tf-core.js');
31+
importScripts('http://bs-local.com:12345/base/dist/tf-core.%3Cspan%20class="x x-first x-last">min.js');
3232
let a = tf.tensor1d([1, 2, 3]);
3333
const b = tf.tensor1d([3, 2, 1]);
3434
a = a.add(b);

0 commit comments

Comments
 (0)