-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebcam.spec.js
41 lines (35 loc) · 932 Bytes
/
webcam.spec.js
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
const fs = require('fs');
const { describe, it } = require('mocha');
const { assert } = require('chai');
const { defaultOpts, createWebcam, captureImage } = require('./webcam');
const workingWebcam = createWebcam(defaultOpts);
const brokenWebcam = createWebcam({ device: 'broken' });
const removeWebcamCapture = path => {
try {
fs.unlinkSync(path);
} catch (err) {
console.error(err);
}
};
const webcamCaptureExists = path => {
try {
return fs.existsSync(path);
} catch (err) {
console.error(err);
return false;
}
};
describe('Webcam', () => {
it('Captured', () => {
captureImage(workingWebcam, 'test', (err, path) => {
assert.typeOf(err, 'null');
assert.ok(webcamCaptureExists(path));
removeWebcamCapture(path);
});
});
it('Not Captured', () => {
captureImage(brokenWebcam, 'test', err => {
assert.equal(err instanceof Error, true);
});
});
});