forked from sindresorhus/np
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
91 lines (79 loc) · 2.79 KB
/
index.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
import test from 'ava';
import sinon from 'sinon';
import proxyquire from 'proxyquire';
import np from '../source';
const defaultOptions = {
cleanup: true,
tests: true,
publish: true,
runPublish: true,
availability: {
isAvailable: false,
isUnknown: false
}
};
test('version is invalid', async t => {
const message = 'Version should be either patch, minor, major, prepatch, preminor, premajor, prerelease, or a valid semver version.';
await t.throwsAsync(np('foo', defaultOptions), message);
await t.throwsAsync(np('4.x.3', defaultOptions), message);
});
test('version is pre-release', async t => {
const message = 'You must specify a dist-tag using --tag when publishing a pre-release version. This prevents accidentally tagging unstable versions as "latest". https://docs.npmjs.com/cli/dist-tag';
await t.throwsAsync(np('premajor', defaultOptions), message);
await t.throwsAsync(np('preminor', defaultOptions), message);
await t.throwsAsync(np('prepatch', defaultOptions), message);
await t.throwsAsync(np('prerelease', defaultOptions), message);
await t.throwsAsync(np('10.0.0-0', defaultOptions), message);
await t.throwsAsync(np('10.0.0-beta', defaultOptions), message);
});
test('errors on too low version', async t => {
await t.throwsAsync(np('1.0.0', defaultOptions), /New version `1\.0\.0` should be higher than current version `\d+\.\d+\.\d+`/);
await t.throwsAsync(np('1.0.0-beta', defaultOptions), /New version `1\.0\.0-beta` should be higher than current version `\d+\.\d+\.\d+`/);
});
test('skip enabling 2FA if the package exists', async t => {
const enable2faStub = sinon.stub();
const np = proxyquire('../source', {
del: sinon.stub(),
execa: sinon.stub().returns({pipe: sinon.stub()}),
'./prerequisite-tasks': sinon.stub(),
'./git-tasks': sinon.stub(),
'./git-util': {
hasUpstream: sinon.stub().returns(true),
pushGraceful: sinon.stub()
},
'./npm/enable-2fa': enable2faStub,
'./npm/publish': sinon.stub().returns({pipe: sinon.stub()})
});
await t.notThrowsAsync(np('1.0.0', {
...defaultOptions,
availability: {
isAvailable: false,
isUnknown: false
}
}));
t.true(enable2faStub.notCalled);
});
test('skip enabling 2FA if the `2fa` option is false', async t => {
const enable2faStub = sinon.stub();
const np = proxyquire('../source', {
del: sinon.stub(),
execa: sinon.stub().returns({pipe: sinon.stub()}),
'./prerequisite-tasks': sinon.stub(),
'./git-tasks': sinon.stub(),
'./git-util': {
hasUpstream: sinon.stub().returns(true),
pushGraceful: sinon.stub()
},
'./npm/enable-2fa': enable2faStub,
'./npm/publish': sinon.stub().returns({pipe: sinon.stub()})
});
await t.notThrowsAsync(np('1.0.0', {
...defaultOptions,
availability: {
isAvailable: true,
isUnknown: false
},
'2fa': false
}));
t.true(enable2faStub.notCalled);
});