Skip to content

Commit 68c1c96

Browse files
authored
Reworked tests to run on Chrome and Firefox, and fix #1014 and #1010 (#1015)
1 parent 8322fee commit 68c1c96

19 files changed

+7701
-7027
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ worker.min.js
88
.nyc_output
99
dist/
1010
*.swp
11+
*.wasm
12+
*.wasm.js

karma.conf.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
module.exports = function (config) {
4+
config.set({
5+
frameworks: ['mocha'],
6+
files: [
7+
{ pattern: 'dist/tesseract.min.js', included: true },
8+
{ pattern: 'dist/worker.min.js', included: false, served: true },
9+
{ pattern: 'node_modules/tesseract.js-core/tesseract-core-simd-lstm.wasm.js', included: false, served: true },
10+
{ pattern: 'node_modules/tesseract.js-core/tesseract-core-simd.wasm.js', included: false, served: true },
11+
{ pattern: 'tests/constants.mjs', included: false, served: true },
12+
{ pattern: 'node_modules/expect.js/index.js', included: true },
13+
{ pattern: 'tests/*.test.mjs', type: 'module' },
14+
{ pattern: 'tests/assets/images/**', included: false, served: true },
15+
],
16+
reporters: ['progress'],
17+
port: 9876,
18+
colors: true,
19+
logLevel: config.LOG_INFO,
20+
autoWatch: false,
21+
browsers: ['ChromeHeadless', 'FirefoxHeadless'],
22+
singleRun: true,
23+
concurrency: 1,
24+
proxies: {
25+
'/dist/worker.min.js': '/base/dist/worker.min.js',
26+
'/node_modules/tesseract.js-core/tesseract-core-simd-lstm.wasm.js': '/base/node_modules/tesseract.js-core/tesseract-core-simd-lstm.wasm.js',
27+
'/node_modules/tesseract.js-core/tesseract-core-simd.wasm.js': '/base/node_modules/tesseract.js-core/tesseract-core-simd.wasm.js',
28+
'/tests/assets/images': '/base/tests/assets/images',
29+
},
30+
});
31+
};

package-lock.json

Lines changed: 7555 additions & 6795 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@
1515
"prepublishOnly": "npm run build",
1616
"wait": "rimraf dist && wait-on http://localhost:3000/dist/tesseract.min.js",
1717
"test": "npm-run-all -p -r start test:all",
18-
"test:all": "npm-run-all wait test:browser:* test:node:all",
19-
"test:node": "nyc mocha --exit --bail --require ./scripts/test-helper.js",
20-
"test:node:all": "npm run test:node -- ./tests/*.test.js",
21-
"test:browser-tpl": "mocha-headless-chrome -a incognito -a no-sandbox -a disable-setuid-sandbox -a disable-logging -t 300000",
22-
"test:browser:detect": "npm run test:browser-tpl -- -f ./tests/detect.test.html",
23-
"test:browser:recognize": "npm run test:browser-tpl -- -f ./tests/recognize.test.html",
24-
"test:browser:scheduler": "npm run test:browser-tpl -- -f ./tests/scheduler.test.html",
25-
"test:browser:FS": "npm run test:browser-tpl -- -f ./tests/FS.test.html",
18+
"test:all": "npm-run-all wait test:browser test:node:all",
19+
"test:browser": "karma start karma.conf.js",
20+
"test:node": "nyc mocha --exit --bail --require ./scripts/test-helper.mjs",
21+
"test:node:all": "npm run test:node -- ./tests/*.test.mjs",
2622
"lint": "eslint src",
2723
"lint:fix": "eslint --fix src",
2824
"postinstall": "opencollective-postinstall || true"
@@ -50,8 +46,12 @@
5046
"expect.js": "^0.3.1",
5147
"express": "^4.18.2",
5248
"mocha": "^10.2.0",
53-
"mocha-headless-chrome": "^4.0.0",
5449
"npm-run-all": "^4.1.5",
50+
"karma": "^6.4.2",
51+
"karma-chrome-launcher": "^3.2.0",
52+
"karma-firefox-launcher": "^2.1.2",
53+
"karma-mocha": "^2.0.1",
54+
"karma-webpack": "^5.0.0",
5555
"nyc": "^15.1.0",
5656
"rimraf": "^5.0.0",
5757
"rollup": "^3.20.7",

scripts/test-helper.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

scripts/test-helper.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import expect from 'expect.js';
2+
import fs from 'fs';
3+
// eslint-disable-next-line import/extensions
4+
import Tesseract from '../src/index.js';
5+
6+
global.Tesseract = Tesseract;
7+
global.expect = expect;
8+
global.fs = fs;

tests/.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"rules": {
33
"no-undef": 0,
4-
"camelcase": 0
4+
"camelcase": 0,
5+
"import/extensions": 0,
56
}
67
}

tests/FS.test.html

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/FS.test.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

tests/FS.test.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { SIMPLE_TEXT, TIMEOUT, OPTIONS } from './constants.mjs';
2+
3+
describe('FS', () => {
4+
let worker;
5+
before(async function cb() {
6+
this.timeout(0);
7+
worker = await Tesseract.createWorker('eng', 1, OPTIONS);
8+
});
9+
10+
it('should write and read text from FS (using FS only)', async () => {
11+
const path = 'tmp.txt';
12+
await worker.FS('writeFile', [path, SIMPLE_TEXT]);
13+
const { data } = await worker.FS('readFile', [path, { encoding: 'utf8' }]);
14+
await worker.FS('unlink', [path]);
15+
expect(data.toString()).to.be(SIMPLE_TEXT);
16+
}).timeout(TIMEOUT);
17+
18+
it('should write and read text from FS (using writeFile, readFile)', async () => {
19+
const path = 'tmp2.txt';
20+
await worker.writeText(path, SIMPLE_TEXT);
21+
const { data } = await worker.readText(path);
22+
await worker.removeFile(path);
23+
expect(data.toString()).to.be(SIMPLE_TEXT);
24+
}).timeout(TIMEOUT);
25+
});

tests/constants.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)