| 1 |
#!/bin/bash |
| 2 |
set -e |
| 3 |
# So the script fails if there are any errors |
| 4 |
|
| 5 |
# Build the wheel |
| 6 |
python3 -m build |
| 7 |
|
| 8 |
# Find name of wheel, strip off the dist/ |
| 9 |
wheel=$(basename $(ls dist/*.whl)) |
| 10 |
|
| 11 |
# Create a blank index page |
| 12 |
echo ' |
| 13 |
<script src="https://cdn.jsdelivr.net/pyodide/v0.20.0/full/pyodide.js"></script> |
| 14 |
' > dist/index.html |
| 15 |
|
| 16 |
# Run a server for that dist/ folder |
| 17 |
cd dist |
| 18 |
python3 -m http.server 8529 & |
| 19 |
cd .. |
| 20 |
|
| 21 |
# Register the kill_server function to be called on script exit |
| 22 |
kill_server() { |
| 23 |
pkill -f 'http.server 8529' |
| 24 |
} |
| 25 |
trap kill_server EXIT |
| 26 |
|
| 27 |
|
| 28 |
shot-scraper javascript http://localhost:8529/ " |
| 29 |
async () => { |
| 30 |
let pyodide = await loadPyodide(); |
| 31 |
await pyodide.loadPackage(['micropip', 'ssl', 'setuptools']); |
| 32 |
let output = await pyodide.runPythonAsync(\` |
| 33 |
import micropip |
| 34 |
await micropip.install('h11==0.12.0') |
| 35 |
await micropip.install('httpx==0.23') |
| 36 |
# To avoid 'from typing_extensions import deprecated' error: |
| 37 |
await micropip.install('typing-extensions>=4.12.2') |
| 38 |
await micropip.install('http://localhost:8529/$wheel') |
| 39 |
import ssl |
| 40 |
import setuptools |
| 41 |
from datasette.app import Datasette |
| 42 |
ds = Datasette(memory=True, settings={'num_sql_threads': 0}) |
| 43 |
(await ds.client.get('/_memory.json?sql=select+55+as+itworks&_shape=array')).text |
| 44 |
\`); |
| 45 |
if (JSON.parse(output)[0].itworks != 55) { |
| 46 |
throw 'Got ' + output + ', expected itworks: 55'; |
| 47 |
} |
| 48 |
return 'Test passed!'; |
| 49 |
} |
| 50 |
" |