Skip to content

Commit

Permalink
Test: Add Testem integration example
Browse files Browse the repository at this point in the history
  • Loading branch information
Krinkle committed May 26, 2024
1 parent 6cee5fd commit 4f57777
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 2 deletions.
2 changes: 0 additions & 2 deletions test/integration/karma-qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
}
});
Expand Down
36 changes: 36 additions & 0 deletions test/integration/testem.js
Original file line number Diff line number Diff line change
@@ -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()
);
});
20 changes: 20 additions & 0 deletions test/integration/testem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# QUnit ♥️ Testem

See also <https://github.com/testem/testem/>.

```bash
npm test
```

```
ok 1 Firefox - [0 ms] - add: two numbers
1..1
# tests 1
# pass 1
# skip 0
# todo 0
# fail 0
# ok
```
3 changes: 3 additions & 0 deletions test/integration/testem/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function add (a, b) {
return a + b;
}
5 changes: 5 additions & 0 deletions test/integration/testem/add.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
QUnit.module('add', () => {
QUnit.test('two numbers', assert => {
assert.equal(add(1, 2), 3);
});
});
9 changes: 9 additions & 0 deletions test/integration/testem/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"devDependencies": {
"testem": "3.13.0"
},
"scripts": {
"test": "testem -l 'Headless Firefox' ci"
}
}
1 change: 1 addition & 0 deletions test/integration/testem/qunit
17 changes: 17 additions & 0 deletions test/integration/testem/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<title>Testem</title>
<link rel="stylesheet" href="/qunit/qunit.css">
<script src="/testem.js"></script>
<script src="/qunit/qunit.js"></script>
<script src="add.js"></script>
<script src="add.test.js"></script>
<script>
Testem.hookIntoTestFramework();
</script>
</head>
<body>
<div id="qunit"></div>
</body>
</html>
4 changes: 4 additions & 0 deletions test/integration/testem/testem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"framework": "qunit",
"test_page": "test.html"
}

0 comments on commit 4f57777

Please sign in to comment.