From 8c0f87ada707fad6630c7c92df2f9e9347839c3e Mon Sep 17 00:00:00 2001 From: Arthur Buldauskas Date: Thu, 7 Dec 2023 20:26:53 -0500 Subject: [PATCH 1/2] Minor bugfixes (#47) - match pathnames with dot('.') literals in them - serialize and accept a `browser` option in config --------- Co-authored-by: Arthur Buldauskas --- src/Config.mjs | 7 +++++++ src/__tests__/server.test.mjs | 8 ++++++-- src/matchers/GlobMatcher.mjs | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Config.mjs b/src/Config.mjs index 3e62dbd..6dbd5f9 100644 --- a/src/Config.mjs +++ b/src/Config.mjs @@ -22,12 +22,14 @@ const debug = createDebug('config'); * @property {boolean=} blockNetworkRequests * @property {boolean=} paused * @property {string=} port + * @property {string=} browser */ export default class Config extends Emitter { /** * @member {URL} */ serverURL; + browser = 'chrome'; cwd = ''; dir = ''; filepath = ''; @@ -124,6 +126,10 @@ export default class Config extends Emitter { this.serverURL.port = options.port; } + if (typeof options.browser === 'string') { + this.browser = options.browser; + } + this.dispatch('update', this.serialize()); } @@ -184,6 +190,7 @@ export default class Config extends Emitter { serialize() { return { + browser: this.browser, serverURL: this.serverURL.origin, paused: this.paused, blockNetworkRequests: this.blockNetworkRequests, diff --git a/src/__tests__/server.test.mjs b/src/__tests__/server.test.mjs index e93a17d..cc93d83 100644 --- a/src/__tests__/server.test.mjs +++ b/src/__tests__/server.test.mjs @@ -43,6 +43,7 @@ test.serial('ws - config', async (t) => { await supertest(t.context.server) .post('/api/config') .send({ + browser: 'chrome-canary', forward: { 'http://github.com': `http://localhost:${APP_PORT}`, 'http://google.com': `http://localhost:${APP_PORT}`, @@ -55,6 +56,7 @@ test.serial('ws - config', async (t) => { t.like(JSON.parse(ws.messages.pendingPush[0].data.toString()), { type: 'config.update', payload: { + browser: 'chrome-canary', forward: { 'http://github.com': `http://localhost:${APP_PORT}`, 'http://google.com': `http://localhost:${APP_PORT}`, @@ -68,8 +70,10 @@ test.serial('ws - config', async (t) => { const res = await (await fetch('http://github.com', opts)).json(); t.like(res, { path: '/' }); - const res2 = await (await fetch('http://google.com/echo', opts)).json(); - t.like(res2, { path: '/echo' }); + // the dot '.' in the path below is intentional + // see https://github.com/ballercat/jambox/pull/47 + const res2 = await (await fetch('http://google.com/.echo', opts)).json(); + t.like(res2, { path: '/.echo' }); }); test.serial('auto mocks', async (t) => { diff --git a/src/matchers/GlobMatcher.mjs b/src/matchers/GlobMatcher.mjs index 2ca9d4d..d5e1872 100644 --- a/src/matchers/GlobMatcher.mjs +++ b/src/matchers/GlobMatcher.mjs @@ -4,7 +4,7 @@ import mockttp from 'mockttp'; const checkGlobs = (url, globs) => { for (const glob of globs) { - if (!minimatch(url.pathname, glob)) { + if (!minimatch(url.pathname, glob, { dot: true })) { return false; } } From cbadef83ba93d3c2051fc296c43926c3867378f5 Mon Sep 17 00:00:00 2001 From: Arthur Buldauskas Date: Thu, 7 Dec 2023 20:35:09 -0500 Subject: [PATCH 2/2] publish 0.1.3 --- CHANGELOG.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b0a9da..cc66f68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.1.3 - Match paths containing dots, serialize browser config values + +- fix: match pathnames with dot('.') literals in them +- fix: serialize and accept a `browser` option in config + ## 0.1.2 - Fix config api route - fix: wait on `reset` event during config api calls diff --git a/package.json b/package.json index a593e6b..ada0402 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jambox", - "version": "0.1.2", + "version": "0.1.3", "description": "Tool for recording and playing back HTTP requests.", "bin": { "jam": "./jam.mjs",