This is just an example to demonstrate how lab code coverage can get in the way
Last active
August 31, 2018 16:04
-
-
Save danielo515/22e33e3a4d48c0b60a4da16008cedd39 to your computer and use it in GitHub Desktop.
Demonstrate how lab code coverage can get into a promise chain
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
// This is a simple but valid function | |
const trace = (msg) => (x) => (console.info(msg, x), x); | |
// This will receive the result of the previous execution | |
const destructureSomething = ([a,b]) => { | |
console.log('I have destructured: ',a ,b ); | |
return [a,b] | |
} | |
// This is just a stupid function that does something | |
const executeThings = scopeA => scopeB => | |
{ | |
console.log('Scope A', scopeA); | |
console.log('Scope B', scopeB); | |
return Promise | |
.resolve([scopeA, scopeB]) | |
.then (trace('This are the scopes and the stuff')) // Here code coverage gets int and ruins the promise chain | |
.then (destructureSomething); | |
} | |
module.exports = { | |
name: 'fails-on-testing' | |
, version: '1.0.0' | |
, multiple: false | |
, async register(server, options) { | |
server.method('random.stuff', executeThings ('Hello from A')) | |
} | |
}; |
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 Lab = require('lab'); | |
const Sinon = require('sinon'); | |
// Test shortcuts | |
const lab = exports.lab = Lab.script(); | |
const { it, expect, experiment: describe, before, afterEach } = lab; | |
const server = { | |
method: Sinon.spy() | |
}; | |
// Module to test | |
const Plugin = require('./module.js'); | |
before((done) => { | |
// Register plugin | |
Plugin.register(server).then(() => { | |
done(); | |
}); | |
}); | |
describe ('Satan', (done) => { | |
it('Should not fail!', (done) => { | |
const executeThings = server.method.firstCall.args[1]; | |
executeThings('Hello from B').then((res) => { | |
expect(res).to.exist() | |
done(); | |
}); | |
}); | |
}); |
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
{ | |
"name": "putoLabCoverage", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "lab module.spec.js --reporter console --threshold 100 --assert code --coverage --verbose -l", | |
"test:ok": "lab module.spec.js --reporter console --assert code --verbose -l" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"code": "^5.2.0", | |
"lab": "^14.3.4", | |
"sinon": "^6.1.5" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment