-
Notifications
You must be signed in to change notification settings - Fork 6
/
util.js
67 lines (55 loc) · 1.36 KB
/
util.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
"use strict";
let AssetManager = require("faucet-pipeline-core/lib/manager");
let path = require("path");
let assert = require("assert");
let assertSame = assert.strictEqual;
exports.FIXTURES_DIR = path.resolve(__dirname, "fixtures");
exports.MockAssetManager = class MockAssetManager extends AssetManager {
constructor(...args) {
super(...args);
this._writes = [];
}
writeFile(filepath, data, error) {
this._writes.push({ filepath, content: data });
return new Promise(resolve => {
setTimeout(_ => resolve(), 1);
});
}
assertWriteCount(expected) {
assertSame(this._writes.length, expected);
}
assertWrites(expected) {
let actual = this._writes;
assertSame(actual.length, expected.length);
actual.forEach((op, i) => {
let { filepath, content } = expected[i];
assertSame(op.filepath, filepath);
assertSame(op.content, content);
});
}
};
// wraps given code in boilerplate
exports.makeBundle = function makeBundle(code, { compact } = {}) {
if(compact) {
return `
(function(){'use strict';${code}})();
`.trim();
}
return `
(function () {
'use strict';
${code}
})();
`.trim() + "\n";
};
// returns a function that invokes `callback` only after having itself been
// invoked `total` times
exports.awaitInvocations = function awaitAll(total, callback) {
let i = 0;
return _ => {
i++;
if(i === total) {
callback();
}
};
};