Allow tests to tamper with Node.js built-ins without breaking AVA
See original GitHub issueWith latest master (c01ac05ef610c87f5c264b1a3eb80f89b4fc0832) and Node.js 4 and 7.
import fs from 'fs';
import test from 'ava';
import sinon from 'sinon';
test(t => {
fs.readFileSync = sinon.stub(fs, 'readFileSync');
// ...
fs.readFileSync.restore();
t.pass();
});
2 exceptions
Uncaught Exception
TypeError: Cannot read property 'sections' of undefined
new SourceMapConsumer (/Users/sindresorhus/dev/ava/node_modules/source-map/lib/source-map-consumer.js:20:19)
mapSourcePosition (/Users/sindresorhus/dev/ava/node_modules/source-map-support/source-map-support.js:171:14)
wrapCallSite (/Users/sindresorhus/dev/ava/node_modules/source-map-support/source-map-support.js:338:20)
/Users/sindresorhus/dev/ava/node_modules/source-map-support/source-map-support.js:373:26
Function.prepareStackTrace (/Users/sindresorhus/dev/ava/node_modules/source-map-support/source-map-support.js:372:24)
✖ Test results were not received from test.js
I think we need to protect all builtins from being overridden, so mocking in the tests doesn’t affect our usage or our dependencies’ usage of core APIs. Maybe running the test files in a new vm
context would help with that?
There is a $60.00 open bounty on this issue. Add more on Issuehunt.
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on Issuehunt to raise funds.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Getting Started with Node.js Unit Testing - KnowledgeHut
Node.js unit testing is a built-in assert module that allows you to test a condition and throw an error if it does not...
Read more >How To Test a Node.js Module with Mocha and Assert
Running tests consistently after writing new code ensures that new changes don't break pre-existing features. This gives the developer ...
Read more >Crypto | Node.js v19.3.0 Documentation
setAuthTag() method is used to pass in the received authentication tag. If no tag is provided, or if the cipher text has been...
Read more >Node.js Unit Testing: Get Started Quickly With Examples
Unit testing improves your code's quality and confidence. Find bugs early on in the software development lifecycle with a Node.js unit test.
Read more >AVA unit tests fails passed Javascript test specs - Stack Overflow
AVA does not support .mjs out of the box, but it looks like you figured out the configuration. For the test script, just...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
@mrozbarry this should be fixed with https://github.com/avajs/ava/pull/2057.
IMHO achieving this kind of isolation will have such an overhead as to not be worthwhile.