Skip to content

Commit 9aa3110

Browse files
committed
Test: Add Testem integration example
1 parent 6cee5fd commit 9aa3110

File tree

9 files changed

+99
-2
lines changed

9 files changed

+99
-2
lines changed

test/integration/karma-qunit.js

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ function normalize (str) {
1313

1414
QUnit.module('karma-qunit', {
1515
before: () => {
16-
// Need --legacy-peer-deps under npm 7 for "file:" override in package.json.
17-
// Once CI and dev environments are on npm 8, consider using native "overrides".
1816
cp.execSync('npm install --prefer-offline --no-audit --omit=dev --legacy-peer-deps', { cwd: DIR, encoding: 'utf8' });
1917
}
2018
});

test/integration/testem.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const cp = require('child_process');
2+
const path = require('path');
3+
const DIR = path.join(__dirname, 'testem');
4+
5+
function normalize (str) {
6+
return str
7+
.trim()
8+
.replace(/(Firefox) [\d.]+/g, '$1')
9+
.replace(/(\d+ ms)/g, '0 ms');
10+
}
11+
12+
QUnit.module('testem', {
13+
before: () => {
14+
// Let this be quick for re-runs
15+
cp.execSync('npm install --prefer-offline --no-audit', { cwd: DIR, encoding: 'utf8' });
16+
}
17+
});
18+
19+
QUnit.test('passing test', assert => {
20+
const ret = cp.execSync('npm run -s test', { cwd: DIR, encoding: 'utf8' });
21+
assert.strictEqual(
22+
normalize(ret),
23+
`
24+
ok 1 Firefox - [0 ms] - add: two numbers
25+
26+
1..1
27+
# tests 1
28+
# pass 1
29+
# skip 0
30+
# todo 0
31+
# fail 0
32+
33+
# ok
34+
`.trim()
35+
);
36+
});

test/integration/testem/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# QUnit ♥️ Testem
2+
3+
See also <https://github.com/testem/testem/>.
4+
5+
```bash
6+
npm test
7+
```
8+
9+
```
10+
ok 1 Firefox - [0 ms] - add: two numbers
11+
12+
1..1
13+
# tests 1
14+
# pass 1
15+
# skip 0
16+
# todo 0
17+
# fail 0
18+
19+
# ok
20+
```

test/integration/testem/add.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* eslint-disable no-unused-vars */
2+
3+
function add (a, b) {
4+
return a + b;
5+
}

test/integration/testem/add.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* global add */
2+
QUnit.module('add', () => {
3+
QUnit.test('two numbers', assert => {
4+
assert.equal(add(1, 2), 3);
5+
});
6+
});

test/integration/testem/package.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"private": true,
3+
"devDependencies": {
4+
"testem": "3.13.0"
5+
},
6+
"scripts": {
7+
"test": "testem -l 'Headless Firefox' ci"
8+
}
9+
}

test/integration/testem/qunit

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../qunit

test/integration/testem/test.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Testem</title>
5+
<link rel="stylesheet" href="/qunit/qunit.css">
6+
<script src="/testem.js"></script>
7+
<script src="/qunit/qunit.js"></script>
8+
<script src="add.js"></script>
9+
<script src="add.test.js"></script>
10+
<script>
11+
/* global Testem */
12+
Testem.hookIntoTestFramework();
13+
</script>
14+
</head>
15+
<body>
16+
<div id="qunit"></div>
17+
</body>
18+
</html>

test/integration/testem/testem.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"framework": "qunit",
3+
"test_page": "test.html"
4+
}

0 commit comments

Comments
 (0)