Skip to content

Instantly share code, notes, and snippets.

@marufsiddiqui
Created May 19, 2021 09:56
Show Gist options
  • Save marufsiddiqui/b699b9e054357e24b07d80dcb7eb391f to your computer and use it in GitHub Desktop.
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
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
}
@marufsiddiqui
Copy link
Author

"test": "jest --passWithNoTests --silent -u $(lerna ls -a -p)",
"test1": "jest --passWithNoTests --silent --testEnvironment=node --testResultsProcessor=/Users/maruf/Projects/webmobile-pwa/config/jest/test.js $(lerna ls -a -p)",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment