Skip to content
Permalink
Browse files
Make t.log() behave more like console.log()
  • Loading branch information
kugtong33 authored and novemberborn committed Jan 25, 2018
1 parent f00f3c4 commit 4f896c2832a186bf0c7f6b0f21b0e36b8e8fdcf2
Showing 6 changed files with 30 additions and 8 deletions.
@@ -84,7 +84,7 @@ type TestContext = AssertContext & {
title: string;
plan(count: number): void;
skip: AssertContext;
log(message: string): void;
log(...values: Array<any>): void;
};
type ContextualTestContext = TestContext & { context: any; };
type ContextualCallbackTestContext = TestContext & { context: any; end(): void; };
@@ -130,8 +130,16 @@ function wrapAssertions(callbacks) {
}
},

log(text) {
log(this, text);
log() {
const args = Array.from(arguments, value => {
return typeof value === 'string' ?
value :
concordance.format(value, concordanceOptions);
});

if (args.length > 0) {
log(this, args.join(' '));
}
},

deepEqual(actual, expected, message) {
@@ -890,9 +890,9 @@ Plan how many assertion there are in the test. The test will fail if the actual

End the test. Only works with `test.cb()`.

###### `t.log(message)`
###### `t.log(...values)`

Print a log message contextually alongside the test result instead of immediately printing it to `stdout` like `console.log`.
Log values contextually alongside the test result instead of immediately printing them to `stdout`. Behaves somewhat like `console.log`, but without support for placeholder tokens.

## Assertions

@@ -0,0 +1,8 @@
/* @flow */

const test = require('../../index.js.flow');

test('log', t => {
t.pass();
t.log({object: true}, 42, ['array'], false, new Date(), new Map());
})
@@ -741,13 +741,19 @@ test('log from tests', t => {
a.log('a log message from a test');
t.true(true);
a.log('another log message from a test');
a.log({b: 1, c: {d: 2}}, 'complex log', 5, 5.1);
a.log();
}, null, r => {
result = r;
}).run();

t.deepEqual(
result.result.logs,
['a log message from a test', 'another log message from a test']
[
'a log message from a test',
'another log message from a test',
'{\n b: 1,\n c: {\n d: 2,\n },\n} complex log 5 5.1'
]
);

t.end();
@@ -104,9 +104,9 @@ export interface TestContext extends AssertContext {

skip: AssertContext;
/**
* Print a log message contextually alongside the test result instead of immediately printing it to stdout like console.log.
* Log values contextually alongside the test result instead of immediately printing them to `stdout`.
*/
log(message: string): void;
log(...values: any[]): void;
}
export interface CallbackTestContext extends TestContext {
/**

0 comments on commit 4f896c2

Please sign in to comment.