Skip to content

Commit c2f3f81

Browse files
committed
Console.log some timing metrics on startup
1 parent 836ca9c commit c2f3f81

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,21 @@ async function generateHTTPSConfig(configPath: string) {
4747
export async function runHTK(options: {
4848
configPath?: string
4949
} = {}) {
50+
const startTime = Date.now();
51+
5052
const configPath = options.configPath || envPaths('httptoolkit', { suffix: '' }).config;
5153

5254
await ensureDirectoryExists(configPath);
5355
await checkBrowserConfig(configPath);
5456

57+
const configCheckTime = Date.now();
58+
console.log('Config checked in', configCheckTime - startTime, 'ms');
59+
5560
const httpsConfig = await generateHTTPSConfig(configPath);
5661

62+
const certSetupTime = Date.now();
63+
console.log('Certificates setup in', certSetupTime - configCheckTime, 'ms');
64+
5765
// Start a standalone server
5866
const standalone = getStandalone({
5967
serverDefaults: {
@@ -95,5 +103,6 @@ export async function runHTK(options: {
95103

96104
await htkServer.start();
97105

98-
console.log('Server started');
106+
console.log('Server started in', Date.now() - certSetupTime, 'ms');
107+
console.log('Total startup took', Date.now() - startTime, 'ms');
99108
}

test/integration-test.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Integration test', function () {
2626

2727
return new Promise((resolve, reject) => {
2828
serverProcess.stdout.on('data', (d) => {
29-
resolve();
29+
if (d.includes('Server started')) resolve();
3030
stdout = stdout + d.toString();
3131
console.log(d.toString());
3232
});
@@ -49,7 +49,7 @@ describe('Integration test', function () {
4949
serverProcess.kill();
5050

5151
expect(stderr).to.equal('');
52-
expect(stdout).to.equal('Server started\n');
52+
expect(stdout).to.contain('\nServer started');
5353
});
5454

5555
it('starts a Mockttp server', async () => {

0 commit comments

Comments
 (0)