-
-
Notifications
You must be signed in to change notification settings - Fork 750
Expand file tree
/
Copy pathworkerStorage_test.js
More file actions
35 lines (31 loc) · 1.04 KB
/
workerStorage_test.js
File metadata and controls
35 lines (31 loc) · 1.04 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
const { expect } = require('expect');
const WorkerStorage = require('../../lib/workerStorage');
const { Worker } = require('worker_threads');
const event = require('../../lib/event');
describe('WorkerStorage', () => {
it('should handle share message correctly without circular dependency', (done) => {
// Create a mock worker to test the functionality
const mockWorker = {
threadId: 'test-thread-1',
on: (eventName, callback) => {
if (eventName === 'message') {
// Simulate receiving a share message
setTimeout(() => {
callback({ event: 'share', data: { testKey: 'testValue' } });
done();
}, 10);
}
},
postMessage: () => {}
};
// Add the mock worker to storage
WorkerStorage.addWorker(mockWorker);
});
it('should not crash when sharing data', () => {
const testData = { user: 'test', password: '123' };
// This should not throw an error
expect(() => {
WorkerStorage.share(testData);
}).not.toThrow();
});
});