forked from rollup/rollup
/
_config.js
37 lines (35 loc) · 836 Bytes
/
_config.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 assert = require('assert');
const fs = require('fs');
const fsReadFile = fs.readFile;
let currentReads = 0;
let maxReads = 0;
module.exports = {
description: 'maxParallelFileReads with plugin',
options: {
maxParallelFileReads: 3,
plugins: [
{
async load(id) {
return new Promise((fulfil, reject) =>
fs.readFile(id, 'utf-8', (err, contents) => (err ? reject(err) : fulfil(contents)))
);
}
}
]
},
before() {
fs.readFile = (path, options, callback) => {
console.log('mock read');
currentReads++;
maxReads = Math.max(maxReads, currentReads);
fsReadFile(path, options, (err, data) => {
currentReads--;
callback(err, data);
});
};
},
after() {
fs.readFile = fsReadFile;
assert.strictEqual(maxReads, 3, 'Wrong number of parallel file reads: ' + maxReads);
}
};