Skip to content

Commit

Permalink
Minor bugfixes (#47)
Browse files Browse the repository at this point in the history
- match pathnames with dot('.') literals in them
- serialize and accept a `browser` option in config

---------

Co-authored-by: Arthur Buldauskas <[email protected]>
  • Loading branch information
ballercat and Arthur Buldauskas authored Dec 8, 2023
1 parent 5ab3498 commit 8c0f87a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/__tests__/server.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand All @@ -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}`,
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/matchers/GlobMatcher.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 8c0f87a

Please sign in to comment.