-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkarma-bundle.js
80 lines (67 loc) · 2.22 KB
/
karma-bundle.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import 'aurelia-polyfills';
import 'aurelia-loader-webpack';
import {install as installJasmineAsync} from 'jest-jasmine2/jasmine_async';
// enable running Promise-returning tests:
installJasmineAsync(global);
// enable running the same unit tests by using the Jest expect:
installJestExpect();
global.jest = false;
// disable stacktrace limit so we do not loose any error information
Error.stackTraceLimit = Infinity;
// load and run tests:
const testModuleContexts = loadTestModules();
runTests(testModuleContexts);
function loadTestModules() {
const srcContext = require.context(
// directory:
'../src',
// recursive:
true,
// tests in /src folder regex:
/\.spec\.[tj]s$/im
);
const testContext = require.context(
// directory:
'./unit',
// recursive:
true,
// tests in ./unit folder regex:
/\.spec\.[tj]s$/im
);
return [srcContext, testContext];
}
function runTests(contexts) {
contexts.forEach(requireAllInContext);
}
function requireAllInContext(requireContext) {
return requireContext.keys().map(requireContext);
}
/**
* A non-snapshot version of jest-jasmine2/jest-expect
* See https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/jest-expect.js
*/
function installJestExpect() {
const expect = require('jest-matchers');
global.expect = expect;
const jasmine = global.jasmine;
jasmine.anything = expect.anything;
jasmine.any = expect.any;
jasmine.objectContaining = expect.objectContaining;
jasmine.arrayContaining = expect.arrayContaining;
jasmine.stringMatching = expect.stringMatching;
jasmine.addMatchers = (jasmineMatchersObject) => {
const jestMatchersObject = Object.create(null);
Object.keys(jasmineMatchersObject).forEach(name => {
jestMatchersObject[name] = function() {
const result = jasmineMatchersObject[name](jasmine.matchersUtil, null);
// if there is no 'negativeCompare', both should be handled by `compare`
const negativeCompare = result.negativeCompare || result.compare;
return this.isNot
? negativeCompare.apply(null, arguments)
: result.compare.apply(null, arguments);
};
});
const expect = global.expect;
expect.extend(jestMatchersObject);
};
}