From b0a23beb8fae964be3cdd8c23c38af66257d34c7 Mon Sep 17 00:00:00 2001 From: andy finch Date: Mon, 1 Apr 2019 15:09:59 -0400 Subject: Add web worker JS API (#1993) * Refactored the way worker polling is scheduled and errors are handled. * Share the worker future as a Shared --- tests/026_workers.test | 2 ++ tests/026_workers.ts | 14 ++++++++++++++ tests/026_workers.ts.out | 4 ++++ tests/error_004_missing_module | 4 ++++ tests/error_004_missing_module.disabled | 4 ---- tests/error_005_missing_dynamic_import | 4 ++++ tests/error_005_missing_dynamic_import.disabled | 4 ---- tests/error_006_import_ext_failure | 4 ++++ tests/error_006_import_ext_failure.disabled | 4 ---- tests/subdir/test_worker.js | 7 +++++++ tests/subdir/test_worker.ts | 7 +++++++ 11 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 tests/026_workers.test create mode 100644 tests/026_workers.ts create mode 100644 tests/026_workers.ts.out create mode 100644 tests/error_004_missing_module delete mode 100644 tests/error_004_missing_module.disabled create mode 100644 tests/error_005_missing_dynamic_import delete mode 100644 tests/error_005_missing_dynamic_import.disabled create mode 100644 tests/error_006_import_ext_failure delete mode 100644 tests/error_006_import_ext_failure.disabled create mode 100644 tests/subdir/test_worker.js create mode 100644 tests/subdir/test_worker.ts (limited to 'tests') diff --git a/tests/026_workers.test b/tests/026_workers.test new file mode 100644 index 000000000..1c5b6f4e6 --- /dev/null +++ b/tests/026_workers.test @@ -0,0 +1,2 @@ +args: tests/026_workers.ts --reload +output: tests/026_workers.ts.out \ No newline at end of file diff --git a/tests/026_workers.ts b/tests/026_workers.ts new file mode 100644 index 000000000..0cf8f53b1 --- /dev/null +++ b/tests/026_workers.ts @@ -0,0 +1,14 @@ +const jsWorker = new Worker("tests/subdir/test_worker.js"); +const tsWorker = new Worker("tests/subdir/test_worker.ts"); + +tsWorker.onmessage = e => { + console.log("Received ts: " + e.data); +}; + +jsWorker.onmessage = e => { + console.log("Received js: " + e.data); + + tsWorker.postMessage("Hello World"); +}; + +jsWorker.postMessage("Hello World"); diff --git a/tests/026_workers.ts.out b/tests/026_workers.ts.out new file mode 100644 index 000000000..7538cc867 --- /dev/null +++ b/tests/026_workers.ts.out @@ -0,0 +1,4 @@ +Hello World +Received js: Hello World +Hello World +Received ts: Hello World diff --git a/tests/error_004_missing_module b/tests/error_004_missing_module new file mode 100644 index 000000000..b94c86004 --- /dev/null +++ b/tests/error_004_missing_module @@ -0,0 +1,4 @@ +args: tests/error_004_missing_module.ts --reload +check_stderr: true +exit_code: 1 +output: tests/error_004_missing_module.ts.out diff --git a/tests/error_004_missing_module.disabled b/tests/error_004_missing_module.disabled deleted file mode 100644 index b94c86004..000000000 --- a/tests/error_004_missing_module.disabled +++ /dev/null @@ -1,4 +0,0 @@ -args: tests/error_004_missing_module.ts --reload -check_stderr: true -exit_code: 1 -output: tests/error_004_missing_module.ts.out diff --git a/tests/error_005_missing_dynamic_import b/tests/error_005_missing_dynamic_import new file mode 100644 index 000000000..2acf467c1 --- /dev/null +++ b/tests/error_005_missing_dynamic_import @@ -0,0 +1,4 @@ +args: tests/error_005_missing_dynamic_import.ts --reload +check_stderr: true +exit_code: 1 +output: tests/error_005_missing_dynamic_import.ts.out diff --git a/tests/error_005_missing_dynamic_import.disabled b/tests/error_005_missing_dynamic_import.disabled deleted file mode 100644 index 2acf467c1..000000000 --- a/tests/error_005_missing_dynamic_import.disabled +++ /dev/null @@ -1,4 +0,0 @@ -args: tests/error_005_missing_dynamic_import.ts --reload -check_stderr: true -exit_code: 1 -output: tests/error_005_missing_dynamic_import.ts.out diff --git a/tests/error_006_import_ext_failure b/tests/error_006_import_ext_failure new file mode 100644 index 000000000..5fe245739 --- /dev/null +++ b/tests/error_006_import_ext_failure @@ -0,0 +1,4 @@ +args: tests/error_006_import_ext_failure.ts --reload +check_stderr: true +exit_code: 1 +output: tests/error_006_import_ext_failure.ts.out diff --git a/tests/error_006_import_ext_failure.disabled b/tests/error_006_import_ext_failure.disabled deleted file mode 100644 index 5fe245739..000000000 --- a/tests/error_006_import_ext_failure.disabled +++ /dev/null @@ -1,4 +0,0 @@ -args: tests/error_006_import_ext_failure.ts --reload -check_stderr: true -exit_code: 1 -output: tests/error_006_import_ext_failure.ts.out diff --git a/tests/subdir/test_worker.js b/tests/subdir/test_worker.js new file mode 100644 index 000000000..53d38ba96 --- /dev/null +++ b/tests/subdir/test_worker.js @@ -0,0 +1,7 @@ +onmessage = function(e) { + console.log(e.data); + + postMessage(e.data); + + workerClose(); +}; diff --git a/tests/subdir/test_worker.ts b/tests/subdir/test_worker.ts new file mode 100644 index 000000000..53d38ba96 --- /dev/null +++ b/tests/subdir/test_worker.ts @@ -0,0 +1,7 @@ +onmessage = function(e) { + console.log(e.data); + + postMessage(e.data); + + workerClose(); +}; -- cgit v1.2.3