From 4f5777724795d9c32b4a00590dbebfab52a77230 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sun, 26 May 2024 18:34:10 +0100 Subject: [PATCH] Test: Add Testem integration example --- test/integration/karma-qunit.js | 2 -- test/integration/testem.js | 36 ++++++++++++++++++++++++++++ test/integration/testem/README.md | 20 ++++++++++++++++ test/integration/testem/add.js | 3 +++ test/integration/testem/add.test.js | 5 ++++ test/integration/testem/package.json | 9 +++++++ test/integration/testem/qunit | 1 + test/integration/testem/test.html | 17 +++++++++++++ test/integration/testem/testem.json | 4 ++++ 9 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 test/integration/testem.js create mode 100644 test/integration/testem/README.md create mode 100644 test/integration/testem/add.js create mode 100644 test/integration/testem/add.test.js create mode 100644 test/integration/testem/package.json create mode 120000 test/integration/testem/qunit create mode 100644 test/integration/testem/test.html create mode 100644 test/integration/testem/testem.json diff --git a/test/integration/karma-qunit.js b/test/integration/karma-qunit.js index b739f1b63..2cc635aa4 100644 --- a/test/integration/karma-qunit.js +++ b/test/integration/karma-qunit.js @@ -13,8 +13,6 @@ function normalize (str) { QUnit.module('karma-qunit', { before: () => { - // Need --legacy-peer-deps under npm 7 for "file:" override in package.json. - // Once CI and dev environments are on npm 8, consider using native "overrides". cp.execSync('npm install --prefer-offline --no-audit --omit=dev --legacy-peer-deps', { cwd: DIR, encoding: 'utf8' }); } }); diff --git a/test/integration/testem.js b/test/integration/testem.js new file mode 100644 index 000000000..af43a3de7 --- /dev/null +++ b/test/integration/testem.js @@ -0,0 +1,36 @@ +const cp = require('child_process'); +const path = require('path'); +const DIR = path.join(__dirname, 'testem'); + +function normalize (str) { + return str + .trim() + .replace(/(Firefox) [\d\.]+/g, '$1') + .replace(/(\d+ ms)/g, '0 ms'); +} + +QUnit.module('testem', { + before: () => { + // Let this be quick for re-runs + cp.execSync('npm install --prefer-offline --no-audit', { cwd: DIR, encoding: 'utf8' }); + } +}); + +QUnit.test('passing test', assert => { + const ret = cp.execSync('npm run -s test', { cwd: DIR, encoding: 'utf8' }); + assert.strictEqual( + normalize(ret), + ` +ok 1 Firefox - [0 ms] - add: two numbers + +1..1 +# tests 1 +# pass 1 +# skip 0 +# todo 0 +# fail 0 + +# ok + `.trim() + ); +}); diff --git a/test/integration/testem/README.md b/test/integration/testem/README.md new file mode 100644 index 000000000..cd52c6a17 --- /dev/null +++ b/test/integration/testem/README.md @@ -0,0 +1,20 @@ +# QUnit ♥️ Testem + +See also . + +```bash +npm test +``` + +``` +ok 1 Firefox - [0 ms] - add: two numbers + +1..1 +# tests 1 +# pass 1 +# skip 0 +# todo 0 +# fail 0 + +# ok +``` diff --git a/test/integration/testem/add.js b/test/integration/testem/add.js new file mode 100644 index 000000000..640d4d23e --- /dev/null +++ b/test/integration/testem/add.js @@ -0,0 +1,3 @@ +function add (a, b) { + return a + b; +} diff --git a/test/integration/testem/add.test.js b/test/integration/testem/add.test.js new file mode 100644 index 000000000..3b1d19b66 --- /dev/null +++ b/test/integration/testem/add.test.js @@ -0,0 +1,5 @@ +QUnit.module('add', () => { + QUnit.test('two numbers', assert => { + assert.equal(add(1, 2), 3); + }); +}); diff --git a/test/integration/testem/package.json b/test/integration/testem/package.json new file mode 100644 index 000000000..09167ddd4 --- /dev/null +++ b/test/integration/testem/package.json @@ -0,0 +1,9 @@ +{ + "private": true, + "devDependencies": { + "testem": "3.13.0" + }, + "scripts": { + "test": "testem -l 'Headless Firefox' ci" + } +} diff --git a/test/integration/testem/qunit b/test/integration/testem/qunit new file mode 120000 index 000000000..24e236ddd --- /dev/null +++ b/test/integration/testem/qunit @@ -0,0 +1 @@ +../../../qunit \ No newline at end of file diff --git a/test/integration/testem/test.html b/test/integration/testem/test.html new file mode 100644 index 000000000..8a140eb60 --- /dev/null +++ b/test/integration/testem/test.html @@ -0,0 +1,17 @@ + + + +Testem + + + + + + + + +
+ + diff --git a/test/integration/testem/testem.json b/test/integration/testem/testem.json new file mode 100644 index 000000000..4f9ba0f88 --- /dev/null +++ b/test/integration/testem/testem.json @@ -0,0 +1,4 @@ +{ + "framework": "qunit", + "test_page": "test.html" +}