diff --git a/package.json b/package.json index a689d54..28a90d0 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "test:browser:detect": "npm run test:browser-tpl -- -f ./tests/detect.test.html", "test:browser:recognize": "npm run test:browser-tpl -- -f ./tests/recognize.test.html", "test:browser:scheduler": "npm run test:browser-tpl -- -f ./tests/scheduler.test.html", + "test:browser:FS": "npm run test:browser-tpl -- -f ./tests/FS.test.html", "lint": "eslint src", "postinstall": "opencollective-postinstall || true" }, diff --git a/tests/FS.test.html b/tests/FS.test.html new file mode 100644 index 0000000..350c743 --- /dev/null +++ b/tests/FS.test.html @@ -0,0 +1,18 @@ + +
+ + + + + + + + + + + + + + diff --git a/tests/FS.test.js b/tests/FS.test.js new file mode 100644 index 0000000..6e99dc4 --- /dev/null +++ b/tests/FS.test.js @@ -0,0 +1,36 @@ +const { createWorker } = Tesseract; +const worker = createWorker(OPTIONS); +before(function cb() { + this.timeout(0); + return worker.load(); +}); + +describe('FS', async () => { + it('should write and read text from FS (using FS only)', () => { + [ + SIMPLE_TEXT, + ].forEach(async (text) => { + const path = 'tmp.txt'; + await worker.FS('writeFile', [path, SIMPLE_TEXT]); + setTimeout(async () => { + const { data } = await worker.FS('readFile', [path]); + await worker.FS('unlink', [path]); + expect(data).to.be(SIMPLE_TEXT); + }, 200); + }); + }).timeout(TIMEOUT); + + it('should write and read text from FS (using writeFile, readFile)', () => { + [ + SIMPLE_TEXT, + ].forEach(async (text) => { + const path = 'tmp2.txt'; + await worker.writeText(path, SIMPLE_TEXT); + setTimeout(async () => { + const { data } = await worker.readText(path); + await worker.removeText(path); + expect(data).to.be(SIMPLE_TEXT); + }, 200); + }); + }).timeout(TIMEOUT); +});