feat: init project

This commit is contained in:
yugasun
2018-11-20 21:35:47 +08:00
parent 28cf46138a
commit 82f77ad9e7
31 changed files with 7340 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
make test for your own private key
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 935 B

+37
View File
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<title>Mocha</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="../../node_modules/es5-shim/es5-shim.js"></script>
<script src="../../node_modules/es5-shim/es5-sham.js"></script>
<script src="../../node_modules/mocha/mocha.js"></script>
<script src="../../node_modules/expect.js/index.js"></script>
<script>
mocha.setup('bdd');
</script>
<script src="../../dist/index.aio.js"></script>
<script>
var libs = {
'expect.js': expect,
'../dist/index.js': window['qrcode-decoder']
};
var require = function(path) {
return libs[path];
}
</script>
<script src="../test.js"></script>
<script>
mocha.run();
</script>
</body>
</html>
+57
View File
@@ -0,0 +1,57 @@
const expect = require('expect.js');
const QrcodeDecoder = require('../dist/index.js');
describe('QrcodeDecoder', function () {
// global.mocha.checkLeaks = false;
this.timeout(180000);
it('be defined', function () {
expect(QrcodeDecoder).to.be.ok();
});
var qr;
beforeEach(function () {
qr = new QrcodeDecoder();
});
describe('decodeFromImage', function () {
it('decode image from img element', function (done) {
const img = document.createElement('img');
img.src = 'test/assets/qrcode.png';
img.onload = async function () {
const result = await qr.decodeFromImage(img);
expect(result.data).to.equal('192.168.1.13:3000');
done();
}
});
it('decode image from img url', async function () {
const result = await qr.decodeFromImage('test/assets/qrcode.png');
expect(result.data).to.equal('192.168.1.13:3000');
});
it('throw if no src in image element', async function (done) {
var img = document.createElement('img');
try {
await qr.decodeFromImage(img);
} catch(e) {
expect(e.message).to.equal('The ImageElement must contain a src')
done();
}
});
});
describe('decodeFromCamera', function () {
it('decode from a video with qrcode', async function () {
const video = document.createElement('video');
video.setAttribute('autoplay', true);
video.setAttribute('src', 'test/assets/qrcode-video.mp4');
const result = await qr.decodeFromVideo(video);
expect(result.data).to.equal('192.168.1.13:3000');
});
});
});