Skip to content

Commit

Permalink
Merge branch 'main' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Buldauskas committed Dec 23, 2023
2 parents 88f6d08 + cbadef8 commit 97bebb6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
- feat: build & publish TS types
- fix: wait for full reset when cwd is changed via api

## 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
Expand Down
7 changes: 7 additions & 0 deletions src/Config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,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 @@ -140,6 +142,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 @@ -204,6 +210,7 @@ export default class Config extends Emitter {
*/
serialize() {
return {
browser: this.browser,

Check failure on line 213 in src/Config.mjs

View workflow job for this annotation

GitHub Actions / typecheck

Type '{ browser: string; serverURL: string; paused: boolean; blockNetworkRequests: boolean; cwd: string; forward: Record<string, ForwardOption>; cache: CacheOption; ... 4 more ...; errors: any[]; }' is not assignable to type 'SerializedConfig'.
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 97bebb6

Please sign in to comment.