-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathtest_all_toggles.js
37 lines (33 loc) · 1.23 KB
/
test_all_toggles.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
const { initialize, isEnabled, getVariant, getFeatureToggleDefinitions } = require('../lib');
const url = process.env.UNLEASH_API_URL || 'https://app.unleash-hosted.com/demo/api';
const apiKey = process.env.UNLEASH_API_KEY || '56907a2fa53c1d16101d509a10b78e36190b0f918d9f122d';
const client = initialize({
appName: 'test-all-toggles',
url,
metricsInterval: 2000,
refreshInterval: 1000,
customHeaders: {
Authorization: apiKey,
},
});
client.on('error', console.error);
client.on('warn', console.log);
// client.on('unchanged', () => console.error('NOT CHANGED'));
client.on('changed', () => console.log('CHANGED!'));
console.log(`Fetching toggles from: ${url}`);
setInterval(() => {
const userId = Math.random() * 1000;
process.stdout.write('\u001b[2J\u001b[0;0H');
console.log(`current userId: ${userId}`);
getFeatureToggleDefinitions()
.sort((a, b) => {
if (a.name.toLocaleLowerCase() > b.name.toLocaleLowerCase()) return 1;
if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) return -1;
return 0;
})
.forEach((t) => {
console.log(`${t.name} (${t.project}):
Enabled: ${isEnabled(t.name, { userId })} \t Variant: ${getVariant(t.name, { userId }).name}
`);
});
}, 1000);