diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..46efd0a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +name: Install > Build > Test + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Using Node.js 12 + uses: actions/setup-node@v1 + with: + node-version: 12.x + - name: Install + run: npm ci + - name: Build + run: npm run build:production + - name: Install Test Dependencies + run: cd test; npm ci; + - name: Test + run: npm test diff --git a/.gitignore b/.gitignore index eb66f12..0f2a2d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/* +**/node_modules/* .vscode/ diff --git a/package.json b/package.json index 1c025ac..02c5348 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,10 @@ "dist" ], "scripts": { - "build": "rollup -c", - "build:production": "NODE_ENV=production rollup -c", - "test": "echo \"Error: no test specified\" && exit 1" + "clean": "rm -rf dist", + "build": "npm run clean; rollup -c", + "build:production": "npm run clean; NODE_ENV=production rollup -c", + "test": "npm run build:production; cd test; npm t" }, "author": { "name": "Timothée 'Tim' Pillard", diff --git a/test/helpers.js b/test/helpers.js index 9e558ea..75b853a 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -10,7 +10,7 @@ async function fetchSample(url) { const response = await fetchPromise; if (response) { if (response.status !== 200) { - const error = new Error('Unable to fetch slice'); + const error = new Error('Unable to fetch sample'); error.response = response; throw error; } @@ -35,5 +35,23 @@ function getArrayBuffer(file) { }); } -window.fetchSample = fetchSample; -window.getArrayBuffer = getArrayBuffer; +async function test(which, what) { + const start = performance.now(); + + try { + const ret = await what(); + + const end = performance.now(); + const out = { case: which, duration: `${end - start}`, length: ret.length }; + console.table(out); + return out; + } catch (_err) { + const msg = `Test failed > ${which} > ${_err.message.replace( + 'Error: ', + '' + )}`; + const err = new Error(); + err.stack = [msg, ..._err.stack.split('\n').slice(1)].join('\n'); + throw err; + } +} diff --git a/test/index.html b/test/index.html index ac15621..010b017 100644 --- a/test/index.html +++ b/test/index.html @@ -2,14 +2,31 @@
- - + + + - - - - \ No newline at end of file + +