-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathnpm-parser.test.ts
More file actions
137 lines (111 loc) · 4.39 KB
/
npm-parser.test.ts
File metadata and controls
137 lines (111 loc) · 4.39 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import * as npmparser from '../src/util/npm-parser';
import test from 'node:test';
import assert from 'assert/strict';
const kilobyte = 1024;
const megabyte = 1024 * 1024;
test('getHexColor B green', () => {
const actual = npmparser.getHexColor(712);
assert.equal(actual, npmparser.color.brightgreen);
});
test('getHexColor kB green', () => {
const actual = npmparser.getHexColor(kilobyte * 3.14);
assert.equal(actual, npmparser.color.brightgreen);
});
test('getHexColor 900 kB limegreen', () => {
const actual = npmparser.getHexColor(kilobyte * 900);
assert.equal(actual, npmparser.color.limegreen);
});
test('getHexColor 2 MB blue', () => {
const actual = npmparser.getHexColor(megabyte * 2);
assert.equal(actual, npmparser.color.blue);
});
test('getHexColor 10 MB yellow', () => {
const actual = npmparser.getHexColor(megabyte * 10);
assert.equal(actual, npmparser.color.yellow);
});
test('getHexColor 40 MB orange', () => {
const actual = npmparser.getHexColor(megabyte * 40);
assert.equal(actual, npmparser.color.orange);
});
test('getHexColor 80 MB red', () => {
const actual = npmparser.getHexColor(megabyte * 80);
assert.equal(actual, npmparser.color.orange);
});
test('getHexColor 120 MB red', () => {
const actual = npmparser.getHexColor(megabyte * 120);
assert.equal(actual, npmparser.color.red);
});
test('getHexColor 700 MB super red pink', () => {
const actual = npmparser.getHexColor(megabyte * 700);
assert.equal(actual, npmparser.color.pink);
});
test('getReadableFileSize 512 B', () => {
const actual = npmparser.getReadableFileSize(512);
assert.equal(actual.size, '512');
assert.equal(actual.unit, 'B');
});
test('getReadableFileSize 3.14 kB', () => {
const actual = npmparser.getReadableFileSize(kilobyte * 3.14);
assert.equal(actual.size, '3.14');
assert.equal(actual.unit, 'kB');
});
test('getReadableFileSize 1 MB', () => {
const actual = npmparser.getReadableFileSize(megabyte);
assert.equal(actual.size, '1.00');
assert.equal(actual.unit, 'MB');
});
test('getReadableFileSize 10 MB', () => {
const actual = npmparser.getReadableFileSize(megabyte * 16.3);
assert.equal(actual.size, '16.3');
assert.equal(actual.unit, 'MB');
});
test('getReadableFileSize 712 MB', () => {
const actual = npmparser.getReadableFileSize(megabyte * 712.8);
assert.equal(actual.size, '713');
assert.equal(actual.unit, 'MB');
});
test('getReadableFileSize 5.86 GB', () => {
const actual = npmparser.getReadableFileSize(megabyte * 6000);
assert.equal(actual.size, '5.86');
assert.equal(actual.unit, 'GB');
});
test('parsePackageString without scope and with version', () => {
const actual = npmparser.parsePackageString('foo@1.2.3');
assert.deepEqual(actual, { scoped: false, name: 'foo', version: '1.2.3' });
});
test('parsePackageString with scope and with version', () => {
const actual = npmparser.parsePackageString('@types/foo@1.2.3');
assert.deepEqual(actual, { scoped: true, name: '@types/foo', version: '1.2.3' });
});
test('parsePackageString without scope and without version', () => {
const actual = npmparser.parsePackageString('foo');
assert.deepEqual(actual, { scoped: false, name: 'foo', version: null });
});
test('parsePackageString with scope and without version', () => {
const actual = npmparser.parsePackageString('@types/foo');
assert.deepEqual(actual, { scoped: true, name: '@types/foo', version: null });
});
test('parsePackageString with leading space', () => {
const actual = npmparser.parsePackageString(' @types/foo');
assert.deepEqual(actual, { scoped: true, name: '@types/foo', version: null });
});
test('parsePackageString with trailing space', () => {
const actual = npmparser.parsePackageString(' @types/foo ');
assert.deepEqual(actual, { scoped: true, name: '@types/foo', version: null });
});
test('isFullRelease 1.2.3', () => {
const actual = npmparser.isFullRelease('1.2.3');
assert.equal(actual, true);
});
test('isFullRelease 10.0.39', () => {
const actual = npmparser.isFullRelease('10.0.39');
assert.equal(actual, true);
});
test('isFullRelease 2.9.0-dev.20180323', () => {
const actual = npmparser.isFullRelease('2.9.0-dev.20180323');
assert.equal(actual, false);
});
test('isFullRelease 2.0.0-alpha.1', () => {
const actual = npmparser.isFullRelease('2.0.0-alpha.1');
assert.equal(actual, false);
});