我对后端服务器进行了大量的回归测试。 这些测试不再完成以在第一个测试中失败。 该项目源自使用webpack构建的angular-starter项目。该项目运行良好,但是回归测试不再起作用。
使用(testServer.sh)运行服务器中的测试:
#!/usr/bin/env bash
find . -name "*.js" -type f -delete
rm -rf coverage
tsc
export NODE_ENV='test'
export ...
...
istanbul cover --config='test.istanbul.yml' --report html _mocha -- -- $(find . -path ../node_modules -prune -o -name '*.spec.js');
../node_modules/.bin/remap-istanbul -i coverage/coverage.json -o coverage-final -t html;
echo 'all done:'
查找。 -path ../node_modules -prune -o -name'* .spec.js'列出:
./api/user/user.controller.spec.js
./api/user/user.model.spec.js
./api/user/index.spec.js
...
...
./auth/local/local.spec.js
./email/email.spec.js
第一个测试集来自“ ./api/user/user.controller.spec.js”。
第一个测试(user.controller.spec.ts)是:
import * as chai from 'chai';
import * as sinonChai from 'sinon-chai';
import { log, error } from '../../logging';
import mocha from 'mocha';
import * as app from '../../app';
import { Token } from '../user/token';
import * as userController from './user.controller';
import * as auth from '../../auth/auth.service';
import * as mongodb from 'mongodb';
import { User } from '../../api/user';
import { UserData } from '../../api/user';
chai.use(sinonChai);
const expect = chai.expect;
import * as request from 'supertest';
const users = User.getUsers();
describe('user.controller test', function () {
const admin_id = new mongodb.ObjectID('55148df6935c4bac084b30b2'); // JoelParke
const user_id = new mongodb.ObjectID('580bc41993b35207fd6c2263'); // joel@dynazu
const textangular_id = new mongodb.ObjectID('55a1baa2521bc91832f2450a');
const sample_id = new mongodb.ObjectID('5547e7520845397b4ff2eb18');
const icalAdmin = 'ZzO1xCPTB14qJrknRIXAkvRtWIqBewbEiH6dipFF.ics?nocache';
let accessTokenAdminUser: string;
this.timeout(10000);
before( (done: mocha.Done) => {
log('app setup');
app.start().then((res) => {
log('all setup and ready to test');
done();
});
});
it('checkSharingFromUsers success', (done: mocha.Done) => {
users.findOne({_id: admin_id})
.catch((err2: any) => {
throw err2;
})
.then((__user: UserData) => {
userController.checkSharingFrom(__user, textangular_id)
.then((result) => {
expect(result.found).equals(result.bWrite).equals(true);
done();
});
});
});
it('... success', (done: mocha.Done) => { ... });
....
....
});
运行./testServer.sh将调用的输出提供给app.start():
2018-07-29T13:52:01-0600 <log> app.js:9 () ApiSocket.bEnableSocket: set FALSE====================
*************** IPv6 array of addresses: [ '2601:283:8101:7c9e:e10a:a995:9c8f:ae87',
'2601:283:8101:7c9e:c73a:d0a6:5899:6e11' ]
(node:6535) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2018-07-29T13:52:01-0600 <log> seed.js:9 () removed 6 users
...
2018-07-29T13:52:01-0600 <log> seed.js:9 () populated 6 users.
2018-07-29T13:52:01-0600 <log> seed.js:9 () _users: 6
2018-07-29T13:52:01-0600 <log> seed.js:9 () removed 65 lists
2018-07-29T13:52:01-0600 <log> seed.js:9 () populated 65 lists.
2018-07-29T13:52:01-0600 <log> seed.js:9 () removed 881 tasks
2018-07-29T13:52:01-0600 <log> seed.js:9 () populated 881 tasks.
2018-07-29T13:52:01-0600 <log> seed.js:9 (Timeout._onTimeout) removed 1 commands
2018-07-29T13:52:01-0600 <log> seed.js:9 (Timeout._onTimeout) removed 10 files
2018-07-29T13:52:01-0600 <log> seed.js:9 () populated 10 files.
2018-07-29T13:52:01-0600 <log> seed.js:9 () removed 15 backups
2018-07-29T13:52:01-0600 <log> seed.js:9 () populated 15 backups.
2018-07-29T13:52:01-0600 <log> seed.js:9 () resolveAll ==============================
2018-07-29T13:52:01-0600 <log> app.js:9 () .............do transform.......
2018-07-29T13:52:01-0600 <log> transform.js:668 () done commands... 5
2018-07-29T13:52:01-0600 <log> transform.js:698 () done backups... 4
2018-07-29T13:52:01-0600 <log> transform.js:272 () done lists... 3
2018-07-29T13:52:01-0600 <log> transform.js:638 () done files... 2
2018-07-29T13:52:01-0600 <log> transform.js:874 () done users... 1
2018-07-29T13:52:01-0600 <log> transform.js:550 () done tasks... 0
2018-07-29T13:52:01-0600 <log> app.js:9 () ApiSocket.bEnableSocket: set TRUE ============================
2018-07-29T13:52:01-0600 <log> app.js:9 () *************** TEST SERVER ***************
但是-除了在app()中启动的服务器生成的初始日志消息外,我再也看不到任何日志消息 在test.istanbul.yml中设置verbose:true并运行./testServer.sh会给出:
Using configuration
-------------------
verbose: true
instrumentation:
root: .
extensions:
- .js
default-excludes: true
excludes:
- '**/customError.*'
- '**/errors/*.*'
- '**/config/socketio.*'
- '**/transform.*'
- '**/*.spec.*'
- '**/*.ts'
embed-source: false
variable: __coverage__
compact: true
preserve-comments: false
complete-copy: false
save-baseline: false
baseline-file: ./coverage/coverage-baseline.json
include-all-sources: false
include-pid: false
es-modules: false
preload-sources: false
reporting:
print: summary
reports:
- html
dir: ./coverage
watermarks:
statements: [50, 80]
lines: [50, 80]
functions: [50, 80]
branches: [50, 80]
report-config:
clover: {file: clover.xml}
cobertura: {file: cobertura-coverage.xml}
json: {file: coverage-final.json}
json-summary: {file: coverage-summary.json}
lcovonly: {file: lcov.info}
teamcity: {file: null, blockName: Code Coverage Summary}
text: {file: null, maxCols: 0}
text-lcov: {file: lcov.info}
text-summary: {file: null}
hooks:
hook-run-in-context: false
post-require-hook: null
handle-sigint: true
check:
global:
statements: 0
lines: 0
branches: 0
functions: 0
excludes: []
each:
statements: 0
lines: 0
branches: 0
functions: 0
excludes: []
-------------------
Running: node /usr/local/bin/_mocha -- ./api/user/user.controller.spec.js ./api/user/user.model.spec.js ./api/user/index.spec.js ... ... ./email/email.spec.js
Module load hook: transform [/home/joel/workspace/Tracker3/server/logging.js]
Module load hook: transform [/home/joel/workspace/Tracker3/server/email/email.js]
Module load hook: transform [/home/joel/workspace/Tracker3/server/localEnv.js]
Module load hook: ... ... ...
Module load hook: ... ... ...
Module load hook: transform [/home/joel/workspace/Tracker3/server/auth/google/index.js]
Module load hook: transform [/home/joel/workspace/Tracker3/server/auth/gitlab/index.js]
此输出之后是实例化来自服务器的日志消息(如上所示)。
但是我再也没有看到其他消息。等待很长时间后,按^ C给出: (因为我启用了handle-sigint:在test.istanbul.yml中为true)
^C=============================================================================
Writing coverage object [/home/joel/workspace/Tracker3/server/coverage/coverage.json]
Writing coverage reports at [/home/joel/workspace/Tracker3/server/coverage]
=============================================================================
=============================== Coverage summary ===============================
Statements : 54.15% ( 3643/6727 ), 1663 ignored
Branches : 56.19% ( 989/1760 ), 818 ignored
Functions : 35.07% ( 498/1420 ), 296 ignored
Lines : 54.15% ( 3641/6724 )
================================================================================
all done:
因此由于某种原因,测试已挂起。但是我不清楚为什么会这样,或者如何调试它。
如果您有任何见解,将不胜感激!
注意:我已经检查服务器是否在分配的端口9000上进行侦听: tcp6 0 0 ::: 9000 ::: *听1088 /节点