Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ matrix:
- TRAVIS_RUST_VERSION=nightly
- REGULAR_TEST=false
- CODE_COVERAGE=true
- name: test WASM
language: python
python: 3.6
cache:
pip: true
# Because we're using the Python Travis environment, we can't use
# the built-in cargo cacher
directories:
- /home/travis/.cargo
- target
addons:
firefox: latest
install:
- nvm install node
- pip install pipenv
script:
- wasm/tests/.travis-runner.sh
env:
- REGULAR_TEST=true
- TRAVIS_RUST_VERSION=stable
allow_failures:
- rust: nightly
env: REGULAR_TEST=true
Expand Down
7 changes: 5 additions & 2 deletions wasm/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
"raw-loader": "^1.0.0",
"webpack": "^4.16.3",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5"
"webpack-dev-server": "^3.1.5",
"start-server-and-test": "^1.7.11"
},
"scripts": {
"dev": "webpack-dev-server -d",
"build": "webpack",
"dist": "webpack --mode production"
"dist": "webpack --mode production",
"test": "cd ../tests; pipenv run pytest",
"ci": "start-server-and-test dev http-get://localhost:8080 test"
},
"repository": {
"type": "git",
Expand Down
23 changes: 23 additions & 0 deletions wasm/tests/.travis-runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh -eux
# This script is intended to be run in Travis from the root of the repository

# Install Rust
curl -sSf https://build.travis-ci.org/files/rustup-init.sh | sh -s -- --default-toolchain=$TRAVIS_RUST_VERSION -y
export PATH=$HOME/.cargo/bin:$PATH

# install wasm-pack
if [ ! -f $HOME/.cargo/bin/wasm-pack ]; then
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
fi

# install geckodriver
wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux32.tar.gz
mkdir geckodriver
tar -xzf geckodriver-v0.24.0-linux32.tar.gz -C geckodriver
export PATH=$PATH:$PWD/geckodriver

# Install pipenv
pip install pipenv
(cd wasm/tests; pipenv install)

(cd wasm/demo; npm install; npm run ci)
13 changes: 13 additions & 0 deletions wasm/tests/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pytest = "*"
selenium = "*"

[dev-packages]

[requires]
python_version = "3"
87 changes: 87 additions & 0 deletions wasm/tests/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions wasm/tests/test_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import time

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import pytest

RUN_CODE_TEMPLATE = """
var output = "";
save_output = function(text) {{
output += text
}};
var vm = window.rp.vmStore.init('test_vm');
vm.setStdout(save_output);
vm.exec('{}');
vm.destroy();
return output;
"""

@pytest.fixture(scope="module")
def driver(request):
options = Options()
options.add_argument('-headless')
driver = webdriver.Firefox(options=options)
driver.get("http://localhost:8080")
time.sleep(5)
yield driver
driver.close()


@pytest.mark.parametrize("script, output",
[
("print(5)", "5"),
("a=5;b=4;print(a+b)", "9")
]
)
def test_demo(driver, script, output):
script = RUN_CODE_TEMPLATE.format(script)
assert driver.execute_script(script).strip() == output