Skip to content

Commit a5cc8cf

Browse files
committed
chore: move all tests from jest to mocha
Ticket: WP-4695
1 parent beec742 commit a5cc8cf

File tree

10 files changed

+95
-81
lines changed

10 files changed

+95
-81
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules/
33
coverage/
44
.idea/
55
logs/
6+
tsconfig.tsbuildinfo

.mocharc.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module.exports = {
22
require: ['ts-node/register'],
33
extension: ['ts'],
4-
timeout: 60000,
5-
reporter: 'min',
6-
'reporter-option': ['cdn=true', 'json=false', 'consoleReporter=spec'],
7-
exit: true,
4+
timeout: 0,
5+
ui: 'bdd',
6+
spec: 'src/**/__tests__/**/*.test.ts',
7+
recursive: true,
8+
exit: true
89
};

jest.config.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"scripts": {
1111
"start": "nodemon bin/enclaved-bitgo-express",
1212
"build": "yarn tsc --build --incremental --verbose . && cp package.json dist/",
13-
"test": "jest",
14-
"test:watch": "jest --watch",
15-
"test:coverage": "jest --coverage",
13+
"test": "mocha --require ts-node/register 'src/**/__tests__/**/*.test.ts'",
14+
"test:watch": "mocha --require ts-node/register --watch 'src/**/__tests__/**/*.test.ts'",
15+
"test:coverage": "nyc mocha --require ts-node/register 'src/**/__tests__/**/*.test.ts'",
1616
"lint": "eslint --quiet .",
1717
"generate-test-ssl": "openssl req -x509 -newkey rsa:2048 -keyout test-ssl-key.pem -out test-ssl-cert.pem -days 365 -nodes -subj '/CN=localhost'"
1818
},
@@ -70,7 +70,8 @@
7070
"supertest": "^4.0.2",
7171
"ts-jest": "^29.1.2",
7272
"ts-node": "^10.9.2",
73-
"typescript": "^4.2.4"
73+
"typescript": "^4.2.4",
74+
"typescript-cached-transpile": "^0.0.6"
7475
},
7576
"engines": {
7677
"node": ">=22.1.0"

src/__tests__/config.test.ts

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'should';
12
import { config, isEnclavedConfig, TlsMode } from '../config';
23

34
describe('Configuration', () => {
@@ -6,23 +7,26 @@ describe('Configuration', () => {
67
const mockTlsCert = '-----BEGIN CERTIFICATE-----\nMOCK_CERT\n-----END CERTIFICATE-----';
78

89
beforeEach(() => {
9-
jest.resetModules();
1010
process.env = { ...originalEnv };
1111
// Clear TLS-related environment variables
1212
delete process.env.TLS_MODE;
1313
});
1414

15-
afterAll(() => {
15+
after(() => {
1616
process.env = originalEnv;
1717
});
1818

1919
it('should throw error when APP_MODE is not set', () => {
20-
expect(() => config()).toThrow('APP_MODE environment variable is required');
20+
(() => config()).should.throw(
21+
'APP_MODE environment variable is required. Set APP_MODE to either "enclaved" or "master-express"',
22+
);
2123
});
2224

2325
it('should throw error when APP_MODE is invalid', () => {
2426
process.env.APP_MODE = 'invalid';
25-
expect(() => config()).toThrow('Invalid APP_MODE: invalid');
27+
(() => config()).should.throw(
28+
'Invalid APP_MODE: invalid. Must be either "enclaved" or "master-express"',
29+
);
2630
});
2731

2832
describe('Enclaved Mode', () => {
@@ -36,64 +40,66 @@ describe('Configuration', () => {
3640

3741
it('should use default configuration when no environment variables are set', () => {
3842
const cfg = config();
39-
expect(isEnclavedConfig(cfg)).toBe(true);
43+
isEnclavedConfig(cfg).should.be.true();
4044
if (isEnclavedConfig(cfg)) {
41-
expect(cfg.port).toBe(3080);
42-
expect(cfg.bind).toBe('localhost');
43-
expect(cfg.tlsMode).toBe(TlsMode.MTLS);
44-
expect(cfg.timeout).toBe(305 * 1000);
45-
expect(cfg.kmsUrl).toBe('http://localhost:3000');
46-
expect(cfg.tlsKey).toBe(mockTlsKey);
47-
expect(cfg.tlsCert).toBe(mockTlsCert);
45+
cfg.port.should.equal(3080);
46+
cfg.bind.should.equal('localhost');
47+
cfg.tlsMode.should.equal(TlsMode.MTLS);
48+
cfg.timeout.should.equal(305 * 1000);
49+
cfg.kmsUrl.should.equal('http://localhost:3000');
50+
cfg.tlsKey!.should.equal(mockTlsKey);
51+
cfg.tlsCert!.should.equal(mockTlsCert);
4852
}
4953
});
5054

5155
it('should read port from environment variable', () => {
5256
process.env.ENCLAVED_EXPRESS_PORT = '4000';
5357
const cfg = config();
54-
expect(isEnclavedConfig(cfg)).toBe(true);
58+
isEnclavedConfig(cfg).should.be.true();
5559
if (isEnclavedConfig(cfg)) {
56-
expect(cfg.port).toBe(4000);
57-
expect(cfg.kmsUrl).toBe('http://localhost:3000');
58-
expect(cfg.tlsKey).toBe(mockTlsKey);
59-
expect(cfg.tlsCert).toBe(mockTlsCert);
60+
cfg.port.should.equal(4000);
61+
cfg.kmsUrl.should.equal('http://localhost:3000');
62+
cfg.tlsKey!.should.equal(mockTlsKey);
63+
cfg.tlsCert!.should.equal(mockTlsCert);
6064
}
6165
});
6266

6367
it('should read TLS mode from environment variables', () => {
6468
// Test with TLS disabled
6569
process.env.TLS_MODE = 'disabled';
6670
let cfg = config();
67-
expect(isEnclavedConfig(cfg)).toBe(true);
71+
isEnclavedConfig(cfg).should.be.true();
6872
if (isEnclavedConfig(cfg)) {
69-
expect(cfg.tlsMode).toBe(TlsMode.DISABLED);
70-
expect(cfg.kmsUrl).toBe('http://localhost:3000');
73+
cfg.tlsMode.should.equal(TlsMode.DISABLED);
74+
cfg.kmsUrl.should.equal('http://localhost:3000');
7175
}
7276

7377
// Test with mTLS explicitly enabled
7478
process.env.TLS_MODE = 'mtls';
7579
cfg = config();
76-
expect(isEnclavedConfig(cfg)).toBe(true);
80+
isEnclavedConfig(cfg).should.be.true();
7781
if (isEnclavedConfig(cfg)) {
78-
expect(cfg.tlsMode).toBe(TlsMode.MTLS);
79-
expect(cfg.kmsUrl).toBe('http://localhost:3000');
80-
expect(cfg.tlsKey).toBe(mockTlsKey);
81-
expect(cfg.tlsCert).toBe(mockTlsCert);
82+
cfg.tlsMode.should.equal(TlsMode.MTLS);
83+
cfg.kmsUrl.should.equal('http://localhost:3000');
84+
cfg.tlsKey!.should.equal(mockTlsKey);
85+
cfg.tlsCert!.should.equal(mockTlsCert);
8286
}
8387

8488
// Test with invalid TLS mode
8589
process.env.TLS_MODE = 'invalid';
86-
expect(() => config()).toThrow('Invalid TLS_MODE: invalid');
90+
(() => config()).should.throw(
91+
'Invalid TLS_MODE: invalid. Must be either "disabled" or "mtls"',
92+
);
8793

8894
// Test with no TLS mode (should default to MTLS)
8995
delete process.env.TLS_MODE;
9096
cfg = config();
91-
expect(isEnclavedConfig(cfg)).toBe(true);
97+
isEnclavedConfig(cfg).should.be.true();
9298
if (isEnclavedConfig(cfg)) {
93-
expect(cfg.tlsMode).toBe(TlsMode.MTLS);
94-
expect(cfg.kmsUrl).toBe('http://localhost:3000');
95-
expect(cfg.tlsKey).toBe(mockTlsKey);
96-
expect(cfg.tlsCert).toBe(mockTlsCert);
99+
cfg.tlsMode.should.equal(TlsMode.MTLS);
100+
cfg.kmsUrl.should.equal('http://localhost:3000');
101+
cfg.tlsKey!.should.equal(mockTlsKey);
102+
cfg.tlsCert!.should.equal(mockTlsCert);
97103
}
98104
});
99105

@@ -103,13 +109,13 @@ describe('Configuration', () => {
103109
process.env.MTLS_ALLOWED_CLIENT_FINGERPRINTS = 'ABC123,DEF456';
104110

105111
const cfg = config();
106-
expect(isEnclavedConfig(cfg)).toBe(true);
112+
isEnclavedConfig(cfg).should.be.true();
107113
if (isEnclavedConfig(cfg)) {
108-
expect(cfg.mtlsRequestCert).toBe(true);
109-
expect(cfg.mtlsAllowedClientFingerprints).toEqual(['ABC123', 'DEF456']);
110-
expect(cfg.kmsUrl).toBe('http://localhost:3000');
111-
expect(cfg.tlsKey).toBe(mockTlsKey);
112-
expect(cfg.tlsCert).toBe(mockTlsCert);
114+
cfg.mtlsRequestCert!.should.be.true();
115+
cfg.mtlsAllowedClientFingerprints!.should.deepEqual(['ABC123', 'DEF456']);
116+
cfg.kmsUrl.should.equal('http://localhost:3000');
117+
cfg.tlsKey!.should.equal(mockTlsKey);
118+
cfg.tlsCert!.should.equal(mockTlsCert);
113119
}
114120
});
115121
});

src/__tests__/index.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import 'should';
2+
13
describe('Basic test setup', () => {
24
it('should pass a basic test', () => {
3-
expect(true).toBe(true);
5+
true.should.be.true();
46
});
57

68
it('should handle basic math', () => {
7-
expect(1 + 1).toBe(2);
9+
(1 + 1).should.equal(2);
810
});
911
});

src/__tests__/masterBitgoExpress/generateWallet.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import nock from 'nock';
55
import { app as expressApp } from '../../masterExpressApp';
66
import { AppMode, MasterExpressConfig, TlsMode } from '../../types';
77
import { Environments } from '@bitgo/sdk-core';
8-
import { before, after } from 'mocha';
98

109
describe('POST /api/:coin/wallet/generate', () => {
1110
let agent: request.SuperAgentTest;

src/__tests__/routes.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'should';
12
import express from 'express';
23
import request from 'supertest';
34
import { setupRoutes } from '../routes/enclaved';
@@ -13,24 +14,24 @@ describe('Routes', () => {
1314
describe('Health Check Routes', () => {
1415
it('should return 200 and status message for /ping', async () => {
1516
const response = await request(app).post('/ping');
16-
expect(response.status).toBe(200);
17-
expect(response.body).toHaveProperty('status', 'enclaved express server is ok!');
18-
expect(response.body).toHaveProperty('timestamp');
17+
response.status.should.equal(200);
18+
response.body.should.have.property('status', 'enclaved express server is ok!');
19+
response.body.should.have.property('timestamp');
1920
});
2021

2122
it('should return version info for /version', async () => {
2223
const response = await request(app).get('/version');
23-
expect(response.status).toBe(200);
24-
expect(response.body).toHaveProperty('version');
25-
expect(response.body).toHaveProperty('name', '@bitgo/enclaved-bitgo-express');
24+
response.status.should.equal(200);
25+
response.body.should.have.property('version');
26+
response.body.should.have.property('name', '@bitgo/enclaved-bitgo-express');
2627
});
2728
});
2829

2930
describe('Error Handling', () => {
3031
it('should return 404 for non-existent routes', async () => {
3132
const response = await request(app).get('/non-existent-route');
32-
expect(response.status).toBe(404);
33-
expect(response.body).toHaveProperty(
33+
response.status.should.equal(404);
34+
response.body.should.have.property(
3435
'error',
3536
'Route not found or not supported in enclaved mode',
3637
);

tsconfig.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
{
22
"compilerOptions": {
3-
"target": "es2018",
4-
"module": "commonjs",
5-
"lib": ["es2018"],
6-
"declaration": true,
7-
"outDir": "./dist",
8-
"rootDir": ".",
9-
"strict": true,
3+
"target": "ES2020",
4+
"module": "CommonJS",
5+
"moduleResolution": "node",
106
"esModuleInterop": true,
7+
"strict": true,
118
"skipLibCheck": true,
129
"forceConsistentCasingInFileNames": true,
13-
"resolveJsonModule": true,
14-
"types": ["node", "jest"]
10+
"outDir": "dist",
11+
"rootDir": ".",
12+
"declaration": true,
13+
"resolveJsonModule": true
1514
},
1615
"include": ["src/**/*", "package.json"],
17-
"exclude": ["node_modules", "dist", "**/*.test.ts"]
16+
"exclude": ["node_modules", "dist"]
1817
}

yarn.lock

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5032,7 +5032,7 @@
50325032
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.17.60.tgz#35f3d6213daed95da7f0f73e75bcc6980e90597b"
50335033
integrity sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==
50345034

5035-
"@types/node@^12.12.54", "@types/node@^12.12.6":
5035+
"@types/node@^12.12.54", "@types/node@^12.12.6", "@types/node@^12.12.7":
50365036
version "12.20.55"
50375037
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240"
50385038
integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==
@@ -8763,6 +8763,15 @@ fs-extra@^4.0.2:
87638763
jsonfile "^4.0.0"
87648764
universalify "^0.1.0"
87658765

8766+
fs-extra@^8.1.0:
8767+
version "8.1.0"
8768+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
8769+
integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
8770+
dependencies:
8771+
graceful-fs "^4.2.0"
8772+
jsonfile "^4.0.0"
8773+
universalify "^0.1.0"
8774+
87668775
fs-extra@^9.1.0:
87678776
version "9.1.0"
87688777
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d"
@@ -13432,6 +13441,15 @@ typeforce@^1.11.3, typeforce@^1.11.5, typeforce@^1.18.0:
1343213441
resolved "https://registry.yarnpkg.com/typeforce/-/typeforce-1.18.0.tgz#d7416a2c5845e085034d70fcc5b6cc4a90edbfdc"
1343313442
integrity sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g==
1343413443

13444+
typescript-cached-transpile@^0.0.6:
13445+
version "0.0.6"
13446+
resolved "https://registry.yarnpkg.com/typescript-cached-transpile/-/typescript-cached-transpile-0.0.6.tgz#1d1f0620ebb29cf8d8c11e5353c2b4f43dfafc01"
13447+
integrity sha512-bfPc7YUW0PrVkQHU0xN0ANRuxdPgoYYXtZEW6PNkH5a97/AOM+kPPxSTMZbpWA3BG1do22JUkfC60KoCKJ9VZQ==
13448+
dependencies:
13449+
"@types/node" "^12.12.7"
13450+
fs-extra "^8.1.0"
13451+
tslib "^1.10.0"
13452+
1343513453
typescript@^4.2.4:
1343613454
version "4.9.5"
1343713455
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"

0 commit comments

Comments
 (0)