@ -4,6 +4,7 @@ const IMAGE_PATH = 'http://localhost:3000/tests/assets/images';
@@ -4,6 +4,7 @@ const IMAGE_PATH = 'http://localhost:3000/tests/assets/images';
const SIMPLE _TEXT = 'Tesseract.js\n' ;
const COMSIC _TEXT = 'HellO World\nfrom beyond\nthe Cosmic Void\n' ;
const TESTOCR _TEXT = 'This is a lot of 12 point text to test the\nocr code and see if it works on all types\nof file format.\n\nThe quick brown dog jumped over the\nlazy fox. The quick brown dog jumped\nover the lazy fox. The quick brown dog\njumped over the lazy fox. The quick\nbrown dog jumped over the lazy fox.\n' ;
const CHINESE _TEXT = '繁 體 中 文 測 試\n' ;
const loadLangOptions = {
langPath : 'http://localhost:3000/tests/assets/traineddata' ,
@ -19,19 +20,22 @@ const getWorker = options => (
@@ -19,19 +20,22 @@ const getWorker = options => (
) ;
before ( function cb ( done ) {
this . timeout ( 10000 ) ;
this . timeout ( 30000 ) ;
const load = ( ) => (
loadLang ( {
langs : 'eng' ,
langs : 'eng+chi_tra ' ,
cacheMethod : 'write' ,
langURI : loadLangOptions . langPath ,
... loadLangOptions ,
} ) . then ( ( ) => {
done ( ) ;
} )
) ;
if ( typeof startServer !== 'undefined' ) {
startServer ( done ) ;
startServer ( load ) ;
} else {
done ( ) ;
load ( ) ;
}
} ) ;
} ) ;
after ( ( done ) => {
@ -43,14 +47,31 @@ after((done) => {
@@ -43,14 +47,31 @@ after((done) => {
} ) ;
describe ( 'recognize()' , ( ) => {
describe ( 'supports multiple formats' , ( ) => {
describe ( 'should recognize different langs' , ( ) => {
[
{ name : 'chinese.png' , lang : 'chi_tra' , ans : CHINESE _TEXT } ,
] . forEach ( ( { name , lang , ans } ) => (
it ( ` recongize ${ lang } ` , ( done ) => {
const worker = getWorker ( ) ;
worker
. recognize ( ` ${ IMAGE _PATH } / ${ name } ` , lang )
. then ( ( { text } ) => {
expect ( text ) . to . be ( ans ) ;
worker . terminate ( ) ;
done ( ) ;
} ) ;
} ) . timeout ( 30000 )
) ) ;
} ) ;
describe ( 'should read bmp, jpg, png and pbm format images' , ( ) => {
[ 'bmp' , 'jpg' , 'png' , 'pbm' ] . forEach ( format => (
it ( ` support ${ format } format ` , ( done ) => {
const worker = getWorker ( ) ;
worker
. recognize ( ` ${ IMAGE _PATH } /simple. ${ format } ` )
. then ( ( result ) => {
expect ( result . text ) . to . be ( SIMPLE _TEXT ) ;
. then ( ( { text } ) => {
expect ( text ) . to . be ( SIMPLE _TEXT ) ;
worker . terminate ( ) ;
done ( ) ;
} ) ;
@ -58,7 +79,7 @@ describe('recognize()', () => {
@@ -58,7 +79,7 @@ describe('recognize()', () => {
) ) ;
} ) ;
describe ( '1 worker multiple recognition ' , ( ) => {
describe ( 'should be able to recognize multiple images with 1 worker ' , ( ) => {
[ 3 , 10 , 20 ] . forEach ( num => (
it ( ` recognize ${ num } images with 1 worker ` , ( done ) => {
const worker = getWorker ( ) ;
@ -75,7 +96,7 @@ describe('recognize()', () => {
@@ -75,7 +96,7 @@ describe('recognize()', () => {
) ) ;
} ) ;
describe ( 'should recognize in order' , ( ) => {
describe ( 'should recognize multiple images in order' , ( ) => {
[ 1 , 2 ] . forEach ( ( num ) => {
it ( ` recognize ${ num * 2 } images with 1 worker in order ` , ( done ) => {
const worker = getWorker ( ) ;