Skip to content

Commit 0c91ccb

Browse files
committed
test: updated UT
1 parent 94da1e5 commit 0c91ccb

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"lint:fix": "eslint --quiet --fix src test",
2727
"prepare": "husky install",
2828
"test": "npm run test:unit && npm run test:integ",
29-
"test:unit": "APP_CONFIG=./test/unit/utils/.app.json mocha test/unit/*.spec.js test/unit/**/*.spec.js test/unit/**/*.spec.js test/unit/**/**/*.spec.js --timeout=3000",
29+
"test:unit": "APP_CONFIG=./test/unit/utils/.app.json APP_CONFIG1=./test/unit/utils/.app1.json mocha test/unit/*.spec.js test/unit/**/*.spec.js test/unit/**/*.spec.js test/unit/**/**/*.spec.js --timeout=3000",
3030
"test:integ": "mocha test/integration/*.spec.js test/integration/**/*.spec.js --timeout=3000",
3131
"printReportsLink": "echo Detailed unit test coverage report: file:///$(pwd)/coverage-unit/index.html && echo Detailed integration test coverage report: file:///$(pwd)/coverage-integration/index.html",
3232
"cover": "npm run cover:unit",

test/unit/utils/.app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"port": "5000",
2+
"port": "3000",
33
"authKey": "YWxhZGRpbjpvcGVuc2VzYW1l",
44
"allowPublicAccess": false,
55
"mysql": {

test/unit/utils/.app1.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"authKey": "YWxhZGRpbjpvcGVuc2VzYW1l",
3+
"allowPublicAccess": false,
4+
"mysql": {
5+
"host": "localhost",
6+
"port": "3306",
7+
"database": "testdb",
8+
"user": "root",
9+
"password": "1234"
10+
}
11+
}

test/unit/utils/configs-test.spec.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,17 @@ describe('unit Tests', function () {
3232

3333
});
3434
it('default port should be 5000', function () {
35+
const backup = process.env.APP_CONFIG;
36+
process.env.APP_CONFIG = process.env.APP_CONFIG1;
37+
deleteAppConfig();
3538
let configs = getConfigs();
36-
_verifyConfigs(configs);
37-
configs = getConfigs();
38-
// call verify config second time
39-
_verifyConfigs(configs);
39+
expect(configs.port).to.eql('5000');
40+
process.env.APP_CONFIG = backup;
4041
});
4142
});
4243

4344
function _verifyConfigs(configs) {
44-
expect(configs.port).to.eql('5000');
45+
expect(configs.port).to.eql('3000');
4546
expect(configs.authKey.length).to.eql(24);
4647
expect(configs.mysql.port).to.eql('3306');
4748
expect(configs.mysql.user.length).to.gt(0);

0 commit comments

Comments
 (0)