forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupTestFramework.js
134 lines (126 loc) · 3.18 KB
/
setupTestFramework.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
expect.extend({
toBeTypeOf(received, expected) {
const objType = typeof received;
const pass = objType === expected;
const message = pass
? () =>
this.utils.matcherHint(".not.toBeTypeOf") +
"\n\n" +
"Expected value to not be (using typeof):\n" +
` ${this.utils.printExpected(expected)}\n` +
"Received:\n" +
` ${this.utils.printReceived(objType)}`
: () =>
this.utils.matcherHint(".toBeTypeOf") +
"\n\n" +
"Expected value to be (using typeof):\n" +
` ${this.utils.printExpected(expected)}\n` +
"Received:\n" +
` ${this.utils.printReceived(objType)}`;
return { message, pass };
},
toEndWith(received, expected) {
const pass = typeof received === "string" && received.endsWith(expected);
const message = pass
? () =>
this.utils.matcherHint(".not.toEndWith") +
"\n\n" +
"Expected value to not end with:\n" +
` ${this.utils.printExpected(expected)}\n` +
"Received:\n" +
` ${this.utils.printReceived(received)}`
: () =>
this.utils.matcherHint(".toEndWith") +
"\n\n" +
"Expected value to end with:\n" +
` ${this.utils.printExpected(expected)}\n` +
"Received:\n" +
` ${this.utils.printReceived(received)}`;
return { message, pass };
}
});
if (process.env.ALTERNATIVE_SORT) {
const oldSort = Array.prototype.sort;
Array.prototype.sort = function (cmp) {
oldSort.call(this, cmp);
if (cmp) {
for (let i = 1; i < this.length; i++) {
if (cmp(this[i - 1], this[i]) === 0) {
let j = i + 1;
for (; j < this.length; j++) {
if (cmp(this[j - 1], this[j]) !== 0) {
break;
}
}
for (let x = i - 1, y = j - 1; x < y; x++, y--) {
const temp = this[x];
this[x] = this[y];
this[y] = temp;
}
i = j;
}
}
}
return this;
};
}
// Setup debugging info for tests
if (process.env.DEBUG_INFO) {
const addDebugInfo = it => {
return (name, fn, timeout) => {
if (fn.length === 0) {
it(
name,
() => {
process.stdout.write(`START1 ${name}\n`);
try {
const promise = fn();
if (promise && promise.then) {
return promise.then(
r => {
process.stdout.write(`DONE OK ${name}\n`);
return r;
},
e => {
process.stdout.write(`DONE FAIL ${name}\n`);
throw e;
}
);
} else {
process.stdout.write(`DONE OK ${name}\n`);
}
} catch (e) {
process.stdout.write(`DONE FAIL ${name}\n`);
throw e;
}
},
timeout
);
} else {
it(
name,
done => {
process.stdout.write(`START2 ${name}\n`);
return fn(err => {
if (err) {
process.stdout.write(`DONE FAIL ${name}\n`);
} else {
process.stdout.write(`DONE OK ${name}\n`);
}
return done(err);
});
},
timeout
);
}
};
};
const env = jasmine.getEnv();
env.it = addDebugInfo(env.it);
}
// Workaround for a memory leak in wabt
// It leaks an Error object on construction
// so it leaks the whole stack trace
require("wast-loader");
process.removeAllListeners("uncaughtException");
process.removeAllListeners("unhandledRejection");