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
| // the sample simply logs every item with its corresponding path | |
| // replace 'logKeyValue' with custom functions/filters/... that should be applied | |
| function traverse(obj, path = []) { | |
| Object.entries(obj).forEach(([key, val]) => { | |
| if (val !== null && typeof val == 'object') { | |
| if (Array.isArray(val)) { | |
| for (let i = 0; i < val.length; i++) { | |
| let elem = val[i]; | |
| let itemKey = createKeyString(i, true); |
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 Readable = require('stream').Readable; | |
| // stream-to-buffer promise variant | |
| module.exports.streamToBufferPromise = function (stream) { | |
| return new Promise((resolve, reject) => { | |
| var bufs = []; | |
| var buffer = null; | |
| stream.on('error', (error) => { reject(error); }); | |
| stream.on('data', (data) => { bufs.push(data); }); | |
| stream.on('end', () => { |
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 myFunc = function (condition) { | |
| console.log('before'); | |
| if (condition) { | |
| process.exit(-1); | |
| } | |
| console.log('after'); | |
| } | |
| describe('jest-process-exit test suite', () => { |
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
| // MY_VAR is available in all Jest tests and suites, no need to adapt the before() or beforeAll() functions | |
| process.env['MY_VAR'] = 'My-Var-value'; | |
| module.exports = { | |
| testEnvironment: 'node' | |
| }; |
NewerOlder