This file contains 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' | |
}; |
This file contains 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 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 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 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
function jsonToHtmlList(obj, level = 0) { | |
if (level == 0) { | |
console.log('<ul>'); | |
} | |
else { | |
console.log((' ').repeat(level) + '<ul class=\"nested\">'); | |
} | |
Object.entries(obj).forEach(([key, val]) => { | |
if (val !== null && typeof val == 'object' && !Array.isArray(val)) { | |
console.log((' ').repeat(level) + ' <li class=\"caret\">Key: ' + key + '</li>') |
This file contains 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 crypto = require('crypto'); | |
const algorithm = 'aes-256-cbc'; | |
const dbURI = 'mongodb://localhost/encryptiontest'; | |
const dbOptions = { | |
user: 'encryptiontest', | |
pass: 'test', | |
useNewUrlParser: true, | |
useCreateIndex: true, | |
useFindAndModify: false, |
This file contains 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
#!/bin/bash | |
# set URL to test here | |
url=YOUR_URL_HERE | |
# set test iterations here: requests|concurrent | |
declare -a iterations=("1|1" "10|10" "100|20" "100|100" "1000|50" "1000|100") | |
# first argument is the bearer token | |
if [ -z "$1" ] |
This file contains 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 got = require('got'); | |
const stream = require('stream'); | |
const fs = require('fs'); | |
const { promisify } = require('util'); | |
const pipeline = promisify(stream.pipeline); | |
// instantiate the download stream - use options to set authorization header etc. if needed | |
let downStream = got.stream('https://example.com/download'); | |
downStream.on('response', response => { |
This file contains 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
git rm -r --cached . | |
git add . |
OlderNewer