summaryrefslogtreecommitdiffstats
path: root/tests/pyodide_testrunner/test-runner.js
diff options
context:
space:
mode:
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'))