-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
npm-publish.js
44 lines (34 loc) · 991 Bytes
/
npm-publish.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
"use strict";
const packed = new Set();
const registry = new Map();
// by default, act like a spy that populates registry
const mockNpmPublish = jest.fn((pkg, tag) => {
registry.set(pkg.name, tag);
return Promise.resolve();
});
const mockNpmPack = jest.fn((rootManifest, packages) => {
packages.forEach(pkg => {
packed.add(pkg.name);
// simulate decoration after npm pack
pkg.tarball = {
filename: `${pkg.name}-MOCKED.tgz`,
};
});
return Promise.resolve();
});
const mockMakePacker = jest.fn(rootManifest => batch => mockNpmPack(rootManifest, batch));
// a convenient format for assertions
function order() {
return Array.from(registry.keys());
}
// keep test data isolated
afterEach(() => {
registry.clear();
packed.clear();
});
module.exports = mockNpmPublish;
module.exports.npmPack = mockNpmPack;
module.exports.makePacker = mockMakePacker;
module.exports.order = order;
module.exports.packed = packed;
module.exports.registry = registry;