Browse Source

Add detect() unit test

pull/265/head
Jerome Wu 6 years ago
parent
commit
9aafe4aa24
  1. 3
      tests/.eslintrc
  2. 3
      tests/assets/traineddata/osd.traineddata
  3. 3
      tests/assets/traineddata/osd.traineddata.gz
  4. 17
      tests/browser/detect.test.html
  5. 57
      tests/detect.test.js

3
tests/.eslintrc

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
{
"rules": {
"no-undef": 0
"no-undef": 0,
"camelcase": 0
}
}

3
tests/assets/traineddata/osd.traineddata

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e19f2ae860792fdf372cf48d8ce70ae5da3c4052962fe22e9de1f680c374bb0e
size 10562874

3
tests/assets/traineddata/osd.traineddata.gz

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:da43a9828b253a7b272c38635c20dbf6274ff7e2115488bcb54bc32acb8a9977
size 4320198

17
tests/browser/detect.test.html

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css">
</head>
<body>
<div id="mocha"></div>
<script src="../../node_modules/mocha/mocha.js"></script>
<script src="../../node_modules/expect.js/index.js"></script>
<script src="/dist/tesseract.dev.js"></script>
<script>mocha.setup('bdd');</script>
<script src="../detect.test.js"></script>
<script>
mocha.run();
</script>
</body>
</html>

57
tests/detect.test.js

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
const { TesseractWorker, utils: { loadLang } } = Tesseract;
const IMAGE_PATH = 'http://localhost:3000/tests/assets/images';
const loadLangOptions = {
langPath: 'http://localhost:3000/tests/assets/traineddata',
cachePath: './tests/assets/traineddata',
};
const getWorker = options => (
new TesseractWorker({
cacheMethod: 'readOnly',
...loadLangOptions,
...options,
})
);
before(function cb(done) {
this.timeout(30000);
const load = () => (
loadLang({
lang: 'osd',
cacheMethod: 'write',
...loadLangOptions,
}).then(() => {
done();
})
);
if (typeof startServer !== 'undefined') {
startServer(load);
} else {
load();
}
});
after((done) => {
if (typeof stopServer !== 'undefined') {
stopServer(done);
} else {
done();
}
});
describe('detect()', () => {
it('should detect OSD', (done) => {
[
{ name: 'cosmic.png', ans: { id: 12, degree: 0 } },
].forEach(({ name, ans: { id, degree } }) => {
const worker = getWorker();
worker
.detect(`${IMAGE_PATH}/${name}`)
.then(({ tesseract_script_id, orientation_degrees }) => {
expect(tesseract_script_id).to.be(id);
expect(orientation_degrees).to.be(degree);
done();
});
});
}).timeout(10000);
});
Loading…
Cancel
Save