nodeunit

【从0到1学习边缘容器系列2】之 边缘应用管理

白昼怎懂夜的黑 提交于 2020-10-23 15:54:16
边缘容器作为当前热门的研究方向,腾讯云容器团队在孜孜不倦做技术研究的同时,也希望能 普惠到更多的云原生技术开发者们,为此推出【从0到1学习边缘容器系列】 。上次我们推出了第一篇《边缘计算与边缘容器的起源》,这次我们和大家来聊聊边缘场景下的容器应用部署和管理。 大家对使用Kubernetes管理应用已经比较熟悉,但是边缘场景下的应用部署和管理是否存在不同的需求呢?本文将和大家一起探讨 边缘场景下常见的容器应用管理方案 。 1. 边缘简单服务场景 在笔者接触过的边缘需求中部分用户业务场景比较简单,如:拨测服务。这种场景的特点是用户希望在每个节点部署相同的服务,并且每个节点起一个 pod 即可,这种场景一般推荐用户直接使用 daemonset 部署。关于 daemonset 的特点和使用方式读者可以阅读 kubernetes 官方文档。 2.边缘单站点部署微服务场景 第二种场景是部署边缘 SAAS 服务,由于涉及客户商业机密,此处暂不举例。用户会在一个边缘机房内部署一整套微服务,包括账号服务、接入服务、业务服务、存储及消息队列,服务之间借助kubernetes的dns做服务注册和发现。这种情况下客户可以直接使用 deployment和service,其中最主要的困难不在于服务管理而是边缘自治能力。 关于deployment和service的使用方式读者可以阅读kubernetes

Use Jasmine to stub JS callbacks based on argument values

拟墨画扇 提交于 2020-01-01 18:59:08
问题 I've got a JS method in my node.js app that I want to unit test. It makes several calls to a service method, each time passing that service a callback; the callback accumulates the results. How can I use Jasmine to stub out the service method so that each time the stub is called, it calls the callback with a response determined by the arguments? This is (like) the method I'm testing: function methodUnderTest() { var result = []; var f = function(response) {result.push(response)}; service

how to debug nodeunit using node-inspector

放肆的年华 提交于 2019-12-31 21:33:53
问题 I can do: I can test node.js modules using nodeunit. I can debug my node.js express site using node inspector. But how to debug nodeunit test using node inspector? I tried, but not working: nodeunit --debug myNodeUnitModule_test.js It's not working. I tried to install nodebug. And used it like this: nodebug /usr/local/bin/nodeunit myNodeunit_test.js But it's not working neither on ubuntu ( No such file or directory ) nor on mac ( env: node\r: No such file or directory ) Almost works node -

Nodeunit: Runtime/thrown errors in test function are _silent_

时间秒杀一切 提交于 2019-12-22 04:36:10
问题 One of the points of using NodeUnit is to write new functions and test them often. Problem is, if one of the tested functions throws an error (including JS runtime errors), the error is not shown to the user. Here is the simplest possible test case: (Note that a.b.c.d will cause a runtime error) exports.all = { one: function( test ){ test.done(); }, two: function( test ){ as( function( err, res ){ test.done(); }); }, } function as( callback ){ process.nextTick( function() { a = testMe();

Overriding functions in other modules in node.js

被刻印的时光 ゝ 提交于 2019-12-21 20:47:54
问题 I'm trying to stub a function with nodeunit in a Node.js app. Here's a simplified version of what I'm trying to do: In lib/file.js : var request = require('request'); var myFunc = function(input, callback){ request(input, function(err, body){ callback(body); }); }; In test/test.file.js : var file = require('../lib/file'); exports['test myFunc'] = function (test) { request = function(options, callback){ callback('testbody'); }; file.myFunc('something', function(err, body){ test.equal(body,

how I can get line number with error in coffeescript file

笑着哭i 提交于 2019-12-13 04:31:49
问题 In node.js express app and nodeunit tests I widely use coffeescript without saving resulting javascript files on disk to avoid project clogging by javascript translations. When I got any error in coffeeScript file I see in console: the filename where error was occured and line number (for example 37): /pathTo_File/fileName.coffee:37 . But I dont have 37th line in my coffee file!!! I have two times less lines there. I guess that I got error on 37th row in my output javascript file, but I don't

Using sinon mocks with nodeunit

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 02:32:41
问题 I'm learning to use sinon with nodeunit, specifically to do mocking. The recommended approach is to use sinon-nodeunit. According to the documentation, mocks should be available via the mock method of the test parameter to each test function. However, this doesn't seem to work. If I run nodeunit on a file containing the following — require('sinon-nodeunit'); exports['test sinon-nodeunit'] = function (test) { mock = test.mock({}); test.done(); }; — I get this: $ nodeunit test/test-sinon

Nodeunit testing event based async code

点点圈 提交于 2019-12-08 08:56:09
问题 I've already posted a few question the past few days, which were too long (I'm guessing because I didn't receive any non cryptic feedback). I've tried to make this brief. The following code uses a 'setup-complete' event to notify the nodeunit setUp command to run the tests. Test 1 passes, test 2 fails with FAILURES: Undone tests (or their setups/teardowns): - event based async code - test2 Is there some mistake in my code? Is nodeunit a bad choice for testing event based code? Is my approach?

Nodeunit testing event based async code

做~自己de王妃 提交于 2019-12-06 15:28:46
I've already posted a few question the past few days, which were too long (I'm guessing because I didn't receive any non cryptic feedback). I've tried to make this brief. The following code uses a 'setup-complete' event to notify the nodeunit setUp command to run the tests. Test 1 passes, test 2 fails with FAILURES: Undone tests (or their setups/teardowns): - event based async code - test2 Is there some mistake in my code? Is nodeunit a bad choice for testing event based code? Is my approach? Any advice appreciated. thanks async_setup.js: var events = require( 'events' ), setup = new events

Nodeunit: Runtime/thrown errors in test function are _silent_

老子叫甜甜 提交于 2019-12-05 03:40:55
One of the points of using NodeUnit is to write new functions and test them often. Problem is, if one of the tested functions throws an error (including JS runtime errors), the error is not shown to the user. Here is the simplest possible test case: (Note that a.b.c.d will cause a runtime error) exports.all = { one: function( test ){ test.done(); }, two: function( test ){ as( function( err, res ){ test.done(); }); }, } function as( callback ){ process.nextTick( function() { a = testMe(); callback( null, a ); }); } function testMe(){ a.b.c.d.e = 100; return 10; } However, testMe() might be a