-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw better errors when there are parsing issues #49
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,17 @@ mocha.describe('EPub', () => { | |
`/images/` | ||
); | ||
}); | ||
|
||
mocha.it('basic parsing', () => { | ||
const epub = new EPub('./example/alice.epub'); | ||
|
||
epub.on('end', ()=> { | ||
assert.ok(epub.metadata.title) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added some basic coverage |
||
assert.equal(epub.metadata.title, "Alice's Adventures in Wonderland") | ||
}) | ||
|
||
epub.parse(); | ||
|
||
assert.strictEqual( | ||
epub.imageroot, | ||
`/images/` | ||
|
@@ -27,4 +33,19 @@ mocha.describe('EPub', () => { | |
var res = epub.walkNavMap(branch, [], []); | ||
assert.ok(res); | ||
}); | ||
|
||
mocha.it('raises descriptive errors', () => { | ||
// const epub = new EPub('./example/alice.epub') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's weird is that if this line is uncommented instead of the below, the tests still pass when they shouldn't 🤔 not sure if I'm parsing it wrong or what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, mocha doesn't wait for callbacks to be executed, does it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should move to async/await... :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, you're right. I haven't written mocha tests w/ But you're also right that we should use promises, so I added a tool for awaiting events and now it works like a charm! |
||
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() | ||
}) | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are the only two files actually needed at runtime for the user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea