summaryrefslogtreecommitdiffstats
path: root/tests/pyodide_testrunner/test-runner.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 20:21:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 20:21:34 +0000
commitfe1438b06234f8e5ecd4caa7eedfeec585b6f77c (patch)
tree5c2a9ff683189a61e0855ca3f24df319e7e03b7f /tests/pyodide_testrunner/test-runner.js
parentInitial commit. (diff)
downloadpygls-upstream.tar.xz
pygls-upstream.zip
Adding upstream version 1.3.0.upstream/1.3.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/pyodide_testrunner/test-runner.js')
-rw-r--r--tests/pyodide_testrunner/test-runner.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/pyodide_testrunner/test-runner.js b/tests/pyodide_testrunner/test-runner.js
new file mode 100644
index 0000000..dbbc01f
--- /dev/null
+++ b/tests/pyodide_testrunner/test-runner.js
@@ -0,0 +1,38 @@
+importScripts("https://cdn.jsdelivr.net/pyodide/v0.21.3/full/pyodide.js")
+
+// Used to redirect pyodide's stdout to the webpage.
+function patchedStdout(...args) {
+ postMessage(args[0])
+}
+
+async function runTests(whl) {
+ console.log("Loading pyodide")
+ let pyodide = await loadPyodide({
+ indexURL: "https://cdn.jsdelivr.net/pyodide/v0.21.3/full/"
+ })
+
+ console.log("Installing dependencies")
+ await pyodide.loadPackage("micropip")
+ await pyodide.runPythonAsync(`
+ import sys
+ import micropip
+
+ await micropip.install('pytest')
+ await micropip.install('pytest-asyncio')
+ await micropip.install('${whl}')
+ `)
+
+ console.log('Running testsuite')
+
+ // Patch stdout to redirect the output.
+ pyodide.globals.get('sys').stdout.write = patchedStdout
+ await pyodide.runPythonAsync(`
+ import pytest
+ exit_code = pytest.main(['--color', 'no', '--pyargs', 'pygls.tests'])
+ `)
+
+ postMessage({ exitCode: pyodide.globals.get('exit_code') })
+}
+
+let queryParams = new URLSearchParams(self.location.search)
+runTests(queryParams.get('whl'))