设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 软件追踪 查看内容

Node.js v14.2.0发布

2020-5-6 16:30| 发布者: joejoe0332| 查看: 678| 评论: 0|原作者: oschina|来自: oschina

摘要: Node.js v14.2.0 发布了,主要更新内容包括: 使用assert.CallTracker跟踪函数调用(实验) assert.CallTracker是一个新的实验性 API,它允许跟踪并稍后验证函数被调用的次数。通过创建一个CallTracker对象并使用其c ...

Node.js v14.2.0 发布了,主要更新内容包括:

使用 assert.CallTracker 跟踪函数调用(实验)

assert.CallTracker 是一个新的实验性 API,它允许跟踪并稍后验证函数被调用的次数。通过创建一个 CallTracker 对象并使用其 calls 方法来创建包装器函数,该函数将在每次调用它们时计数。然后,可以使用 verify 方法来断言预期的调用次数:

const assert = require('assert');

const tracker = new assert.CallTracker();

function func() {}
// callsfunc() must be called exactly twice before tracker.verify().
const callsfunc = tracker.calls(func, 2);
callsfunc();
callsfunc();

function otherFunc() {}
// The second parameter defaults to `1`.
const callsotherFunc = tracker.calls(otherFunc);
callsotherFunc();

// Calls tracker.verify() and verifies if all tracker.calls() functions have
// been called the right number of times.
process.on('exit', () => {
  tracker.verify();
});

此外,tracker.report() 将返回一个数组,其中包含有关错误的信息(如果存在):

const assert = require('assert');

const tracker = new assert.CallTracker();

function func() {}
const callsfunc = tracker.calls(func);

console.log(tracker.report());
/*
[
  {
    message: 'Expected the func function to be executed 1 time(s) but was executed 0 time(s).',
    actual: 0,
    expected: 1,
    operator: 'func',
    stack: Error
        ...
  }
]
*/

控制台 groupIndentation 选项

控制台构造函数(require('console').Console)现在支持不同的组缩进。

const { Console } = require('console');
const customConsole = new Console({
  stdout: process.stdout,
  stderr: process.stderr,
  groupIndentation: 10
});

customConsole.log('foo');
// 'foo'
customConsole.group();
customConsole.log('foo');
//           'foo'

更新说明:https://nodejs.org/en/blog/release/v14.2.0/


酷毙

雷人

鲜花

鸡蛋

漂亮
  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部