Skip to content

Commit

Permalink
Ran linter on automated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Balearica committed Dec 24, 2024
1 parent 241cddb commit 6cf46c1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion tests/FS.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const FS_WAIT = 500;
let worker;
before(async function cb() {
this.timeout(0);
worker = await createWorker("eng", 1, OPTIONS);
worker = await createWorker('eng', 1, OPTIONS);
});

describe('FS', async () => {
Expand Down
3 changes: 1 addition & 2 deletions tests/detect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { createWorker } = Tesseract;
let worker;
before(async function cb() {
this.timeout(0);
worker = await createWorker("osd", 0, OPTIONS);
worker = await createWorker('osd', 0, OPTIONS);
});

describe('detect()', async () => {
Expand All @@ -16,7 +16,6 @@ describe('detect()', async () => {
}).timeout(TIMEOUT);
});


describe('detect()', async () => {
it('should detect OSD (simplified interface)', () => {
[
Expand Down
27 changes: 13 additions & 14 deletions tests/recognize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ const { createWorker, PSM } = Tesseract;
let worker;
before(async function cb() {
this.timeout(0);
worker = await createWorker("eng", 1, OPTIONS);
workerLegacy = await createWorker("eng", 0, OPTIONS);
worker = await createWorker('eng', 1, OPTIONS);
workerLegacy = await createWorker('eng', 0, OPTIONS);
});

describe('recognize()', () => {
describe('should read bmp, jpg, png and pbm format images', () => {
FORMATS.forEach(format => (
FORMATS.forEach((format) => (
it(`support ${format} format`, async () => {
await worker.reinitialize('eng');
const { data: { text } } = await worker.recognize(`${IMAGE_PATH}/simple.${format}`);
Expand Down Expand Up @@ -69,7 +69,6 @@ describe('recognize()', () => {
));
});


describe('should recognize different langs', () => {
[
{ name: 'chinese.png', lang: 'chi_tra', ans: CHINESE_TEXT },
Expand Down Expand Up @@ -142,7 +141,7 @@ describe('recognize()', () => {
describe('should support all page seg modes (Legacy)', () => {
Object
.keys(PSM)
.map(name => ({ name, mode: PSM[name] }))
.map((name) => ({ name, mode: PSM[name] }))
.forEach(({ name, mode }) => (
it(`support PSM.${name} mode`, async () => {
await workerLegacy.reinitialize(['eng', 'osd']);
Expand All @@ -159,7 +158,7 @@ describe('recognize()', () => {
Object
.keys(PSM)
.filter((x) => x !== 'OSD_ONLY')
.map(name => ({ name, mode: PSM[name] }))
.map((name) => ({ name, mode: PSM[name] }))
.forEach(({ name, mode }) => (
it(`support PSM.${name} mode`, async () => {
await worker.reinitialize(['eng', 'osd']);
Expand All @@ -173,7 +172,7 @@ describe('recognize()', () => {
});

(IS_BROWSER ? describe.skip : describe)('should recognize image in Buffer format (Node.js only)', () => {
FORMATS.forEach(format => (
FORMATS.forEach((format) => (
it(`support ${format} format`, async () => {
const buf = fs.readFileSync(path.join(__dirname, 'assets', 'images', `simple.${format}`));
await worker.reinitialize('eng');
Expand All @@ -184,7 +183,7 @@ describe('recognize()', () => {
});

(IS_BROWSER ? describe : describe.skip)('should read image from img DOM element (browser only)', () => {
FORMATS.forEach(format => (
FORMATS.forEach((format) => (
it(`support ${format} format`, async () => {
const imageDOM = document.createElement('img');
imageDOM.setAttribute('src', `${IMAGE_PATH}/simple.${format}`);
Expand All @@ -196,7 +195,7 @@ describe('recognize()', () => {
});

(IS_BROWSER ? describe : describe.skip)('should read image from video DOM element (browser only)', () => {
FORMATS.forEach(format => (
FORMATS.forEach((format) => (
it(`support ${format} format`, async () => {
const videoDOM = document.createElement('video');
videoDOM.setAttribute('poster', `${IMAGE_PATH}/simple.${format}`);
Expand All @@ -209,7 +208,7 @@ describe('recognize()', () => {

(IS_BROWSER ? describe : describe.skip)('should read video from canvas DOM element (browser only)', () => {
// img tag is unable to render pbm, so let's skip it.
const formats = FORMATS.filter(f => f !== 'pbm');
const formats = FORMATS.filter((f) => f !== 'pbm');
let canvasDOM = null;
let imageDOM = null;
let idx = 0;
Expand All @@ -230,7 +229,7 @@ describe('recognize()', () => {
imageDOM.remove();
});

formats.forEach(format => (
formats.forEach((format) => (
it(`support ${format} format`, async () => {
await worker.reinitialize('eng');
const { data: { text } } = await worker.recognize(canvasDOM);
Expand All @@ -241,15 +240,15 @@ describe('recognize()', () => {

(IS_BROWSER ? describe : describe.skip)('should read video from OffscreenCanvas (browser only)', () => {
// img tag is unable to render pbm, so let's skip it.
const formats = FORMATS.filter(f => f !== 'pbm');
const formats = FORMATS.filter((f) => f !== 'pbm');
let offscreenCanvas = null;
let imageDOM = null;
let idx = 0;
beforeEach((done) => {
imageDOM = document.createElement('img');
imageDOM.setAttribute('crossOrigin', 'Anonymous');
imageDOM.onload = () => {
offscreenCanvas = new OffscreenCanvas(imageDOM.width, imageDOM.height)
offscreenCanvas = new OffscreenCanvas(imageDOM.width, imageDOM.height);
offscreenCanvas.getContext('2d').drawImage(imageDOM, 0, 0);
done();
};
Expand All @@ -262,7 +261,7 @@ describe('recognize()', () => {
imageDOM.remove();
});

formats.forEach(format => (
formats.forEach((format) => (
it(`support ${format} format`, async () => {
await worker.reinitialize('eng');
const { data: { text } } = await worker.recognize(offscreenCanvas);
Expand Down
6 changes: 2 additions & 4 deletions tests/scheduler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ before(async function cb() {
this.timeout(0);
const NUM_WORKERS = 5;
console.log(`Initializing ${NUM_WORKERS} workers`);
workers = await Promise.all(Array(NUM_WORKERS).fill(0).map(async () => {
return await createWorker("eng", 1, OPTIONS);
}));
workers = await Promise.all(Array(NUM_WORKERS).fill(0).map(async () => (createWorker('eng', 1, OPTIONS))));
console.log(`Initialized ${NUM_WORKERS} workers`);
});

describe('scheduler', () => {
describe('should speed up with more workers (running 10 jobs)', () => {
[1, 3, 5].forEach(num => (
[1, 3, 5].forEach((num) => (
it(`support using ${num} workers`, async () => {
const NUM_JOBS = 10;
const scheduler = createScheduler();
Expand Down

0 comments on commit 6cf46c1

Please sign in to comment.