-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
48 lines (40 loc) · 1.23 KB
/
test.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
'use strict';
const rejectUnsatisfiedNpmVersion = require('.');
const test = require('tape');
const MAX_VERSION = `${Number.MAX_SAFE_INTEGER}.${Number.MAX_SAFE_INTEGER}.${Number.MAX_SAFE_INTEGER}`;
test('rejectUnsatisfiedNpmVersion()', async t => {
await rejectUnsatisfiedNpmVersion('6.1.0');
t.pass('should be resolved when npm CLI satisfies the required verion.');
try {
await require('.')(MAX_VERSION);
} catch ({code, message}) {
t.ok(
message.includes(`Expected a version of npm CLI to be ${MAX_VERSION} or greater, but an older version `),
'should fail when npm CLI does\'t satisfy the required version.'
);
t.equal(
code,
'ERR_TOO_OLD_NPM',
'should add `code` property to the error when npm CLI does\'t satisfy the required version.'
);
}
try {
await rejectUnsatisfiedNpmVersion();
} catch (err) {
t.equal(
err.toString(),
'RangeError: Expected 1 argument (<string>), but got no arguments.',
'should fail when it takes no arguments.'
);
}
try {
await rejectUnsatisfiedNpmVersion('0.0.0', '1.1.1');
} catch (err) {
t.equal(
err.toString(),
'RangeError: Expected 1 argument (<string>), but got 2 arguments.',
'should fail when it takes too many arguments.'
);
}
t.end();
});