Skip to content

Commit fcd1421

Browse files
committed
Update to Mockttp v2.7.0 and avoid deprecated APIs to prepare for v3
We don't want to update to v3 immediately, since some edge cases mean it's useful to roll out a widespread UI update first (and because there's no urgent need for it) but this lays the groundwork so that it's easy to do that update with no breakage later on.
1 parent ac94d7a commit fcd1421

File tree

9 files changed

+63
-29
lines changed

9 files changed

+63
-29
lines changed

pack.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const packageApp = async () => {
5151
// Add the fully bundled source (not normally packaged by npm):
5252
path.join('bundle', 'index.js'),
5353
path.join('bundle', 'error-tracking.js'),
54-
path.join('bundle', 'schema.gql'),
5554
// Static resources normally stored in browser-launcher
5655
path.join('bundle', 'bl-resources')
5756
].map((extraFile) =>

package-lock.json

Lines changed: 44 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"lookpath": "^1.2.1",
6666
"mime-types": "^2.1.27",
6767
"mobx": "^6.3.5",
68-
"mockttp": "^2.6.0",
68+
"mockttp": "^2.7.0",
6969
"node-abort-controller": "^3.0.1",
7070
"node-fetch": "^2.6.1",
7171
"node-forge": "^1.3.0",

src/api-server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { makeExecutableSchema } from '@graphql-tools/schema';
88
import { GraphQLScalarType } from 'graphql';
99
import { graphqlHTTP } from 'express-graphql';
1010

11-
import { generateSPKIFingerprint, MockttpStandalone } from 'mockttp';
11+
import { generateSPKIFingerprint, MockttpAdminServer } from 'mockttp';
1212
import { getSystemProxy } from 'os-proxy-config';
1313

1414
import { HtkConfig } from './config';
@@ -113,7 +113,7 @@ const INTERCEPTOR_TIMEOUT = 1000;
113113
const buildResolvers = (
114114
config: HtkConfig,
115115
interceptors: _.Dictionary<Interceptor>,
116-
mockttpStandalone: MockttpStandalone,
116+
mockttpAdminServer: MockttpAdminServer,
117117
eventEmitter: events.EventEmitter
118118
) => {
119119
return {
@@ -139,7 +139,7 @@ const buildResolvers = (
139139
return [`127.0.0.1:${dnsServer.address().port}`];
140140
},
141141
ruleParameterKeys: async (): Promise<String[]> => {
142-
return mockttpStandalone.ruleParameterKeys;
142+
return mockttpAdminServer.ruleParameterKeys;
143143
}
144144
},
145145

@@ -275,14 +275,14 @@ export class HttpToolkitServerApi extends events.EventEmitter {
275275

276276
private server: express.Application;
277277

278-
constructor(config: HtkConfig, mockttpStandalone: MockttpStandalone) {
278+
constructor(config: HtkConfig, mockttpAdminServer: MockttpAdminServer) {
279279
super();
280280

281281
let interceptors = buildInterceptors(config);
282282

283283
const schema = makeExecutableSchema({
284284
typeDefs,
285-
resolvers: buildResolvers(config, interceptors, mockttpStandalone, this)
285+
resolvers: buildResolvers(config, interceptors, mockttpAdminServer, this)
286286
});
287287

288288
this.server = express();

src/cert-check-server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ export class CertCheckServer {
3838
await this.server.start(EPHEMERAL_PORT_RANGE);
3939

4040
await Promise.all([
41-
this.server.get('/test-https').thenCallback(() => {
41+
this.server.forGet('/test-https').thenCallback(() => {
4242
console.log('Request to /test-https successfully received');
4343
this.certCheckedSuccessfully.resolve(true);
4444
return { statusCode: 200 };
4545
}),
46-
this.server.get('/check-cert').thenCallback(() => {
46+
this.server.forGet('/check-cert').thenCallback(() => {
4747
console.log('Request to /check-cert received');
4848

4949
return {
@@ -117,7 +117,7 @@ export class CertCheckServer {
117117
`)
118118
};
119119
}),
120-
this.server.get('/failed-test').thenCallback(() => {
120+
this.server.forGet('/failed-test').thenCallback(() => {
121121
console.log('Request to /failed-test received');
122122
this.certCheckedSuccessfully.resolve(false);
123123

src/hide-warning-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class HideWarningServer {
2727
async start(targetUrl: string) {
2828
await this.server.start(EPHEMERAL_PORT_RANGE);
2929

30-
await this.server.get('/hide-warning').thenReply(200, `
30+
await this.server.forGet('/hide-warning').thenReply(200, `
3131
<html>
3232
<title>HTTP Toolkit Warning Fix</title>
3333
<meta charset="UTF-8" />

src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as path from 'path';
22
import * as fs from 'fs';
33
import * as envPaths from 'env-paths';
4-
import { getStandalone, generateCACertificate } from 'mockttp';
5-
import { MockttpStandalone } from 'mockttp/dist/standalone/mockttp-standalone';
4+
import { getAdminServer, generateCACertificate } from 'mockttp';
5+
import { MockttpAdminServer } from 'mockttp';
66
import { Mutex } from 'async-mutex';
77

88
import updateCommand from '@oclif/plugin-update/lib/commands/update';
@@ -66,18 +66,18 @@ function checkCertExpiry(certContents: string): void {
6666
}
6767

6868
function manageBackgroundServices(
69-
standalone: MockttpStandalone,
69+
standalone: MockttpAdminServer,
7070
httpsConfig: { certPath: string, certContent: string }
7171
) {
72-
standalone.on('mock-server-started', async (server) => {
73-
startDockerInterceptionServices(server.port, httpsConfig, ruleParameters)
72+
standalone.on('mock-session-started', async ({ http }) => {
73+
startDockerInterceptionServices(http.getMockServer().port, httpsConfig, ruleParameters)
7474
.catch((error) => {
7575
console.log("Could not start Docker components:", error);
7676
});
7777
});
7878

79-
standalone.on('mock-server-stopping', (server) => {
80-
stopDockerInterceptionServices(server.port, ruleParameters)
79+
standalone.on('mock-session-stopping', ({ http }) => {
80+
stopDockerInterceptionServices(http.getMockServer().port, ruleParameters)
8181
.catch((error) => {
8282
console.log("Could not stop Docker components:", error);
8383
});
@@ -112,7 +112,7 @@ export async function runHTK(options: {
112112
console.log('Certificates setup in', certSetupTime - configCheckTime, 'ms');
113113

114114
// Start a Mockttp standalone server
115-
const standalone = getStandalone({
115+
const standalone = getAdminServer({
116116
serverDefaults: {
117117
cors: false, // Don't add mocked CORS responses to intercepted traffic
118118
recordTraffic: false, // Don't persist traffic here (keep it in the UI)

src/message-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class MessageServer {
1919
this.server = getLocal({ https: this.config.https, cors: true });
2020
await this.server.start(EPHEMERAL_PORT_RANGE);
2121

22-
await this.server.get('/')
22+
await this.server.forGet('/')
2323
.thenCallback(() => {
2424
console.log('Request to message server received');
2525
this.messageSeen.resolve();

webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ module.exports = {
8787
new webpack.IgnorePlugin(/^\.\/protocol.json$/, /chrome-remote-interface/),
8888
// Copy Mockttp's schema (read with readFile) into the output directory
8989
new CopyWebpackPlugin([
90-
{ from: path.join('node_modules', 'mockttp', 'dist', 'standalone', 'schema.gql') },
9190
{ from: path.join('node_modules', '@httptoolkit', 'browser-launcher', 'res'), to: 'bl-resources' }
9291
]),
9392
// If SENTRY_AUTH_TOKEN is set, upload this sourcemap to Sentry

0 commit comments

Comments
 (0)