-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make t.log() behave like console.log() #1635
Comments
@edbrannin, thanks, that's a good catch.
Expanding support for logging non-strings makes sense too. We should use the same formatting as we do for other values (this line, basically). Would folks want to log more than one argument in that case? |
Yes, most are used to |
@novemberborn , i'll give this a try 👍 |
@vadimdemedes , will this be covered on your WIP task? @novemberborn @vadimdemedes , I will still write my thoughts here, on what I understood and if I have the correct context of the problem, to have feedback from you guys as I just started digging up the codes :) |
@kugtong33 #1645 does not impact this.
👍 |
So I tried all reporters, import test from 'ava';
test('Log an object', (t) => {
t.log('sample string log');
t.log({ a: 1 });
t.is(true, true);
});
/* mini only shows logs when it fails */
1 failed
Log an object
ℹ sample string log
ℹ [object Object]
/github/ava-labs/test/log.test.js:6
5: t.log({ a: 1 });
6: t.fail();
7: });
Test failed via `t.fail()`
/* verbose reporter */
✔ Log an object
ℹ sample string log
ℹ [object Object]
1 test passed
/* tap throws an error as described by the issue */ Logs are stored in an array as I have seen in here and is directly fed into If we want it to behave the same as Does it sound right? |
Yes. We should use the same formatting as we do for other values (this line, basically). |
@novemberborn , I also found this import test from 'ava';
test('Log an object', (t) => {
t.log();
t.is(true, true);
});
/* verbose */
✔ Log an object
ℹ null
1 test passed
/* mini when test fails */
Log an object
ℹ null
/github/ava-labs/test/log.test.js:5
4: t.log();
5: t.fail();
6: });
/* tap */
TAP version 13
/github/ava-labs/node_modules/indent-string/index.js:9
throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof str}\``);
^
TypeError: Expected `input` to be a `string`, got `object`
at module.exports (/github/ava-labs/node_modules/indent-string/index.js:9:9)
at test.logs.forEach.log (/github/ava-labs/node_modules/ava/lib/reporters/tap.js:64:23)
at Array.forEach (<anonymous>)
at appendLogs (/github/ava-labs/node_modules/ava/lib/reporters/tap.js:63:15)
at TapReporter.test (/github/ava-labs/node_modules/ava/lib/reporters/tap.js:83:4)
at Logger.test (/github/ava-labs/node_modules/ava/lib/logger.js:27:28)
at emitTwo (events.js:126:13)
at RunStatus.emit (events.js:214:7)
at RunStatus.handleTest (/github/ava-labs/node_modules/ava/lib/run-status.js:105:8)
at emitOne (events.js:121:20)
at ChildProcess.emit (events.js:211:7)
at ChildProcess.ps.on.event (/github/ava-labs/node_modules/ava/lib/fork.js:79:7)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at emit (internal/child_process.js:772:12)
at _combinedTickCallback (internal/process/next_tick.js:141:11) |
@kugtong33 ...and we've come full-circle to the error that prompted this issue. :) |
Description
When using
--tap
output, trying to log an object results in an error. Worse, the stack trace points to ava internals, not to my test code.If
t.log
is given an object:JSON.stringify(arg, null, 2)
I do a lot of
t.log(JSON.stringify(resp.body, null, 2));
and it would be great to just sayt.log(resp.body);
instead.Test Source
Error Message & Stack Trace
Config
N/A. Here's my test package.json:
Command-Line Arguments
Copy your npm build scripts or the
ava
command used:Relevant Links
https://github.com/edbrannin/ava-issue-1635
Environment
Tell us which operating system you are using, as well as which versions of Node.js, npm, and AVA. Run the following to get it quickly:
The text was updated successfully, but these errors were encountered: