File: test-runner.js

package info (click to toggle)
pygls 1.3.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,588 kB
  • sloc: python: 9,820; javascript: 28; makefile: 11
file content (38 lines) | stat: -rw-r--r-- 1,117 bytes parent folder | download | duplicates (3)
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'))