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
// 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 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
git rm -r --cached . | |
git add . |
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 isOdd(x) { | |
return new Promise((resolve, reject) => { | |
if (x == 11) throw new Error('11 is not allowed!'); | |
if (x % 2) { | |
resolve(x.toString() + ' is odd') | |
} | |
else { | |
reject(new Error(x.toString() + ' is even')); | |
} | |
}); |
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
# save as ./github/workflows/git-ci-build.yml | |
# make sure that 'test-coverage' generates the coverage reports (lcov) | |
name: git-ci-build | |
on: | |
[push] | |
jobs: | |
build: |
OlderNewer