-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathunleash-instance-count.test.ts
72 lines (63 loc) · 1.58 KB
/
unleash-instance-count.test.ts
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
import test from 'ava';
import * as nock from 'nock';
import { tmpdir } from 'os';
import { join } from 'path';
import { mkdirp } from 'mkdirp';
import { Unleash } from '../unleash';
const getUrl = () => `http://test2${Math.round(Math.random() * 100000)}.app/`;
function getRandomBackupPath() {
const path = join(tmpdir(), `test-tmp-${Math.round(Math.random() * 100000)}`);
mkdirp.sync(path);
return path;
}
const defaultToggles = [
{
name: 'feature',
enabled: true,
strategies: [{ name: 'default', constraints: [] }],
},
{
name: 'f-context',
enabled: true,
strategies: [
{
name: 'EnvironmentStrategy',
constraints: [],
parameters: {
environments: 'prod',
},
},
],
},
];
function mockNetwork(toggles = defaultToggles, url = getUrl()) {
nock(url).get('/client/features').reply(200, { features: toggles });
return url;
}
test('should increase instanceCount every time sdk is created ', (t) => {
const baseUrl = `${getUrl()}api`;
mockNetwork([], baseUrl);
const u1 = new Unleash({
appName: 'instance-count-1',
disableMetrics: true,
backupPath: getRandomBackupPath(),
url: baseUrl,
});
const u2 = new Unleash({
appName: 'instance-count-2',
disableMetrics: true,
backupPath: getRandomBackupPath(),
url: baseUrl,
});
const u3 = new Unleash({
appName: 'instance-count-3',
disableMetrics: true,
backupPath: getRandomBackupPath(),
url: baseUrl,
});
// @ts-expect-error
t.is(Unleash.instanceCount, 3);
u1.destroy();
u2.destroy();
u3.destroy();
});