Skip to content

Commit 6978967

Browse files
committed
Fixing some test logic
1 parent da2b05b commit 6978967

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

components/pryv-monitor/test/load-helpers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
*/
55
/* global expect, pryv, testData */
66

7+
const { createId: cuid } = require('@paralleldrive/cuid2');
78
require('../src')(pryv);
8-
const testStreamId = global.testStreamId = 'monitor-test';
9+
const testStreamId = global.testStreamId = 'mon-' + cuid().slice(0, 8);
910

1011
global.prepareAndCreateBaseStreams = async () => {
1112
await testData.prepare();

components/pryv-monitor/test/monitor.test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,15 @@ describe('[MONX] Monitor', function () {
4040
describe('[MNTX] notifications', () => {
4141
let monitor = null;
4242
beforeEach(async () => {
43-
monitor = new pryv.Monitor(conn, { limit: 1 });
43+
monitor = new pryv.Monitor(conn, { limit: 1, streams: [global.testStreamId] });
4444
});
4545

4646
afterEach(async () => {
4747
monitor.stop();
4848
});
4949

5050
it('[MNTA] Load events at start', async function () {
51-
let count = 0;
52-
monitor.on('event', function (event) {
53-
count++;
54-
});
55-
await monitor.start();
51+
// Create event before starting the monitor so it's picked up on initial load
5652
await conn.api([
5753
{
5854
method: 'events.create',
@@ -63,7 +59,12 @@ describe('[MONX] Monitor', function () {
6359
}
6460
}
6561
]);
66-
await new Promise(resolve => setTimeout(resolve, 8000));
62+
let count = 0;
63+
monitor.on('event', function (event) {
64+
count++;
65+
});
66+
await monitor.start();
67+
await new Promise(resolve => setTimeout(resolve, 2000));
6768
expect(count).to.be.gt(0);
6869
});
6970

components/pryv-monitor/test/socket.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('[MSKX] Monitor + Socket.IO', function () {
1717
describe('[MSUX] socket updates', function () {
1818
this.timeout(25000);
1919
it('[MSUA] Detect new events added', async function () {
20-
const monitor = new pryv.Monitor(apiEndpoint, { limit: 1 })
20+
const monitor = new pryv.Monitor(apiEndpoint, { limit: 1, streams: [global.testStreamId] })
2121
.addUpdateMethod(new pryv.Monitor.UpdateMethod.Socket());
2222
await monitor.start();
2323

@@ -50,7 +50,7 @@ describe('[MSKX] Monitor + Socket.IO', function () {
5050
describe('[MSTX] stop', () => {
5151
it('[MSTA] Monitor stops when requested', async function () {
5252
this.timeout(20000);
53-
const monitor = new pryv.Monitor(apiEndpoint, { limit: 1 })
53+
const monitor = new pryv.Monitor(apiEndpoint, { limit: 1, streams: [global.testStreamId] })
5454
.addUpdateMethod(new pryv.Monitor.UpdateMethod.Socket());
5555
await monitor.start();
5656
let count = 0;

components/pryv-monitor/test/timer.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('[TIMX] Monitor + EventsTimer', function () {
2828

2929
describe('[TUPX] timer updates', () => {
3030
it('[TUPA] Detect new events added', async function () {
31-
const monitor = new pryv.Monitor(apiEndpoint, { limit: 1 })
31+
const monitor = new pryv.Monitor(apiEndpoint, { limit: 1, streams: [global.testStreamId] })
3232
.addUpdateMethod(new pryv.Monitor.UpdateMethod.EventsTimer(1));
3333
await monitor.start();
3434
let count = 0;
@@ -61,7 +61,7 @@ describe('[TIMX] Monitor + EventsTimer', function () {
6161
describe('[TSTX] stop', () => {
6262
it('[TSTA] Monitor stops when requested', async function () {
6363
this.timeout(20000);
64-
const monitor = await new pryv.Monitor(apiEndpoint, { limit: 1 })
64+
const monitor = await new pryv.Monitor(apiEndpoint, { limit: 1, streams: [global.testStreamId] })
6565
.addUpdateMethod(new pryv.Monitor.UpdateMethod.EventsTimer(1));
6666
await monitor.start();
6767

0 commit comments

Comments
 (0)