Fixed tests

1.0
Christoph Oberhofer 8 years ago
parent 1d470660a7
commit 14684bb58d

@ -14,6 +14,9 @@ module.exports = function(config) {
'test/test-main-integration.js': ['webpack'] 'test/test-main-integration.js': ['webpack']
}, },
webpack: { webpack: {
entry: [
'./src/quagga.js'
],
module: { module: {
loaders: [{ loaders: [{
test: /\.jsx?$/, test: /\.jsx?$/,

@ -13,6 +13,9 @@ module.exports = function(config) {
'test/test-main.js': ['webpack'] 'test/test-main.js': ['webpack']
}, },
webpack: { webpack: {
entry: [
'./src/quagga.js'
],
module: { module: {
loaders: [{ loaders: [{
test: /\.jsx?$/, test: /\.jsx?$/,
@ -23,7 +26,10 @@ module.exports = function(config) {
}, { }, {
test: /\.js$/, test: /\.js$/,
include: path.resolve('src'), include: path.resolve('src'),
loader: 'istanbul-instrumenter-loader' loader: 'istanbul-instrumenter-loader',
query: {
esModules: true
}
}] }]
}, },
resolve: { resolve: {

@ -12,10 +12,9 @@ const windowObjects = [
]; ];
const DOMHelper = windowObjects.reduce((result, obj) => { const DOMHelper = windowObjects.reduce((result, obj) => {
return { return Object.assign({}, result, {
...result,
[obj]: obj in windowRef ? windowRef[obj] : () => {} [obj]: obj in windowRef ? windowRef[obj] : () => {}
}; });
}, {}); }, {});
DOMHelper.setObject = (key, value) => { DOMHelper.setObject = (key, value) => {

@ -324,15 +324,14 @@ EANReader.prototype._decode = function() {
} }
} }
return { return Object.assign({
code: result.join(""), code: result.join(""),
start: startInfo.start, start: startInfo.start,
end: code.end, end: code.end,
codeset: "", codeset: "",
startInfo: startInfo, startInfo: startInfo,
decodedCodes: decodedCodes, decodedCodes: decodedCodes,
...resultInfo }, resultInfo);
};
}; };
EANReader.prototype._decodeExtensions = function(offset) { EANReader.prototype._decodeExtensions = function(offset) {

@ -345,13 +345,9 @@ function createScanner() {
} }
function configForWorker(config) { function configForWorker(config) {
return { return Object.assign({}, config, {
...config, inputStream: Object.assign({}, config.inputStream, {target: null})
inputStream: { });
...config.inputStream,
target: null
}
};
} }
function workerInterface(factory) { function workerInterface(factory) {

@ -50,23 +50,17 @@ describe("CameraAccess", () => {
}); });
describe('success', function() { describe('success', function() {
beforeEach(function() {
sinon.stub(navigator.mediaDevices, "getUserMedia", function(constraints) {
return Promise.resolve(stream);
});
});
afterEach(function() {
navigator.mediaDevices.getUserMedia.restore();
});
describe('request', function () { describe('request', function () {
it('should request the camera', function (done) { it('should request the camera', function (done) {
CameraAccess.request(video, {}) CameraAccess.request(video, {})
.then(function () { .then(function () {
expect(navigator.mediaDevices.getUserMedia.calledOnce).to.equal(true);
expect(video.srcObject).to.deep.equal(stream); expect(video.srcObject).to.deep.equal(stream);
done(); done();
})
.catch((e) => {
console.log(e);
expect(true).to.equal(false);
done();
}); });
}); });
@ -79,16 +73,14 @@ describe("CameraAccess", () => {
maxAspectRatio: 100 maxAspectRatio: 100
}) })
.then(function () { .then(function () {
const call = navigator.mediaDevices.getUserMedia.getCall(0), const transformedConstraints = getConstraints();
args = call.args; expect(transformedConstraints.video.width).to.equal(320);
expect(call).to.be.defined; expect(transformedConstraints.video.height).to.equal(240);
expect(args[0].video.width).to.equal(320); expect(transformedConstraints.video.facingMode).to.equal("user");
expect(args[0].video.height).to.equal(240); expect(transformedConstraints.video.aspectRatio).to.equal(2);
expect(args[0].video.facingMode).to.equal("user"); expect(transformedConstraints.video.facing).not.to.be.defined;
expect(args[0].video.aspectRatio).to.equal(2); expect(transformedConstraints.video.minAspectRatio).not.to.be.defined;
expect(args[0].video.facing).not.to.be.defined; expect(transformedConstraints.video.maxAspectRatio).not.to.be.defined;
expect(args[0].video.minAspectRatio).not.to.be.defined;
expect(args[0].video.maxAspectRatio).not.to.be.defined;
done(); done();
}); });
}); });
@ -126,68 +118,49 @@ describe("CameraAccess", () => {
}); });
}); });
}); });
});
describe("not available", function(){ describe("pickConstraints", () => {
var originalGetUserMedia; it("should return the given constraints if no facingMode is defined", (done) => {
const givenConstraints = {width: 180};
beforeEach(function() { return pickConstraints(givenConstraints).then((actualConstraints) => {
originalGetUserMedia = navigator.mediaDevices.getUserMedia; expect(actualConstraints.video).to.deep.equal(givenConstraints);
navigator.mediaDevices.getUserMedia = undefined; done();
}); })
.catch((err) => {
afterEach(function() { expect(err).to.equal(null);
navigator.mediaDevices.getUserMedia = originalGetUserMedia; console.log(err);
}); done();
it('should throw if getUserMedia not available', function(done) {
CameraAccess.request(video, {})
.catch((err) => {
expect(err).to.be.defined;
done();
});
}); });
}); });
describe("pickConstraints", () => { it("should return the given constraints if deviceId is defined", (done) => {
it("should return the given constraints if no facingMode is defined", (done) => { const givenConstraints = {width: 180, deviceId: "4343"};
const givenConstraints = {width: 180}; return pickConstraints(givenConstraints).then((actualConstraints) => {
return pickConstraints(givenConstraints).then((actualConstraints) => { expect(actualConstraints.video).to.deep.equal(givenConstraints);
expect(actualConstraints.video).to.deep.equal(givenConstraints); done();
done(); })
}) .catch((err) => {
.catch((err) => { expect(err).to.equal(null);
expect(err).to.equal(null); console.log(err);
console.log(err); done();
done();
});
});
it("should return the given constraints if deviceId is defined", (done) => {
const givenConstraints = {width: 180, deviceId: "4343"};
return pickConstraints(givenConstraints).then((actualConstraints) => {
expect(actualConstraints.video).to.deep.equal(givenConstraints);
done();
})
.catch((err) => {
expect(err).to.equal(null);
console.log(err);
done();
});
}); });
});
it("should set deviceId if facingMode is set to environment", (done) => { it("should set deviceId if facingMode & deviceId are set", (done) => {
setDevices([{deviceId: "front", kind: "videoinput", label: "front Facing"}, setDevices([{deviceId: "front", kind: "videoinput", label: "front Facing"},
{deviceId: "back", label: "back Facing", kind: "videoinput"}]); {deviceId: "back", label: "back Facing", kind: "videoinput"}]);
const givenConstraints = {width: 180, facingMode: "environment"}; const givenConstraints = {width: 180, facingMode: "environment", deviceId: "back"};
return pickConstraints(givenConstraints).then((actualConstraints) => { return pickConstraints(givenConstraints)
expect(actualConstraints.video).to.deep.equal({width: 180, deviceId: "back"}); .then((actualConstraints) => {
done(); console.log(JSON.stringify(actualConstraints, 0, 4));
}) expect(actualConstraints.video).to.deep.equal({width: 180, deviceId: "back"});
.catch((err) => { done();
console.log(err); })
expect(err).to.equal(null); .catch((err) => {
done(); console.log(err);
}); expect(err).to.equal(null);
done();
}); });
}); });
}); });

Loading…
Cancel
Save