Created
May 19, 2021 09:56
-
-
Save marufsiddiqui/b699b9e054357e24b07d80dcb7eb391f to your computer and use it in GitHub Desktop.
Adds jest-env node for the tests that can run in node only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const _prependNodeDocBlock = filePath => { | |
const docBlock = `/** | |
* @jest-environment node | |
*/ | |
` | |
fs.readFile(filePath, 'utf8', (error, result) => { | |
if (error && error.code !== 'ENOENT') { | |
return console.log(error) | |
} | |
if (result) { | |
const content = docBlock + '\n' + result | |
fs.writeFile(filePath, content, err => { | |
if (!err) { | |
console.log('updated file', filePath) | |
} | |
}) | |
} | |
}) | |
} | |
module.exports = runResults => { | |
for (const testResult of runResults.testResults) { | |
if (!testResult.failureMessage) { | |
_prependNodeDocBlock(testResult.testFilePath) | |
} | |
} | |
return runResults | |
} |
Author
marufsiddiqui
commented
Jun 2, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment