summaryrefslogtreecommitdiffstats
path: root/tests/pyodide_testrunner/test-runner.js
blob: dbbc01fddcf0626876999d9d2ad8e7c53f28299a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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'))