Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xavdid committed May 9, 2020
1 parent 1ceb064 commit 767f6e5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@types/mocha": "^5.2.5",
"@types/node": "^10.11.7",
"mocha": "^5.2.0",
"p-event": "^4",
"typescript": "3.6.4"
},
"scripts": {
Expand Down
41 changes: 24 additions & 17 deletions test/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as assert from 'assert';
import * as mocha from 'mocha';
import pEvent = require('p-event')

const EPub = require('../../epub');

mocha.describe('EPub', () => {
Expand All @@ -11,15 +13,22 @@ mocha.describe('EPub', () => {
);
});

mocha.it('basic parsing', () => {
mocha.it('basic parsing', async () => {
const epub = new EPub('./example/alice.epub');

epub.on('end', ()=> {
assert.ok(epub.metadata.title)
assert.equal(epub.metadata.title, "Alice's Adventures in Wonderland")
})
epub.parse()
await pEvent(epub, 'end')

assert.ok(epub.metadata.title)
assert.equal(epub.metadata.title, "Alice's Adventures in Wonderland")

assert.equal(epub.toc.length, 14)

epub.parse();
assert.ok(epub.toc[3].level)
assert.ok(epub.toc[3].order)
assert.ok(epub.toc[3].title)
assert.ok(epub.toc[3].href)
assert.ok(epub.toc[3].id)

assert.strictEqual(
epub.imageroot,
Expand All @@ -34,18 +43,16 @@ mocha.describe('EPub', () => {
assert.ok(res);
});

mocha.it('raises descriptive errors', () => {
// const epub = new EPub('./example/alice.epub')
mocha.it('raises descriptive errors', async () => {
const epub = new EPub('./example/alice_broken.epub')

epub.on('error', (err) => {
assert.ok(err.message.includes('Error: Parsing container XML failed in TOC Error: Invalid character in entity name'))
})

epub.on('end', () => {
assert.fail('should not have gotten here')
})

epub.parse()
try {
epub.parse()
await pEvent(epub, 'end')
} catch (err) {
assert.ok(err.message.includes('Parsing container XML failed in TOC Error: Invalid character in entity name'))
return
}
assert.fail('should not get here')
})
});

0 comments on commit 767f6e5

Please sign in to comment.