[gjs/ewlsh/workers-api: 124/124] Initial work on tests




commit 62b50490e3203dbdd2bfea287fc1c1921e9f18b6
Author: Evan Welsh <contact evanwelsh com>
Date:   Fri Mar 25 18:44:30 2022 -0700

    Initial work on tests

 installed-tests/js/jsunit.gresources.xml |  1 +
 installed-tests/js/meson.build           |  1 +
 installed-tests/js/modules/worker.js     | 17 +++++++++++++++++
 installed-tests/js/testWorker.js         | 11 +++++++++++
 4 files changed, 30 insertions(+)
---
diff --git a/installed-tests/js/jsunit.gresources.xml b/installed-tests/js/jsunit.gresources.xml
index 537bfb2e5..70d56cf8d 100644
--- a/installed-tests/js/jsunit.gresources.xml
+++ b/installed-tests/js/jsunit.gresources.xml
@@ -29,5 +29,6 @@
     <file>modules/subA/subB/__init__.js</file>
     <file>modules/subA/subB/baz.js</file>
     <file>modules/subA/subB/foobar.js</file>
+    <file>modules/worker.js</file>
   </gresource>
 </gresources>
diff --git a/installed-tests/js/meson.build b/installed-tests/js/meson.build
index 567e5cc7c..9f45262d0 100644
--- a/installed-tests/js/meson.build
+++ b/installed-tests/js/meson.build
@@ -142,6 +142,7 @@ jasmine_tests = [
     'Signals',
     'System',
     'Tweener',
+    'Worker'
 ]
 
 if build_cairo
diff --git a/installed-tests/js/modules/worker.js b/installed-tests/js/modules/worker.js
new file mode 100644
index 000000000..a5d3897d5
--- /dev/null
+++ b/installed-tests/js/modules/worker.js
@@ -0,0 +1,17 @@
+/* eslint-disable spaced-comment */
+/// <reference lib="dom" />
+
+// onmessage = event => {
+//     console.log(`Why hello there main thread, I got ${event.data} from you. I'm adding 10.`);
+//     postMessage(event.data + 10);
+// };
+
+let i = 0;
+const id = setInterval(() => {
+    i++;
+    console.log(`t: ${i}`);
+    if (i > 5) {
+        clearInterval(id);
+        postMessage(i);
+    }
+}, 1000);
diff --git a/installed-tests/js/testWorker.js b/installed-tests/js/testWorker.js
new file mode 100644
index 000000000..b428f6eb5
--- /dev/null
+++ b/installed-tests/js/testWorker.js
@@ -0,0 +1,11 @@
+/* eslint-disable spaced-comment */
+/// <reference lib="dom" />
+xdescribe('Workers', () => {
+    it('runs in unblocked thread', function (done) {
+        const worker = new Worker('resource:///org/gjs/jsunit/modules/worker.js', {name: '"Test Worker"'});
+
+        worker.onmessage = event => {
+            done();
+        };
+    });
+});


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]