@neurodevs/node-lsl 8.0.0 → 8.0.2
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/.vscode/settings.json +17 -20
- package/build/.spruce/errors/errors.types.js +0 -2
- package/build/.spruce/errors/errors.types.js.map +1 -1
- package/build/__tests__/behavioral/LslOutlet.test.js +9 -14
- package/build/__tests__/behavioral/LslOutlet.test.js.map +1 -1
- package/build/__tests__/behavioral/TimeMarkerOutlet.test.js.map +1 -1
- package/build/__tests__/implementation/Liblsl.test.d.ts +3 -1
- package/build/__tests__/implementation/Liblsl.test.js +44 -19
- package/build/__tests__/implementation/Liblsl.test.js.map +1 -1
- package/build/__tests__/support/consts.js.map +1 -1
- package/build/__tests__/support/generateRandomOutletOptions.js.map +1 -1
- package/build/assertions.js.map +1 -1
- package/build/consts.js.map +1 -1
- package/build/errors/SpruceError.d.ts +1 -1
- package/build/errors/SpruceError.js.map +1 -1
- package/build/errors/failedToLoadLiblsl.builder.js.map +1 -1
- package/build/implementations/Liblsl.js +40 -17
- package/build/implementations/Liblsl.js.map +1 -1
- package/build/implementations/LslOutlet.js +6 -14
- package/build/implementations/LslOutlet.js.map +1 -1
- package/build/implementations/TimeMarkerOutlet.js +4 -1
- package/build/implementations/TimeMarkerOutlet.js.map +1 -1
- package/build/nodeLsl.types.d.ts +11 -11
- package/build/testDoubles/FakeLiblsl.js.map +1 -1
- package/build/testDoubles/MockTimeMarkerOutlet.js.map +1 -1
- package/build/testDoubles/SpyExtendsTimeMarkerOutlet.js.map +1 -1
- package/build/testDoubles/SpyImplementsTimeMarkerOutlet.js.map +1 -1
- package/build/validations.js.map +1 -1
- package/eslint.config.mjs +3 -0
- package/package.json +26 -26
- package/src/.spruce/errors/errors.types.ts +0 -3
- package/src/__tests__/behavioral/LslOutlet.test.ts +272 -267
- package/src/__tests__/behavioral/TimeMarkerOutlet.test.ts +144 -141
- package/src/__tests__/implementation/Liblsl.test.ts +461 -424
- package/src/__tests__/support/consts.ts +22 -22
- package/src/__tests__/support/generateRandomOutletOptions.ts +13 -13
- package/src/assertions.ts +39 -39
- package/src/consts.ts +16 -16
- package/src/errors/SpruceError.ts +16 -16
- package/src/errors/failedToLoadLiblsl.builder.ts +8 -8
- package/src/implementations/Liblsl.ts +205 -181
- package/src/implementations/LslOutlet.ts +114 -114
- package/src/implementations/TimeMarkerOutlet.ts +50 -50
- package/src/nodeLsl.types.ts +65 -85
- package/src/testDoubles/FakeLiblsl.ts +58 -56
- package/src/testDoubles/MockTimeMarkerOutlet.ts +56 -56
- package/src/testDoubles/SpyExtendsTimeMarkerOutlet.ts +11 -11
- package/src/testDoubles/SpyImplementsTimeMarkerOutlet.ts +28 -28
- package/src/validations.ts +6 -6
- package/tsconfig.json +3 -4
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { randomInt } from 'crypto'
|
|
2
2
|
import AbstractSpruceTest, {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
assert,
|
|
4
|
+
generateId,
|
|
5
|
+
test,
|
|
6
6
|
} from '@sprucelabs/test-utils'
|
|
7
7
|
import LiblslImpl from '../../implementations/Liblsl'
|
|
8
8
|
import TimeMarkerOutletImpl from '../../implementations/TimeMarkerOutlet'
|
|
@@ -12,142 +12,145 @@ import SpyExtendsTimeMarkerOutlet from '../../testDoubles/SpyExtendsTimeMarkerOu
|
|
|
12
12
|
import generateRandomOutletOptions from '../support/generateRandomOutletOptions'
|
|
13
13
|
|
|
14
14
|
export default class TimeMarkerOutletTest extends AbstractSpruceTest {
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
15
|
+
private static fakeLiblsl: FakeLiblsl
|
|
16
|
+
private static outlet: SpyExtendsTimeMarkerOutlet
|
|
17
|
+
|
|
18
|
+
protected static async beforeEach() {
|
|
19
|
+
await super.beforeEach()
|
|
20
|
+
TimeMarkerOutletImpl.Class = SpyExtendsTimeMarkerOutlet
|
|
21
|
+
this.fakeLiblsl = new FakeLiblsl()
|
|
22
|
+
LiblslImpl.setInstance(this.fakeLiblsl)
|
|
23
|
+
this.outlet = this.Outlet()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@test()
|
|
27
|
+
protected static async loadsWithTimeMarkerSpecificOptions() {
|
|
28
|
+
assert.isEqualDeep(this.outlet.spyOptions, {
|
|
29
|
+
name: 'Time markers',
|
|
30
|
+
type: 'Markers',
|
|
31
|
+
channelNames: ['Markers'],
|
|
32
|
+
sampleRate: 0,
|
|
33
|
+
channelFormat: 'string',
|
|
34
|
+
sourceId: 'time-markers',
|
|
35
|
+
manufacturer: 'N/A',
|
|
36
|
+
unit: 'N/A',
|
|
37
|
+
chunkSize: 0,
|
|
38
|
+
maxBuffered: 0,
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@test()
|
|
43
|
+
protected static async canOverrideDefaultOptions() {
|
|
44
|
+
const options = generateRandomOutletOptions()
|
|
45
|
+
const outlet = this.Outlet(options)
|
|
46
|
+
assert.isEqualDeep(outlet.spyOptions, options)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@test()
|
|
50
|
+
protected static async pushingSingleMarkerIncrementsHitCountAndWaitTime() {
|
|
51
|
+
const markers = [this.generateDurationMarkerValues()]
|
|
52
|
+
await this.outlet.pushMarkers(markers)
|
|
53
|
+
|
|
54
|
+
assert.isEqual(this.fakeLiblsl.pushSampleStringTimestampHitCount, 1)
|
|
55
|
+
assert.isEqual(this.outlet.totalWaitTimeMs, markers[0].durationMs)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@test()
|
|
59
|
+
protected static async pushingTwoMarkersIncrementsHitCountAndWaitTimeTwice() {
|
|
60
|
+
const markers = await this.pushTotalMarkers(2)
|
|
61
|
+
|
|
62
|
+
assert.isEqual(this.fakeLiblsl.pushSampleStringTimestampHitCount, 2)
|
|
63
|
+
assert.isEqual(
|
|
64
|
+
this.outlet.totalWaitTimeMs,
|
|
65
|
+
markers[0].durationMs + markers[1].durationMs
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@test('can stop on the first marker', 1)
|
|
70
|
+
@test('can stop on the second marker', 2)
|
|
71
|
+
@test('can stop on the third marker', 3)
|
|
72
|
+
protected static async canStopTimeMarkersMidPush(bailIdx: number) {
|
|
73
|
+
let hitCount = 0
|
|
74
|
+
|
|
75
|
+
this.outlet.pushSample = () => {
|
|
76
|
+
hitCount += 1
|
|
77
|
+
if (hitCount === bailIdx) {
|
|
78
|
+
this.outlet.stop()
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
await this.pushTotalMarkers(10)
|
|
83
|
+
|
|
84
|
+
assert.isEqual(hitCount, bailIdx)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@test()
|
|
88
|
+
protected static async canStartAgainAfterStopping() {
|
|
89
|
+
this.outlet.stop()
|
|
90
|
+
|
|
91
|
+
let hitCount = 0
|
|
92
|
+
|
|
93
|
+
this.outlet.pushSample = () => {
|
|
94
|
+
hitCount++
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
await this.pushTotalMarkers(10)
|
|
98
|
+
|
|
99
|
+
assert.isEqual(hitCount, 10)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@test()
|
|
103
|
+
protected static async doesNotWaitIfStopped() {
|
|
104
|
+
this.setupTimeMarkerImpl()
|
|
105
|
+
|
|
106
|
+
const startMs = Date.now()
|
|
107
|
+
const promise = this.pushTotalMarkers(2, 1000)
|
|
108
|
+
this.outlet.stop()
|
|
109
|
+
await promise
|
|
110
|
+
const endMs = Date.now()
|
|
111
|
+
|
|
112
|
+
assert.isBelow(endMs - startMs, 10)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@test()
|
|
116
|
+
protected static async clearsTheTimeoutOnStop() {
|
|
117
|
+
this.setupTimeMarkerImpl()
|
|
118
|
+
|
|
119
|
+
const promise = this.pushTotalMarkers(2, 100)
|
|
120
|
+
|
|
121
|
+
this.outlet.stop()
|
|
122
|
+
this.outlet.pushSample = () =>
|
|
123
|
+
assert.fail('Should not have been called')
|
|
124
|
+
|
|
125
|
+
await promise
|
|
126
|
+
await this.wait(100)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private static setupTimeMarkerImpl() {
|
|
130
|
+
TimeMarkerOutletImpl.Class = TimeMarkerOutletImpl as any
|
|
131
|
+
this.outlet = this.Outlet()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private static async pushTotalMarkers(total: number, durationMs?: number) {
|
|
135
|
+
const markers = new Array(total)
|
|
136
|
+
.fill(null)
|
|
137
|
+
.map(() => this.generateDurationMarkerValues(durationMs))
|
|
138
|
+
|
|
139
|
+
await this.outlet.pushMarkers(markers)
|
|
140
|
+
|
|
141
|
+
return markers
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private static generateDurationMarkerValues(durationMs?: number) {
|
|
145
|
+
return {
|
|
146
|
+
name: generateId(),
|
|
147
|
+
durationMs: durationMs ?? randomInt(100, 1000),
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private static Outlet(options?: Partial<LslOutletOptions>) {
|
|
152
|
+
return TimeMarkerOutletImpl.Outlet(
|
|
153
|
+
options
|
|
154
|
+
) as SpyExtendsTimeMarkerOutlet
|
|
155
|
+
}
|
|
153
156
|
}
|