-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.test.js
More file actions
79 lines (65 loc) · 2.63 KB
/
debug.test.js
File metadata and controls
79 lines (65 loc) · 2.63 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
import { OpenFeature } from '@openfeature/web-sdk';
import { SplitFactory } from '@splitsoftware/splitio-browserjs';
import { OpenFeatureSplitProvider } from '../../lib/js-split-provider';
describe('OpenFeature Split Provider - Debug Tests', () => {
let client;
let splitClient;
beforeAll(async () => {
// Create with more debug options
const splitFactory = SplitFactory({
core: {
authorizationKey: 'localhost',
},
// Define the features directly
features: {
'my_feature': 'on',
'some_other_feature': 'off',
'int_feature': '32',
'obj_feature': '{"key": "value"}'
}
});
splitClient =splitFactory.client();
// Add direct Split client test to verify it works as expected
console.log('Direct Split client test:');
console.log('- my_feature:', splitClient.getTreatment('my_feature'));
console.log('- some_other_feature:', splitClient.getTreatment('some_other_feature'));
console.log('- int_feature:', splitClient.getTreatment('int_feature'));
console.log('- obj_feature:', splitClient.getTreatment('obj_feature'));
// Create provider
const provider = new OpenFeatureSplitProvider(splitFactory);
// Register provider
OpenFeature.setProvider(provider);
// Get client
client = OpenFeature.getClient('debug-test');
// Context we'll use in tests
const context = { targetingKey: 'test-user' };
// Test OpenFeature client directly in setup to debug issues
try {
const boolResult = await client.getBooleanValue('my_feature', false, context);
console.log('OpenFeature boolean test:', boolResult);
const stringResult = await client.getStringValue('some_other_feature', 'default', context);
console.log('OpenFeature string test:', stringResult);
const numberResult = await client.getNumberValue('int_feature', 0, context);
console.log('OpenFeature number test:', numberResult);
const objectResult = await client.getObjectValue('obj_feature', {}, context);
console.log('OpenFeature object test:', objectResult);
} catch (e) {
console.error('Error in OpenFeature test:', e);
}
});
afterAll(async () => {
if (splitClient) {
await splitClient.destroy();
}
});
// Simple test to verify we can run a test at all
test('should create client and provider', () => {
expect(client).toBeDefined();
expect(splitClient).toBeDefined();
});
// Basic test to validate Split direct API
test('Split client works directly', () => {
const treatment = splitClient.getTreatment('my_feature');
expect(treatment).toBe('on');
});
});