diff --git a/compileruntime/BUILD.gn b/compileruntime/BUILD.gn index 5fbd3642ba1d79c335e3708b32fbc206ca56f532..9f73100a2c3f8190bc3882a3bc3f1788fedc4ee6 100644 --- a/compileruntime/BUILD.gn +++ b/compileruntime/BUILD.gn @@ -19,7 +19,7 @@ group("compileruntime") { "process_lib_standard:process_js_test", "url_lib_standard:url_js_test", "util_lib_standard:util_js_test", - "worker_lib_standard:worker_js_hap", +# "worker_lib_standard:worker_js_hap", ] } } diff --git a/compileruntime/worker_lib_standard/Test.json b/compileruntime/worker_lib_standard/Test.json index b1b4bbe008e8a0ff7a33e188d16e572828f58c94..b1ff162f3e175eeef4293e5d070ced0dc6725b14 100644 --- a/compileruntime/worker_lib_standard/Test.json +++ b/compileruntime/worker_lib_standard/Test.json @@ -2,9 +2,9 @@ "description": "Configuration for startup worker js api Tests", "driver": { "type": "JSUnitTest", - "test-timeout": "60000", + "test-timeout": "800000", "package": "com.example.workerxts", - "shell-timeout": "60000" + "shell-timeout": "90000" }, "kits": [ { diff --git a/compileruntime/worker_lib_standard/src/main/config.json b/compileruntime/worker_lib_standard/src/main/config.json index bcb6c0fff3288358a6e0ccc71d54789a26d37d4b..fab84843869b034d31143b40d5de695393fbca7f 100644 --- a/compileruntime/worker_lib_standard/src/main/config.json +++ b/compileruntime/worker_lib_standard/src/main/config.json @@ -37,6 +37,7 @@ ] } ], + "visible": true, "orientation": "unspecified", "name": "com.example.workerxts.MainAbility", "icon": "$media:icon", diff --git a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker.js index 461c656778e9f3b27daf295f197e64b74665c54e..4af785c45bb7b74c733de4e80e09e365713c05cf 100644 --- a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker.js @@ -13,54 +13,44 @@ * limitations under the License. */ -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - function foo(x) {return x} - - var worker = globalThis.requireNapi('worker'); - - const parentPort = worker.parentPort; - - console.info("worker:: new version") - - parentPort.onclose = function() { - console.info("worker::worker.js onclose"); +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +console.info("worker:: new version") + +parentPort.onclose = function() { + console.info("worker::worker.js onclose"); +} + +parentPort.onmessage = function(e) { + var data = e.data; + console.info("worker:: worker thread worker data is " + data.data); + switch(data.type) { + case "normal": + console.info("worker:: worker thread receive data " + data.data); + parentPort.postMessage(data); + console.info("worker:: worker thread post back"); + break; + case "error": + throw new Error("123"); + break; + case "buffer": + console.info("worker:: worker.js receive buffer length is " + data.data.byteLength); + parentPort.postMessage(data, [data.data]); + console.info("worker:: worker.js post buffer length is " + data.data.byteLength); + break; + default: + console.info("worker:: worker.js receive unknow type"); + break } +} - parentPort.onmessage = function(e) { - var data = e.data; - console.info("worker:: worker thread worker data is " + data.data); - switch(data.type) { - case "normal": - console.info("worker:: worker thread receive data " + data.data); - parentPort.postMessage(data); - console.info("worker:: worker thread post back"); - break; - case "error": - throw new Error("123"); - break; - case "buffer": - console.info("worker:: worker.js receive buffer length is " + data.data.byteLength); - parentPort.postMessage(data, [data.data]); - console.info("worker:: worker.js post buffer length is " + data.data.byteLength); - break; - default: - console.info("worker:: worker.js receive unknow type"); - break - } - } - - // 反序列错误 - parentPort.onmessageerror = function() { - console.info("worker:: worker.js onmessageerror"); - } +// 反序列错误 +parentPort.onmessageerror = function() { + console.info("worker:: worker.js onmessageerror"); +} - // js执行异常 - parentPort.onerror = function(data) { - console.info("worker:: worker.js onerror " + data.lineno + ", msg = " + data.message + ", filename = " + data.filename + ", colno = " + data.colno); - } - /******/ })() -; \ No newline at end of file +// js执行异常 +parentPort.onerror = function(data) { + console.info("worker:: worker.js onerror " + data.lineno + ", msg = " + data.message + ", filename = " + data.filename + ", colno = " + data.colno); +} \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_002.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_002.js index 5914eea6d23eb11c8582a5b24a6bbe87844757be..a5e4b564ebcd9f43348f95519111aadd51871906 100644 --- a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_002.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_002.js @@ -13,20 +13,11 @@ * limitations under the License. */ -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - console.log("worker:: run script"); - var worker = globalThis.requireNapi('worker'); +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - console.log("worker:: worker receive data " + e.data); - var data = e.data + " worker"; - parentPort.postMessage(data) - } - /******/ })() -; \ No newline at end of file +parentPort.onmessage = function(e) { + console.log("worker:: worker receive data " + e.data); + var data = e.data + " worker"; + parentPort.postMessage(data) +} \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_003.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_003.js index a680ac1788fdca88e9ca08f75ccad03accfbf692..f44ebffb78e03ad3f576610a942a5b08eb547dd5 100644 --- a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_003.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_003.js @@ -13,18 +13,10 @@ * limitations under the License. */ -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - var worker = globalThis.requireNapi('worker'); +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - var data = e.data * 2 + 1 - parentPort.postMessage(data) - } - /******/ })() -; \ No newline at end of file +parentPort.onmessage = function(e) { + var data = e.data * 2 + 1 + parentPort.postMessage(data) +} \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_004.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_004.js index 49e4423840930b19e290e3eb4e672d0d20918527..9fbddd4633c8bc7fc4e8343e91d8e4bd7fdfe819 100644 --- a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_004.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_004.js @@ -13,19 +13,11 @@ * limitations under the License. */ -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - var worker = globalThis.requireNapi('worker'); +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - var data = e.data; - data.message = "hello world " + "worker" - parentPort.postMessage(data) - } - /******/ })() -; \ No newline at end of file +parentPort.onmessage = function(e) { + var data = e.data; + data.message = "hello world " + "worker" + parentPort.postMessage(data) +} \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_005.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_005.js index cc1cbaaad826dbd06bb862f4faa540498f2cf365..5a49ddb305b09cca49ea6d308f5de0726241db03 100644 --- a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_005.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_005.js @@ -13,17 +13,9 @@ * limitations under the License. */ -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - var worker = globalThis.requireNapi('worker'); +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - parentPort.postMessage(name) - } - /******/ })() -; \ No newline at end of file +parentPort.onmessage = function(e) { + parentPort.postMessage(name) +} \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_006.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_006.js index 6b9ce1e02dcf9a32709948b487861bbf2f854fb0..206092efcc2839424e094088577484c33e821295 100644 --- a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_006.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_006.js @@ -13,17 +13,9 @@ * limitations under the License. */ -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - var worker = globalThis.requireNapi('worker'); +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - parentPort.postMessage("hello world") - } - /******/ })() -; \ No newline at end of file +parentPort.onmessage = function(e) { + parentPort.postMessage("hello world") +} \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_007.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_007.js index 9d5790347a917d7827d1b6276968e4e205734360..ac834e8eda1e062573b3bb5ac809c7a0ff0c471e 100644 --- a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_007.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_007.js @@ -13,17 +13,9 @@ * limitations under the License. */ -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - var worker = globalThis.requireNapi('worker'); +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - throw new Error(123) - } - /******/ })() -; \ No newline at end of file +parentPort.onmessage = function(e) { + throw new Error(123) +} \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_008.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_008.js index 02d4825b98377c83d4bbc9e8a8542b7dea6fd262..1f7996cf9ae6bf51a37fe6021d5fb299c2f3124c 100644 --- a/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_008.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_008.js @@ -13,17 +13,9 @@ * limitations under the License. */ -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - var worker = globalThis.requireNapi('worker'); +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - parentPort.close() - } - /******/ })() -; \ No newline at end of file +parentPort.onmessage = function(e) { + parentPort.close() +} diff --git a/compileruntime/worker_lib_standard/src/main/js/test/ExampleJsunit.test.js b/compileruntime/worker_lib_standard/src/main/js/test/ExampleJsunit.test.js deleted file mode 100644 index d289d77a014adff89086f354807f6caac9c317b7..0000000000000000000000000000000000000000 --- a/compileruntime/worker_lib_standard/src/main/js/test/ExampleJsunit.test.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import app from '@system.app' -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' - -describe('appInfoTest', function () { - it('app_info_test_001', 0, function () { - var info = app.getInfo() - expect(info.versionName).assertEqual('1.0.0') - expect(info.versionCode).assertEqual('1000000') - }) -}) \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/src/main/js/test/List.test.js b/compileruntime/worker_lib_standard/src/main/js/test/List.test.js index f0714ab28b031c9721288cfc773fb9cd5a9133f6..0265650c604b57482635920be5180f5d907ca5e3 100644 --- a/compileruntime/worker_lib_standard/src/main/js/test/List.test.js +++ b/compileruntime/worker_lib_standard/src/main/js/test/List.test.js @@ -13,5 +13,4 @@ * limitations under the License. */ -require('./ExampleJsunit.test.js') require("./Worker.test.js") \ No newline at end of file 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 e8cbc612478de5c342c581911afbcc2886152a18..a6b786f2c32b3caa31407d5dadf5fedd62f3ad9a 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 @@ -1,13 +1,13 @@ /* * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License') * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. @@ -16,7 +16,7 @@ // @ts-nocheck import app from '@system.app' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' -import worker from '@ohos.worker' +import worker from "@ohos.worker"; describe('workerTest', function () { @@ -145,7 +145,22 @@ describe('workerTest', function () { const buffer = new ArrayBuffer(8) expect(buffer.byteLength).assertEqual(8) ss.postMessage(buffer, [buffer]) - expect(buffer.byteLength).assertEqual(0) + var length = undefined; + var exception = undefined; + try { + length = buffer.byteLength; + } catch (e) { + exception = e.message; + } + + console.log("worker:: length is " + length) + console.log("worker:: exception is " + exception) + + if (typeof exception == "undefined") { + expect(length).assertEqual(0) + } else { + expect(exception).assertEqual("IsDetachedBuffer") + } }) // check worker handle error is ok @@ -463,6 +478,7 @@ describe('workerTest', function () { ss.dispatchEvent({type: "zhangsan"}) expect(zhangsanTimes).assertEqual(2) + }) // check worker removeAllListener function is ok @@ -501,65 +517,23 @@ describe('workerTest', function () { it('worker_parentPortClose_test_001', 0, async function (done) { var ss = new worker.Worker("workers/worker_008.js"); var res = 0 + var flag = false; - ss.onmessage = function (e) { + ss.onexit = function (e) { res++; + flag = true; } ss.postMessage("abc") - await promiseCase() - expect(res).assertEqual(0) - done() - }) - - // check parentPort.close is ok - it('worker_parentPortClose_test_002', 0, async function (done) { - var ss1 = new worker.Worker("workers/worker_008.js"); - var ss2 = new worker.Worker("workers/worker_008.js"); - var res = 0 - var times = 0 - - ss1.onmessage = function (e) { - res++; - } - - ss1.postMessage("abc") - await promiseCase() - expect(res).assertEqual(0) - - ss2.postMessage("hello world") - await promiseCase() - expect(res).assertEqual(0) - - done() - }) - - // check parentPort.close is ok - it('worker_parentPortClose_test_003', 0, async function (done) { - var ss1 = new worker.Worker("workers/worker_008.js"); - var ss2 = new worker.Worker("workers/worker_008.js"); - var res = 0 - var times = 0 - - ss1.onmessage = function (e) { - res++; + while (!flag) { + await promiseCase() } - - ss1.postMessage("abc") - await promiseCase() - expect(res).assertEqual(0) - - ss2.addEventListener("zhangsan", ()=>{ - times++; - }) - - ss2.dispatchEvent({type: "zhangsan"}) - expect(times).assertEqual(1) + expect(res).assertEqual(1) done() }) // check parentPort.close is ok - it('worker_parentPortClose_test_004', 0, async function (done) { + it('worker_parentPortClose_test_002', 0, async function (done) { var ss = new worker.Worker("workers/worker_008.js"); var res = 0 var flag = false; @@ -605,23 +579,4 @@ describe('workerTest', function () { 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