-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
155 lines (126 loc) · 5.65 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
'use strict';
const test = require('ava');
const shell = require('execa');
const {filter, identity, is, map} = require('ramda');
const {create, env} = require('sanctuary');
const multi = require('.');
const {either, fromEither, isLeft} = create({checkTypes: false, env});
const always = (name, version, ago) => ago >= 0;
const never = (name, version, ago) => ago >= Number.MAX_SAFE_INTEGER;
const installDefault = multi({path: 'node_modules'});
const installAlways = multi({delay: 10000, path: 'node_modules', invalidate: always, timeout: 25000});
const installNever = multi({delay: 10000, path: 'node_modules', invalidate: never, timeout: 25000});
const prune = () => shell('yarn', ['install', '--force', '--ignore-scripts', '--prefer-offline']);
test.before(prune);
test.after(prune);
test('installing a valid package with latest version should return Right', async t => {
const install = fromEither({}, await installDefault('ramda', 'latest'));
const {identity} = require('ramda@latest');
t.is(install.installed, true);
t.is(install.name, 'ramda');
t.is(install.version, 'latest');
t.is(identity('hello'), 'hello');
});
test('installing a valid package with an exact version should return Right', async t => {
const install = fromEither({}, await installDefault('ramda', '0.23.0'));
const {identity} = require('ramda@0.23.0');
t.is(install.installed, true);
t.is(install.name, 'ramda');
t.is(install.version, '0.23.0');
t.is(identity('hello'), 'hello');
});
test('installing a valid package with an x-based range should return Right', async t => {
const install = fromEither({}, await installDefault('ramda', '0.23.x'));
const {identity} = require('ramda@0.23.x');
t.is(install.installed, true);
t.is(install.name, 'ramda');
t.is(install.version, '0.23.x');
t.is(identity('hello'), 'hello');
});
test('installing a valid package with an tilde-based range should return Right', async t => {
const install = fromEither({}, await installDefault('ramda', '~0.23.0'));
const {identity} = require('ramda@~0.23.0');
t.is(install.installed, true);
t.is(install.name, 'ramda');
t.is(install.version, '~0.23.0');
t.is(identity('hello'), 'hello');
});
test('installing a valid package with an caret-based range should return Right', async t => {
const install = fromEither({}, await installDefault('ramda', '^0.23.0'));
const {identity} = require('ramda@^0.23.0');
t.is(install.installed, true);
t.is(install.name, 'ramda');
t.is(install.version, '^0.23.0');
t.is(identity('hello'), 'hello');
});
test('installing a valid scoped package should return Right', async t => {
const install = fromEither({}, await installDefault('@rockymadden/now-go', 'latest'));
const req = require('@rockymadden/now-go@latest');
t.is(install.installed, true);
t.is(install.name, '@rockymadden/now-go');
t.is(install.version, 'latest');
t.truthy(req);
});
test('installing a package with an always invalidator should return Right', async t => {
await installAlways('ramda', '0.23.0');
const install = fromEither({}, await installAlways('ramda', '0.23.0'));
const {identity} = require('ramda@0.23.0');
t.is(install.uninstalled, true);
t.is(install.installed, true);
t.is(install.name, 'ramda');
t.is(install.version, '0.23.0');
t.is(identity('hello'), 'hello');
});
test('installing a package with a never invalidator should return Right', async t => {
await installNever('ramda', '0.22.0');
const install = fromEither({}, await installNever('ramda', '0.22.0'));
const {identity} = require('ramda@0.22.0');
t.is(install.uninstalled, false);
t.is(install.installed, false);
t.is(install.name, 'ramda');
t.is(install.version, '0.22.0');
t.is(identity('hello'), 'hello');
});
test('installing a non-existent package with an always invalidator should return Left', async t => {
const install = await installAlways('package-doesnt-exist', '0.0.0');
t.true(isLeft(install));
t.true(is(Error, either(identity, identity)(install)));
});
test('installing a non-existent package version with an always invalidator should return Left', async t => {
const install = await installAlways('ramda', '99.99.99');
t.true(isLeft(install));
t.true(is(Error, either(identity, identity)(install)));
});
test('installing a non-existent package with a never invalidator should return Left', async t => {
const install = await installNever('package-doesnt-exist', '0.0.0');
t.true(isLeft(install));
t.true(is(Error, either(identity, identity)(install)));
});
test('installing a non-existent package version with a never invalidator should return Left', async t => {
const install = await installNever('ramda', '99.99.99');
t.true(isLeft(install));
t.true(is(Error, either(identity, identity)(install)));
});
test('installing a valid package numerous times concurrently less than timeout should return Right', async t => {
const toInstall = [
installAlways('ramda', '0.21.0'),
installAlways('ramda', '0.21.0')
];
const installs = map(either(identity, identity), await Promise.all(toInstall));
const delayed0 = filter(i => i.delayed === 0, installs)[0];
const delayedGreaterThan0 = filter(i => i.delayed > 0, installs)[0];
t.true(delayed0.installed);
t.true(delayedGreaterThan0.installed);
});
test('installing a valid package numerous times concurrently greater than timeout should return Left', async t => {
const toInstall = [
installAlways('ramda', '0.20.0'),
installAlways('ramda', '0.20.0'),
installAlways('ramda', '0.20.0'),
installAlways('ramda', '0.20.0'),
installAlways('ramda', '0.20.0')
];
const installs = map(either(identity, identity), await Promise.all(toInstall));
const delayedMaximum = filter(i => is(Error, i) && i.message === 'Delayed exceeds timeout', installs)[0];
t.truthy(delayedMaximum);
});