From cb34c522b0ddc021278d64826ba682ffd37de02c Mon Sep 17 00:00:00 2001 From: y00576111 Date: Thu, 25 Nov 2021 21:36:26 +0800 Subject: [PATCH] fixed b603e77 from https://gitee.com/yaojian16/xts_acts/pulls/1180 add onmessageerror testcase Signed-off-by: y00576111 Change-Id: I5cdd846c3f9f5a0409c58ba2f6ea1a9f2ce50dcb --- .../src/main/js/test/Worker.test.js | 74 +++++++++++++++---- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/compileruntime/worker_lib_standard/src/main/js/test/Worker.test.js b/compileruntime/worker_lib_standard/src/main/js/test/Worker.test.js index 4393ff932..0a3f9099b 100644 --- a/compileruntime/worker_lib_standard/src/main/js/test/Worker.test.js +++ b/compileruntime/worker_lib_standard/src/main/js/test/Worker.test.js @@ -25,7 +25,7 @@ describe('workerTest', function () { console.info('total case over') }) - function PromiseCase() { + function promiseCase() { let p = new Promise(function (resolve, reject) { setTimeout(function () { resolve() @@ -71,7 +71,7 @@ describe('workerTest', function () { ss.postMessage("hello world") while (!flag) { - await PromiseCase() + await promiseCase() } expect(res).assertEqual("hello world worker") done() @@ -92,7 +92,7 @@ describe('workerTest', function () { ss.postMessage(12) while (!flag) { - await PromiseCase() + await promiseCase() } expect(res).assertEqual(25) done() @@ -113,7 +113,7 @@ describe('workerTest', function () { ss.postMessage({"message":"hello world"}) while (!flag) { - await PromiseCase() + await promiseCase() } expect(res).assertEqual("hello world worker") done() @@ -133,7 +133,7 @@ describe('workerTest', function () { ss.postMessage("hello world") while (!flag) { - await PromiseCase() + await promiseCase() } expect(res).assertEqual("zhangsan") done() @@ -163,7 +163,7 @@ describe('workerTest', function () { ss.postMessage("hello world") while (!flag) { - await PromiseCase() + await promiseCase() } expect(res).assertEqual("Error: 123") done() @@ -181,7 +181,7 @@ describe('workerTest', function () { } ss.terminate() while (!flag) { - await PromiseCase() + await promiseCase() } expect(res).assertEqual(1) done() @@ -203,7 +203,7 @@ describe('workerTest', function () { ss.terminate() while (!flag) { - await PromiseCase() + await promiseCase() } expect(res).assertEqual(1) done() @@ -226,12 +226,12 @@ describe('workerTest', function () { ss.terminate() while (!flag) { - await PromiseCase() + await promiseCase() } expect(res).assertEqual(1) ss.postMessage("hello world") - await PromiseCase() + await promiseCase() expect(res).assertEqual(1) done() }) @@ -508,7 +508,7 @@ describe('workerTest', function () { } ss.postMessage("abc") - await PromiseCase() + await promiseCase() expect(res).assertEqual(0) done() }) @@ -525,11 +525,11 @@ describe('workerTest', function () { } ss1.postMessage("abc") - await PromiseCase() + await promiseCase() expect(res).assertEqual(0) ss2.postMessage("hello world") - await PromiseCase() + await promiseCase() expect(res).assertEqual(0) done() @@ -547,7 +547,7 @@ describe('workerTest', function () { } ss1.postMessage("abc") - await PromiseCase() + await promiseCase() expect(res).assertEqual(0) ss2.addEventListener("zhangsan", ()=>{ @@ -575,12 +575,54 @@ describe('workerTest', function () { ss.postMessage("abc") while (!flag) { - await PromiseCase() + await promiseCase() } ss.postMessage("hello") - await PromiseCase() + await promiseCase() expect(res).assertEqual(0) done() }) + + // check onmessageerror is ok + it('worker_onmessageerror_test_001', 0, async function (done) { + var ss = new worker.Worker("workers/worker_008.js"); + var res = 0 + var flag = false; + + ss.onexit = function () { + flag = true + } + + ss.onmessageerror = function (e) { + res++; + } + + ss.postMessage("abc") + while (!flag) { + await promiseCase() + } + expect(res).assertEqual(0) + done() + }) + + // check onmessageerror is ok + it('worker_onmessageerror_test_002', 0, async function (done) { + var ss = new worker.Worker("workers/worker_008.js"); + var res = 0 + var flag = false; + + ss.onmessageerror = function (e) { + flag = true; + res++; + } + function foo() { + } + ss.postMessage(foo) + while (!flag) { + await promiseCase() + } + expect(res).assertEqual(1) + done() + }) }) \ No newline at end of file -- GitLab