Skip to content

Commit

Permalink
docs: Make example code use CommonJS require()
Browse files Browse the repository at this point in the history
Since ESM imports happen before the code is executed, mock-require
cannot be used (in theory) to mock ESM modules, unless they are
transpiled to CommonJS first. mock-require probably does not support
mocking native ES modules in Node.js

Eventually, someone may try to run the example using native ES modules,
and then complain that it doesn't work. To avoid confusion, let's
convert all examples to use CommonJS `require()`.
  • Loading branch information
pastelmind committed Mar 15, 2021
1 parent 5717813 commit d99b6bb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ To test this code in Node.js, you can inject `xpath()` function into the global

```js
// test/my-kolmafia-code.test.js
import mock from 'mock-require';
import {xpath} from 'kolmafia-stubs';
const mock = require('mock-require');
const {xpath} = require('kolmafia-stubs');

mock('kolmafia', {xpath});

import {myFunc} from './src/my-kolmafia-code';
const {myFunc} = require('./src/my-kolmafia-code');
```

## Provided functions
Expand Down

0 comments on commit d99b6bb

Please sign in to comment.