Browse Source

Add tests for FS functions

pull/443/head
jeromewu 5 years ago
parent
commit
1ff4b79f75
  1. 1
      package.json
  2. 18
      tests/FS.test.html
  3. 36
      tests/FS.test.js

1
package.json

@ -21,6 +21,7 @@ @@ -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"
},

18
tests/FS.test.html

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/expect.js/index.js"></script>
<script src="../dist/tesseract.dev.js"></script>
<script src="./constants.js"></script>
<script>mocha.setup('bdd');</script>
<script src="./FS.test.js"></script>
<script>
mocha.run();
</script>
</body>
</html>

36
tests/FS.test.js

@ -0,0 +1,36 @@ @@ -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);
});
Loading…
Cancel
Save