mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Fixed tests
This commit is contained in:
@@ -46,7 +46,7 @@
|
||||
"no-extra-boolean-cast": 1,
|
||||
"no-multi-spaces": 2,
|
||||
"no-underscore-dangle": 0,
|
||||
"comma-dangle": 2,
|
||||
"comma-dangle": 0,
|
||||
"camelcase": 0,
|
||||
"curly": 2,
|
||||
"eqeqeq": 2,
|
||||
|
||||
+1
-1
@@ -10,7 +10,6 @@ import {createConfigFromSource} from './input/config_factory';
|
||||
|
||||
function fromSource(config, source, inputConfig = {}) {
|
||||
config = createConfigFromSource(config, inputConfig, source);
|
||||
console.log(config);
|
||||
const scanner = createScanner();
|
||||
return {
|
||||
addEventListener(eventType, cb) {
|
||||
@@ -36,6 +35,7 @@ function fromSource(config, source, inputConfig = {}) {
|
||||
return this;
|
||||
},
|
||||
toPromise() {
|
||||
// how to cancel?? timeout!
|
||||
return new Promise((resolve, reject) => {
|
||||
scanner.decodeSingle(config, (result) => {
|
||||
if (result && result.codeResult && result.codeResult.code) {
|
||||
|
||||
@@ -47,7 +47,7 @@ describe('decodeSingle', function () {
|
||||
config.readers = readers;
|
||||
Quagga
|
||||
.config(config)
|
||||
.fromImage(config.src)
|
||||
.fromSource(config.src)
|
||||
.addEventListener('processed', function(result){
|
||||
console.log(sample.name);
|
||||
expect(result.codeResult.code).to.equal(sample.result);
|
||||
|
||||
@@ -5,7 +5,8 @@ var originalURL,
|
||||
video,
|
||||
stream;
|
||||
|
||||
beforeEach(function() {
|
||||
describe("CameraAccess", () => {
|
||||
beforeEach(function() {
|
||||
var tracks = [{
|
||||
stop: function() {}
|
||||
}];
|
||||
@@ -14,7 +15,7 @@ beforeEach(function() {
|
||||
originalMediaStreamTrack = window.MediaStreamTrack;
|
||||
window.MediaStreamTrack = {};
|
||||
window.URL = {
|
||||
createObjectURL(stream) {
|
||||
createObjectURL() {
|
||||
return stream;
|
||||
}
|
||||
};
|
||||
@@ -39,14 +40,14 @@ beforeEach(function() {
|
||||
cb();
|
||||
});
|
||||
sinon.stub(video, "play");
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function() {
|
||||
window.URL = originalURL;
|
||||
window.MediaStreamTrack = originalMediaStreamTrack;
|
||||
});
|
||||
});
|
||||
|
||||
describe('success', function() {
|
||||
describe('success', function() {
|
||||
beforeEach(function() {
|
||||
sinon.stub(navigator.mediaDevices, "getUserMedia", function(constraints) {
|
||||
return Promise.resolve(stream);
|
||||
@@ -63,7 +64,7 @@ describe('success', function() {
|
||||
expect(navigator.mediaDevices.getUserMedia.calledOnce).to.equal(true);
|
||||
expect(video.srcObject).to.deep.equal(stream);
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it("should allow deprecated constraints to be used", (done) => {
|
||||
@@ -86,7 +87,7 @@ describe('success', function() {
|
||||
expect(args[0].video.minAspectRatio).not.to.be.defined;
|
||||
expect(args[0].video.maxAspectRatio).not.to.be.defined;
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -103,7 +104,7 @@ describe('success', function() {
|
||||
|
||||
afterEach(() => {
|
||||
window.MediaStreamTrack = {};
|
||||
})
|
||||
});
|
||||
|
||||
it("should set deviceId in case facingMode is not supported", (done) => {
|
||||
CameraAccess.request(video, {
|
||||
@@ -116,7 +117,7 @@ describe('success', function() {
|
||||
expect(args[0].video.facingMode).not.to.be.defined;
|
||||
expect(args[0].video.deviceId).to.equal("user");
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -132,9 +133,9 @@ describe('success', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('failure', function() {
|
||||
describe('failure', function() {
|
||||
describe("permission denied", function(){
|
||||
beforeEach(function() {
|
||||
sinon.stub(navigator.mediaDevices, "getUserMedia", function(constraints, success, failure) {
|
||||
@@ -175,4 +176,5 @@ describe('failure', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,14 +9,6 @@ MyFileList.prototype.constructor = MyFileList;
|
||||
|
||||
const OriginalFileList = window.FileList;
|
||||
|
||||
beforeEach(function() {
|
||||
window.FileList = MyFileList;
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
window.FileList = OriginalFileList;
|
||||
});
|
||||
|
||||
function expectImageConfig(config) {
|
||||
expect(config.inputStream.type).to.equal("ImageStream");
|
||||
expect(config.inputStream.sequence).to.equal(false);
|
||||
@@ -37,6 +29,14 @@ function expectLiveConfig(config) {
|
||||
}
|
||||
|
||||
describe("createConfigFromSource", () => {
|
||||
beforeEach(function() {
|
||||
window.FileList = MyFileList;
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
window.FileList = OriginalFileList;
|
||||
});
|
||||
|
||||
it("should create an image config for an image-file", () => {
|
||||
const file = new File([], "image.jpg", {type: 'image/jpg'});
|
||||
const config = createConfigFromSource({}, {}, file);
|
||||
|
||||
@@ -5,7 +5,8 @@ var canvasMock,
|
||||
imageSize,
|
||||
config;
|
||||
|
||||
beforeEach(function() {
|
||||
describe("ResultCollector", () => {
|
||||
beforeEach(function() {
|
||||
imageSize = {x: 320, y: 240};
|
||||
config = {
|
||||
capture: true,
|
||||
@@ -28,22 +29,22 @@ beforeEach(function() {
|
||||
return canvasMock;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function() {
|
||||
document.createElement.restore();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('create', function () {
|
||||
describe('create', function () {
|
||||
it("should return a new collector", function() {
|
||||
ResultCollector.create(config);
|
||||
expect(document.createElement.calledOnce).to.be.equal(true);
|
||||
expect(document.createElement.getCall(0).args[0]).to.equal("canvas");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('addResult', function() {
|
||||
describe('addResult', function() {
|
||||
beforeEach(function() {
|
||||
sinon.stub(ImageDebug, "drawImage", function() {});
|
||||
});
|
||||
@@ -100,4 +101,5 @@ describe('addResult', function() {
|
||||
collector.addResult([], imageSize, {code: "3574660239843", format: "ean_13"});
|
||||
expect(collector.getResults()).to.have.length(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user