内容简介:Node.js v14.2.0 发布了,主要更新内容包括: 使用 assert.CallTracker 跟踪函数调用(实验) assert.CallTracker 是一个新的实验性 API,它允许跟踪并稍后验证函数被调用的次数。通过创建一个 CallTracker 对象并...
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/
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- NPM包(模块)发布、更新、撤销发布
- 有赞灰度发布与蓝绿发布实践
- 【重磅发布】Linkis 0.10.0 版本发布
- BeetlSQL 3.0.9 发布,Idea 插件发布
- 贝密游戏 0.7.0 发布,发布斗地主
- 【重磅发布】DataSphere Studio 0.9.0 版本发布
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
奔跑吧 Linux内核
张天飞 / 人民邮电出版社 / 2017-9-1 / CNY 158.00
本书内容基于Linux4.x内核,主要选取了Linux内核中比较基本和常用的内存管理、进程管理、并发与同步,以及中断管理这4个内核模块进行讲述。全书共分为6章,依次介绍了ARM体系结构、Linux内存管理、进程调度管理、并发与同步、中断管理、内核调试技巧等内容。本书的每节内容都是一个Linux内核的话题或者技术点,读者可以根据每小节前的问题进行思考,进而围绕问题进行内核源代码的分析。 本书内......一起来看看 《奔跑吧 Linux内核》 这本书的介绍吧!