-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathrun-tests.js
37 lines (32 loc) · 1.07 KB
/
run-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const { unsetRootParent } = require('../../lib/server/utilities');
const isKarma =
typeof window === 'object' && typeof window.__karma__ === 'object';
/**
* Runs tests.
*
* @param {Function} assert - Assert.
* @param {Object} testCases - Test cases.
* @param {Function} actualParser - Actual parser.
* @param {Function} expectedParser - Expected parser.
*/
module.exports = function runTests(
assert,
actualParser,
expectedParser,
testCases,
) {
testCases.forEach(function (testCase) {
const _it = testCase.only ? it.only : testCase.skip ? it.skip : it;
_it('parses ' + testCase.name, function () {
let actualOutput = actualParser(testCase.data);
let expectedOutput = unsetRootParent(expectedParser(testCase.data));
// use `JSON.decycle` since `assert.deepEqual` fails
// when instance types are different in the browser
if (isKarma) {
actualOutput = JSON.decycle(actualOutput);
expectedOutput = JSON.decycle(expectedOutput);
}
assert.deepEqual(actualOutput, expectedOutput);
});
});
};