diff --git a/.travis.yml b/.travis.yml index cbab6ae216..aff28cd6a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/wasm/demo/package.json b/wasm/demo/package.json index 2184c6db84..a03c80aced 100644 --- a/wasm/demo/package.json +++ b/wasm/demo/package.json @@ -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", diff --git a/wasm/tests/.travis-runner.sh b/wasm/tests/.travis-runner.sh new file mode 100755 index 0000000000..add96c6b24 --- /dev/null +++ b/wasm/tests/.travis-runner.sh @@ -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) diff --git a/wasm/tests/Pipfile b/wasm/tests/Pipfile new file mode 100644 index 0000000000..547282c585 --- /dev/null +++ b/wasm/tests/Pipfile @@ -0,0 +1,13 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +pytest = "*" +selenium = "*" + +[dev-packages] + +[requires] +python_version = "3" diff --git a/wasm/tests/Pipfile.lock b/wasm/tests/Pipfile.lock new file mode 100644 index 0000000000..7f8b97f879 --- /dev/null +++ b/wasm/tests/Pipfile.lock @@ -0,0 +1,87 @@ +{ + "_meta": { + "hash": { + "sha256": "e7ebbd25509f50c886b2e9773e88b011af0cbc4bfcfebb386024be80d2c3aa49" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "atomicwrites": { + "hashes": [ + "sha256:03472c30eb2c5d1ba9227e4c2ca66ab8287fbfbbda3888aa93dc2e28fc6811b4", + "sha256:75a9445bac02d8d058d5e1fe689654ba5a6556a1dfd8ce6ec55a0ed79866cfa6" + ], + "version": "==1.3.0" + }, + "attrs": { + "hashes": [ + "sha256:69c0dbf2ed392de1cb5ec704444b08a5ef81680a61cb899dc08127123af36a79", + "sha256:f0b870f674851ecbfbbbd364d6b5cbdff9dcedbc7f3f5e18a6891057f21fe399" + ], + "version": "==19.1.0" + }, + "more-itertools": { + "hashes": [ + "sha256:0125e8f60e9e031347105eb1682cef932f5e97d7b9a1a28d9bf00c22a5daef40", + "sha256:590044e3942351a1bdb1de960b739ff4ce277960f2425ad4509446dbace8d9d1" + ], + "markers": "python_version > '2.7'", + "version": "==6.0.0" + }, + "pluggy": { + "hashes": [ + "sha256:19ecf9ce9db2fce065a7a0586e07cfb4ac8614fe96edf628a264b1c70116cf8f", + "sha256:84d306a647cc805219916e62aab89caa97a33a1dd8c342e87a37f91073cd4746" + ], + "version": "==0.9.0" + }, + "py": { + "hashes": [ + "sha256:64f65755aee5b381cea27766a3a147c3f15b9b6b9ac88676de66ba2ae36793fa", + "sha256:dc639b046a6e2cff5bbe40194ad65936d6ba360b52b3c3fe1d08a82dd50b5e53" + ], + "version": "==1.8.0" + }, + "pytest": { + "hashes": [ + "sha256:592eaa2c33fae68c7d75aacf042efc9f77b27c08a6224a4f59beab8d9a420523", + "sha256:ad3ad5c450284819ecde191a654c09b0ec72257a2c711b9633d677c71c9850c4" + ], + "index": "pypi", + "version": "==4.3.1" + }, + "selenium": { + "hashes": [ + "sha256:2d7131d7bc5a5b99a2d9b04aaf2612c411b03b8ca1b1ee8d3de5845a9be2cb3c", + "sha256:deaf32b60ad91a4611b98d8002757f29e6f2c2d5fcaf202e1c9ad06d6772300d" + ], + "index": "pypi", + "version": "==3.141.0" + }, + "six": { + "hashes": [ + "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", + "sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73" + ], + "version": "==1.12.0" + }, + "urllib3": { + "hashes": [ + "sha256:61bf29cada3fc2fbefad4fdf059ea4bd1b4a86d2b6d15e1c7c0b582b9752fe39", + "sha256:de9529817c93f27c8ccbfead6985011db27bd0ddfcdb2d86f3f663385c6a9c22" + ], + "version": "==1.24.1" + } + }, + "develop": {} +} diff --git a/wasm/tests/test_demo.py b/wasm/tests/test_demo.py new file mode 100644 index 0000000000..9dce406811 --- /dev/null +++ b/wasm/tests/test_demo.py @@ -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