繁体   English   中英

是否可以从节点端点运行mocha测试套件?

Is it possible to run mocha test suite from node endpoint?

提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供   中文繁体   英文版本   中英对照 版本,有任何建议请联系yoyou2525@163.com。

我们的团队构建了一个API,用于为我们的组织提供内部网络服务。 我建立了一个用于测试代码库的mocha测试套件,当前正在通过CLI运行它。

我们有一个公司监视服务,该服务会定期为每台服务器测试一个“ / webcheck”端点,并通知我们这些服务器是否已关闭。

当前,该端点仅以“ overall_status_code:ok”字符串响应,它告诉我们服务器正在运行,仅此而已。 其他端点可能被弄乱了,我们不知道。

我想将此端点绑定到我的Mocha测试套件中,以便在所有测试均通过的情况下,它仅返回“ overall_status_code:ok”。

有人暗示我该怎么做吗? 基本上,如何从节点内部调用测试?

如果您有兴趣,这是我的测试代码:

 const expect = require('chai').expect; const app = require('../server/app.js'); const supertest = require('supertest'); const request = supertest.agent(app); describe('Active Directory Module', () => { it('/ad/members endpoint should return: \\n -> an array of members for a given group \\n -> each element returned should be an object \\n -> John Doe should be the first user in the array', (done) => { request.get('/ad/members?group=%27CHQ%20Service%20Management%27') .expect(200) .end((err, res) => { let result = JSON.parse(res.text); expect(Array.isArray(result)).to.be.true; expect(typeof(result[0]) === 'object').to.be.true; expect(result[0].name === 'John Doe').to.be.true; done(); }) }) it('/ad/membership endpoint should return: \\n -> an array of groups for a given user \\n -> each element returned should be an object \\n -> \\'Domain Users\\' should be the first element in the array', (done) => { request.get('/ad/membership?user=%27chq-mikeru%27') .expect(200) .end((err, res) => { let result = JSON.parse(res.text); // let result = res; expect(Array.isArray(result)).to.be.true; expect(typeof(result[0]) === 'object').to.be.true; expect(result[0].name === 'Domain Users').to.be.true; done(); }) }) it('/ad/userinfo endpoint should return: \\n -> an object\\n -> Should include property called \\'Given Name\\'\\n -> given \\'chq-stephenro\\' the returned object should contain a property \\'UserPrincipleName\\' with value \\'chq-stephenro@corp.company.com\\'', (done) =>{ request.get('/ad/userinfo?user=%27chq-stephenho%27') .expect(200) .end((err, res) => { let result = JSON.parse(res.text); expect(typeof(result) === 'object').to.be.true; expect(result['GivenName']).to.not.be.undefined; expect(result['UserPrincipalName'] === 'chq-stephenro@corp.company.com').to.be.true; done(); }) }) }) describe('Database Querying Module', () => { it('/db/ci-co-conflict-checker should return \\n --> an array\\n --> of arrays\\n --> For each element:\\n * the first, third, and fourth elements should be numbers\\n * the second element should be a string\\n * the fifth element should be a string', (done) => { request.get('/db/ci-co-conflict-checker/?cis=%27CA%20Service%20Catalog%27,%27CA%20Service%20Desk%20Manager%27&start=1533106860&end=1535699040') .expect(200) .end((err, res) => { let result = res.body; expect(Array.isArray(result)).to.be.true; expect(Array.isArray(result[0])).to.be.true; for ( var i = 0; i < result.length; i++ ) { for (var j = 0; j < result[i].length; j++ ) { if ( j === 0 || j === 2 || j === 3) { expect(typeof(result[i][j]) === 'number').to.be.true; } if ( j === 1 || j === 4 ) { expect (typeof(result[i][j]) === 'string').to.be.true; } } } done(); }) }) }) 

1 个回复

是的,您只需要让客户端休息一下就可以对nodejs进行预期结果的比较,但这不是单元测试,而是集成测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题
 
粤ICP备18138465号  © 2020-2022 STACKOOM.COM