there community, I'm having some issues in testing the generator I'm writing. in the generator, I'm using ora to get meaningful console outputs. the code is listed below.
let spinner = ora().start("\nprepairing git repository");
this.spawnCommand("git", ["init", "--quiet"], {
stdio: 'inherit'
});
spinner.succeed("git repository initialized");
when testing the generator, at some test, it gives outputs for ora. my question is that is there a way to suppress the console outputs so the outputs won't happen in the test here is the code at the test
test.beforeEach(t => {
let sora = sinon.stub(ora().__proto__, "start")
.withArgs("")
.returns({
"succeed": sinon.stub().withArgs(""),
"start": sinon.stub().withArgs("")
});
t.log(sora.called);
});
I also tried to inject the stubbed code by tapping into NodeJS native require api.
test.beforeEach(t => {
delete require.cache[require.resolve("ora")];
let sora = sinon.stub()
.withArgs("")
.returns({
"succeed": sinon.stub().withArgs(""),
"start": sinon.stub().withArgs("")
});
require.cache[require.resolve("ora")] = {
exports: sora
}
t.log(sora.called);
instead of using a mocked require library like proxyquire is there any way to suppress the console output or what is the best way to stub out code when we don't control the to exports?
Aucun commentaire:
Enregistrer un commentaire