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.

Revisions

  1. marufsiddiqui created this gist May 19, 2021.
    32 changes: 32 additions & 0 deletions testResultsProcessorNodeEnv.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    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
    }