Logging inside a Command
#2967
-
|
Hi, I read this section in the docs on how to log in a predicate, but I'd like to log in a Is it possible to get access to a I tried export const commandsArbitrary = fc.commands(
[
fc.record({ context: fc.context(), someNumber: fc.nat(10 * 1000) }).map(({ context, someNumber }) => myCommand(context, someNumber)),
],
{ size: 'large' }
);and the command logs to Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
|
Hey, Logs will only be displayed in case of error (ie. property failing). |
Beta Was this translation helpful? Give feedback.
-
|
Here is probably a first working version to make the logs visible by using const commandsArbitrary = fc.context().chain((context) =>
fc.record({
context,
commands: fc.commands(
[fc.nat(10 * 1000).map((someNumber) => myCommand(context, someNumber))],
{ size: 'medium' }
),
})
);
fc.assert(
fc.property(commandsArbitrary, ({ commands }) => {
const real = {};
const model = {};
fc.modelRun(() => ({ model, real }), commands);
})
);Option 1 Another way to have the logs without this issue would be: function myCommand(context, someNumber) {
return {
check() {
return true;
},
run(m, r) {
context.log('hello world');
throw new Error('oops');
},
toString() {
return `myCommand(${context}, ${someNumber})`; // <-- change here
},
};
}Option 2 ⭐ Would probably go for option 2 🤔 I have not run them locally, hope they work 🤞 |
Beta Was this translation helpful? Give feedback.
Here is probably a first working version to make the logs visible by using
fc.contextbut it suffers from the fact that it makes use ofchainwhich does not shrink as well asmap,filteror others:Option 1
Another way to have the logs without this issue would be: