diff --git a/tests/.eslintrc b/tests/.eslintrc index d117642..e56b933 100644 --- a/tests/.eslintrc +++ b/tests/.eslintrc @@ -1,5 +1,6 @@ { "rules": { - "no-undef": 0 + "no-undef": 0, + "camelcase": 0 } } diff --git a/tests/assets/traineddata/osd.traineddata b/tests/assets/traineddata/osd.traineddata new file mode 100644 index 0000000..d9a9568 --- /dev/null +++ b/tests/assets/traineddata/osd.traineddata @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e19f2ae860792fdf372cf48d8ce70ae5da3c4052962fe22e9de1f680c374bb0e +size 10562874 diff --git a/tests/assets/traineddata/osd.traineddata.gz b/tests/assets/traineddata/osd.traineddata.gz new file mode 100644 index 0000000..b8523d5 --- /dev/null +++ b/tests/assets/traineddata/osd.traineddata.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da43a9828b253a7b272c38635c20dbf6274ff7e2115488bcb54bc32acb8a9977 +size 4320198 diff --git a/tests/browser/detect.test.html b/tests/browser/detect.test.html new file mode 100644 index 0000000..a26af37 --- /dev/null +++ b/tests/browser/detect.test.html @@ -0,0 +1,17 @@ + +
+ + + + + + + + + + + + + diff --git a/tests/detect.test.js b/tests/detect.test.js new file mode 100644 index 0000000..9d2f0d1 --- /dev/null +++ b/tests/detect.test.js @@ -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); +});