@thumbmarkjs/thumbmarkjs 1.9.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -102
- package/dist/thumbmark.cjs.js +1 -1
- package/dist/thumbmark.cjs.js.map +1 -1
- package/dist/thumbmark.esm.d.ts +6 -0
- package/dist/thumbmark.esm.js +1 -1
- package/dist/thumbmark.esm.js.map +1 -1
- package/dist/thumbmark.umd.js +1 -1
- package/dist/thumbmark.umd.js.map +1 -1
- package/dist/types/factory.d.ts +0 -4
- package/dist/types/options.d.ts +6 -0
- package/package.json +102 -71
- package/src/factory.ts +0 -4
- package/src/functions/api.ts +19 -6
- package/src/functions/index.ts +1 -1
- package/src/options.ts +7 -0
- package/dist/types/components/intl/index.d.ts +0 -2
- package/dist/types/components/mediaDevices/index.d.ts +0 -2
- package/src/components/canvas/index.test.ts +0 -38
- package/src/components/hardware/index.test.ts +0 -80
- package/src/components/intl/index.test.ts +0 -124
- package/src/components/intl/index.ts +0 -41
- package/src/components/mediaDevices/index.test.ts +0 -120
- package/src/components/mediaDevices/index.ts +0 -26
- package/src/components/system/browser.test.ts +0 -108
- package/src/components/webgl/index.test.ts +0 -223
- package/src/functions/api.test.ts +0 -366
- package/src/functions/filterComponents.test.ts +0 -273
- package/src/functions/functions.test.ts +0 -142
- package/src/functions/metadata.test.ts +0 -211
- package/src/options.test.ts +0 -10
- package/src/thumbmark.custom-components.test.ts +0 -87
- package/src/thumbmark.test.ts +0 -59
- package/src/utils/cache.test.ts +0 -95
- package/src/utils/raceAll.test.ts +0 -86
- package/src/utils/stableStringify.test.ts +0 -335
- package/src/utils/visitorId.test.ts +0 -102
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { getVisitorId, setVisitorId } from './visitorId';
|
|
2
|
-
import { defaultOptions, options, OptionsAfterDefaults } from '../options';
|
|
3
|
-
|
|
4
|
-
describe('visitorId storage tests', () => {
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
// Clear localStorage before each test to ensure isolation
|
|
7
|
-
localStorage.clear();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
describe('storage_property_name option', () => {
|
|
11
|
-
test('should use default storage property name', () => {
|
|
12
|
-
const visitorId = 'test-visitor-123';
|
|
13
|
-
const options = { ...defaultOptions };
|
|
14
|
-
|
|
15
|
-
setVisitorId(visitorId, options);
|
|
16
|
-
|
|
17
|
-
// Verify it was stored with the default property name
|
|
18
|
-
expect(localStorage.getItem('thumbmark_visitor_id')).toBe(visitorId);
|
|
19
|
-
expect(getVisitorId(options)).toBe(visitorId);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('should use custom storage property name', () => {
|
|
23
|
-
const visitorId = 'custom-visitor-456';
|
|
24
|
-
const customOptions: OptionsAfterDefaults = {
|
|
25
|
-
...defaultOptions,
|
|
26
|
-
storage_property_name: 'my_custom_visitor_key'
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
setVisitorId(visitorId, customOptions);
|
|
30
|
-
|
|
31
|
-
// Verify it was stored with the custom property name
|
|
32
|
-
expect(localStorage.getItem('my_custom_visitor_key')).toBe(visitorId);
|
|
33
|
-
expect(getVisitorId(customOptions)).toBe(visitorId);
|
|
34
|
-
|
|
35
|
-
// Verify it's NOT in the default location
|
|
36
|
-
expect(localStorage.getItem('thumbmark_visitor_id')).toBeNull();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('should return null when storage property does not exist', () => {
|
|
40
|
-
const options: OptionsAfterDefaults = {
|
|
41
|
-
...defaultOptions,
|
|
42
|
-
storage_property_name: 'nonexistent_key'
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
expect(getVisitorId(options)).toBeNull();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('should overwrite existing value for same storage property', () => {
|
|
49
|
-
const oldVisitorId = 'old-visitor';
|
|
50
|
-
const newVisitorId = 'new-visitor';
|
|
51
|
-
const options = { ...defaultOptions };
|
|
52
|
-
|
|
53
|
-
setVisitorId(oldVisitorId, options);
|
|
54
|
-
expect(getVisitorId(options)).toBe(oldVisitorId);
|
|
55
|
-
|
|
56
|
-
setVisitorId(newVisitorId, options);
|
|
57
|
-
expect(getVisitorId(options)).toBe(newVisitorId);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('should migrate from old value in case new prefix is set', () => {
|
|
61
|
-
const visitorId = 'test-visitor-123';
|
|
62
|
-
setVisitorId(visitorId, options);
|
|
63
|
-
expect(getVisitorId({
|
|
64
|
-
property_name_factory: (name) => `custom_prefix_${name}`,
|
|
65
|
-
} as OptionsAfterDefaults)).toBe(visitorId);
|
|
66
|
-
expect(localStorage.getItem(`custom_prefix_visitor_id`)).toBe(visitorId);
|
|
67
|
-
})
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('error handling', () => {
|
|
71
|
-
test('should handle localStorage.getItem errors gracefully', () => {
|
|
72
|
-
const options = { ...defaultOptions };
|
|
73
|
-
|
|
74
|
-
// Mock localStorage.getItem to throw an error
|
|
75
|
-
const originalGetItem = localStorage.getItem;
|
|
76
|
-
localStorage.getItem = jest.fn(() => {
|
|
77
|
-
throw new Error('Storage quota exceeded');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
expect(getVisitorId(options)).toBeNull();
|
|
81
|
-
|
|
82
|
-
// Restore original implementation
|
|
83
|
-
localStorage.getItem = originalGetItem;
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('should handle localStorage.setItem errors gracefully', () => {
|
|
87
|
-
const options = { ...defaultOptions };
|
|
88
|
-
|
|
89
|
-
// Mock localStorage.setItem to throw an error
|
|
90
|
-
const originalSetItem = localStorage.setItem;
|
|
91
|
-
localStorage.setItem = jest.fn(() => {
|
|
92
|
-
throw new Error('Storage quota exceeded');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Should not throw error
|
|
96
|
-
expect(() => setVisitorId('test-id', options)).not.toThrow();
|
|
97
|
-
|
|
98
|
-
// Restore original implementation
|
|
99
|
-
localStorage.setItem = originalSetItem;
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|