diff --git a/index.js b/index.js index 7952c80..4d315e0 100644 --- a/index.js +++ b/index.js @@ -31,6 +31,8 @@ module.exports = function domwaiter (pages, opts = {}) { } async function getPage (page, emitter, opts) { + emitter.emit('beforePageLoad', page) + if (opts.json) { try { const json = await got(page.url).json() diff --git a/readme.md b/readme.md index 772fc83..e13b7dc 100644 --- a/readme.md +++ b/readme.md @@ -58,7 +58,8 @@ This module exports a single function `domwaiter`: The `domwaiter` function returns an event emitter which emits the following events: -- `page` - Emitted as each page has been requested and parsed. Returns an object which is a shallow clone of the original `page` object you provided, but with two added properties: +- `beforePageLoad` - Emitted with `page` object for any optional prehandling you want to do, e.g. setting up a request timer. +- `page` - Emitted after the page has been requested and the response is parsed. Returns an object which is a shallow clone of the original `page` object you provided, but with two added properties: - `body`: the raw HTTP response body text - `$`: The body parsed into a jQuery-like [cheerio](https://ghub.io/cheerio) DOM object. - `error` - Emitted when an error occurs fetching a URL diff --git a/test.js b/test.js index e8eef73..b9e2f06 100644 --- a/test.js +++ b/test.js @@ -9,7 +9,7 @@ describe('domwaiter', () => { expect(typeof domwaiter).toBe('function') }) - test('emits events', (done) => { + test('emits `page` and `done` events', (done) => { const mock = nock('https://example.com') .get('/foo') .reply(200, '