Skip to content

Commit

Permalink
Log responses in a collapsed log group
Browse files Browse the repository at this point in the history
  • Loading branch information
latonv committed Jan 26, 2023
1 parent 2054a6a commit 7125c2e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/search-backend/base-search-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ export abstract class BaseSearchBackend implements SearchBackendInterface {
}

console.log(`\n\n***** RESPONSE RECEIVED *****`);
console.groupCollapsed('Response');
console.log(JSON.stringify(clonedResponse, null, 2));
console.groupEnd();
} catch (err) {
console.error('Error printing search response:', err);
}
Expand Down
21 changes: 18 additions & 3 deletions test/search-backend/fulltext-search-backend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,18 @@ describe('FulltextSearchBackend', () => {
});

it('includes scope param from URL if not provided', async () => {
window.location.search = `?scope=boop`;
const url = new URL(window.location.href);
url.searchParams.set('scope', 'boop');
window.history.replaceState({}, '', url.toString());

const backend = new FulltextSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('scope')).to.equal('boop');

url.searchParams.delete('scope');
window.history.replaceState({}, '', url.toString());
});

it('includes caching param if provided', async () => {
Expand All @@ -98,13 +103,19 @@ describe('FulltextSearchBackend', () => {

it('includes caching param from URL if not provided', async () => {
const cachingParam = JSON.stringify({ bypass: true });
window.location.search = `?caching=${cachingParam}`;

const url = new URL(window.location.href);
url.searchParams.set('caching', cachingParam);
window.history.replaceState({}, '', url.toString());

const backend = new FulltextSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('caching')).to.equal(cachingParam);

url.searchParams.delete('caching');
window.history.replaceState({}, '', url.toString());
});

it('can enable debugging by default on all searches', async () => {
Expand Down Expand Up @@ -262,7 +273,9 @@ describe('FulltextSearchBackend', () => {
});

it('includes verbose param from URL if not provided', async () => {
window.location.search = `?verbose=1`;
const url = new URL(window.location.href);
url.searchParams.set('verbose', '1');
window.history.replaceState({}, '', url.toString());

const logBackup = console.log;
const logSpy = Sinon.spy();
Expand All @@ -275,5 +288,7 @@ describe('FulltextSearchBackend', () => {
expect(logSpy.args[0][0]).to.equal('\n\n***** RESPONSE RECEIVED *****');

console.log = logBackup;
url.searchParams.delete('verbose');
window.history.replaceState({}, '', url.toString());
});
});
21 changes: 18 additions & 3 deletions test/search-backend/metadata-search-backend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,18 @@ describe('MetadataSearchBackend', () => {
});

it('includes scope param from URL if not provided', async () => {
window.location.search = `?scope=boop`;
const url = new URL(window.location.href);
url.searchParams.set('scope', 'boop');
window.history.replaceState({}, '', url.toString());

const backend = new MetadataSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('scope')).to.equal('boop');

url.searchParams.delete('scope');
window.history.replaceState({}, '', url.toString());
});

it('includes caching param if provided', async () => {
Expand All @@ -98,13 +103,19 @@ describe('MetadataSearchBackend', () => {

it('includes caching param from URL if not provided', async () => {
const cachingParam = JSON.stringify({ bypass: true });
window.location.search = `?caching=${cachingParam}`;

const url = new URL(window.location.href);
url.searchParams.set('caching', cachingParam);
window.history.replaceState({}, '', url.toString());

const backend = new MetadataSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('caching')).to.equal(cachingParam);

url.searchParams.delete('caching');
window.history.replaceState({}, '', url.toString());
});

it('can enable debugging by default on all searches', async () => {
Expand Down Expand Up @@ -262,7 +273,9 @@ describe('MetadataSearchBackend', () => {
});

it('includes verbose param from URL if not provided', async () => {
window.location.search = `?verbose=1`;
const url = new URL(window.location.href);
url.searchParams.set('verbose', '1');
window.history.replaceState({}, '', url.toString());

const logBackup = console.log;
const logSpy = Sinon.spy();
Expand All @@ -275,5 +288,7 @@ describe('MetadataSearchBackend', () => {
expect(logSpy.args[0][0]).to.equal('\n\n***** RESPONSE RECEIVED *****');

console.log = logBackup;
url.searchParams.delete('verbose');
window.history.replaceState({}, '', url.toString());
});
});

0 comments on commit 7125c2e

Please sign in to comment.