Skip to content

Commit

Permalink
Initial web tests (#1446)
Browse files Browse the repository at this point in the history
* Initial web tests

* Add new action for node and web lib tests.
  • Loading branch information
philass authored Aug 16, 2021
1 parent 743968b commit 0e1ad3f
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 1 deletion.
36 changes: 35 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ jobs:
node --version
export EMCFLAGS="-sINITIAL_MEMORY=2147418112 -O1" # 2gb - 64kb... largest value of memory
futhark test -c --backend=wasm --runner=./tools/node-simd.sh --no-tuning --exclude=no_wasm tests examples
make -C tests_lib/javascript -j
test-wasm-multicore:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -441,6 +440,41 @@ jobs:
export EMCFLAGS="-sINITIAL_MEMORY=2147418112 -O1 -s PTHREAD_POOL_SIZE=12" # 2gb - 64kb... largest value of memory
futhark test -c --backend=wasm-multicore --runner=./tools/node-threaded.sh --no-tuning --exclude=no_wasm tests examples
test-wasm-lib:
runs-on: ubuntu-20.04
needs: [build-linux-nix]

steps:
- uses: actions/checkout@v2

- uses: mymindstorm/setup-emsdk@v7
with:
version: 2.0.18
actions-cache-folder: 'emsdk-cache'

- uses: actions/setup-node@v1
with:
node-version: '16.x'

- name: Install Jest
run: |
npm install jest --global
- uses: actions/download-artifact@v2
with:
name: futhark-nightly-linux-x86_64.tar.xz

- name: Install from nightly tarball
run: |
tar xvf futhark-nightly-linux-x86_64.tar.xz
make -C futhark-nightly-linux-x86_64/ install PREFIX=$HOME/.local
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Run tests
run: |
make -C tests_lib/javascript
make -C tests_lib/web
test-tools:
runs-on: ubuntu-20.04
needs: [build-linux-nix]
Expand Down
18 changes: 18 additions & 0 deletions tests_lib/web/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FUTHARK_BACKEND ?= wasm

.PHONY: test clean

test: npm_install do_test_square

do_test_%: %.test.js %.mjs
jest $*.test.js

%.mjs: %.fut
futhark $(FUTHARK_BACKEND) --library $^

clean:
rm -rf *.c *.h *.class.js *.wasm *.mjs

npm_install:
npm install

7 changes: 7 additions & 0 deletions tests_lib/web/jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// jest-puppeteer.config.js
module.exports = {
server: {
command: 'python3 -m http.server 8000',
port: 8000
}
}
20 changes: 20 additions & 0 deletions tests_lib/web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"scripts": {
"test": "jest"
},
"name": "web-tests",
"jest": {
"preset": "jest-puppeteer",
"verbose": true
},
"dependencies": {
"jest-puppeteer": "^5.0.4",
"puppeteer": "^9.1.1",
"puppeteer-core": "^9.1.1"
},
"devDependencies": {
"jest": "^27.0.6",
"jest-cli": "^27.0.6",
"jest-dev-server": "^5.0.3"
}
}
2 changes: 2 additions & 0 deletions tests_lib/web/square.fut
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
entry square (x : i32) = x * x

25 changes: 25 additions & 0 deletions tests_lib/web/square.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html>
<label for="square">Number to Square:</label><br>
<input type="text" value="37" id="square_id" name="square"><br>

<p id="result"></p>

<script type="module">

import { newFutharkContext } from './square.mjs';
var fc;
newFutharkContext().then(fc => {
function myFunction() {
var num_text = document.getElementById("square_id").value;
var num = parseInt(num_text);
var keep = fc.square(num);
document.getElementById("result").innerHTML = keep;
}
myFunction();
});

// Call Futhark function

</script>
</html>
11 changes: 11 additions & 0 deletions tests_lib/web/square.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require('expect-puppeteer');

describe('Futhark entry point : square test', () => {
beforeAll(async () => {
await page.goto('http://localhost:8000/square.html')
})

it('should display "1369" text on page', async () => {
await expect(page).toMatch('1369')
})
})

0 comments on commit 0e1ad3f

Please sign in to comment.