Conversation
README.md
Outdated
const puppeteer = require('puppeteer') | ||
|
||
// ... In async function |
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.
It would probably be best to just put this code in an async
fn so that people can copy/paste and run without modifying anything.
What do you think?
@@ -22,9 +22,10 @@ This module uses a chainable API to assist in injecting, configuring and analyzi | |||
Here is an example of a script that will drive Puppeteer to this repository, perform analysis and then log results to the console. | |||
|
|||
```js | |||
const AxePuppeteer = require('axe-puppeteer') | |||
const { AxePuppeteer } = require('axe-puppeteer') |
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.
It'd be nice if this wasn't required. Can we just do module.exports = AxePuppeteer
instead? I know TS will complain, but we can just disable the linter for the added line.
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.
The problem is that then we can't export anything else
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.
Which means no access to the loadPage
function.
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.
Can we do something like:
// The below is to ensure CommonJS `require()` works as expected.
// tslint:disable-next-line
exports = module.exports = AxePuppeteer
// ESM exports.
export { loadPage }
export default AxePuppeteer
Note that I haven't tested this.
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.
Nope. loadPage
is undefined
with that. Apparently CommonJS doesn't explicitly have "default" as a thing.
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.
I did a bit of testing and this will work fine. See this TypeScript playground example for proof.
Note that module.exports
and exports.default
are set there, as well as exports.loadPage
.
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.
Ahh, I see, exports is overwritten after we set exports.loadPage
. Disregard :)
Example didn't account for
axe-puppeteer
exporting multiple things. Also added comments about the context of the example code. Seems likeexport default
stopped working at some point, since I know the code used to work.Closes issue:
Reviewer checks
Required fields, to be filled out by PR reviewer(s)