Skip to content

Commit

Permalink
ci(headless): remove web-encoding dependency (#3134)
Browse files Browse the repository at this point in the history
* Remove web-encoding dependency

https://coveord.atlassian.net/browse/KIT-2675

* Add decoder polyfill export

https://coveord.atlassian.net/browse/KIT-2675

* Replace web-encoding with x-global

https://coveord.atlassian.net/browse/KIT-2675

* Remove all text decoding 🎉

https://coveord.atlassian.net/browse/KIT-2675

* Remove irrelevant decoding UTs

https://coveord.atlassian.net/browse/KIT-2675
  • Loading branch information
dmbrooke authored Aug 30, 2023
1 parent 402473f commit 6cc58b5
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 131 deletions.
30 changes: 6 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/headless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
"pino": "8.11.0",
"redux-mock-store": "1.5.4",
"redux-thunk": "2.4.1",
"ts-debounce": "3.0.0",
"web-encoding": "^1.1.4"
"ts-debounce": "3.0.0"
},
"devDependencies": {
"@microsoft/api-extractor": "7.29.3",
Expand Down
23 changes: 0 additions & 23 deletions packages/headless/src/api/search/encoding-finder.test.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/headless/src/api/search/encoding-finder.ts

This file was deleted.

7 changes: 1 addition & 6 deletions packages/headless/src/api/search/html/html-api-client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {Logger} from 'pino';
import {TextDecoder} from 'web-encoding';
import {URLPath} from '../../../utils/url-utils';
import {pickNonBaseParams, unwrapError} from '../../api-client-utils';
import {PlatformClient} from '../../platform-client';
import {PreprocessRequest, RequestMetadata} from '../../preprocess-request';
import {findEncoding} from '../encoding-finder';
import {SearchAPIErrorWithStatusCode} from '../search-api-error-response';
import {baseSearchRequest} from '../search-api-params';
import {HtmlRequest} from './html-request';
Expand Down Expand Up @@ -68,10 +66,7 @@ export const getHtml = async (
throw response;
}

const encoding = findEncoding(response);
const buffer = await response.arrayBuffer();
const decoder = new TextDecoder(encoding);
const body = decoder.decode(buffer);
const body = await response.text();

if (isSuccessHtmlResponse(body)) {
return {success: body};
Expand Down
23 changes: 0 additions & 23 deletions packages/headless/src/api/search/search-api-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,29 +648,6 @@ describe('search api client', () => {
});

describe('SearchAPIClient.html', () => {
function encodeUTF16(str: string) {
const buf = new ArrayBuffer(str.length * 2);
const bufView = new Uint16Array(buf);

for (let i = 0, strLen = str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}

return bufView;
}

it('when the response is UTF-16 encoded, it decodes the response correctly', async () => {
const payload = encodeUTF16('hello');
const headers = {'content-type': 'text/html; charset=UTF-16'};
const response = new Response(payload, {headers});
PlatformClient.call = () => Promise.resolve(response);

const req = await buildResultPreviewRequest(state, {uniqueId: '1'});
const res = await searchAPIClient.html(req);

expect(res.success).toBe('hello');
});

it('when calling SearchAPIClient.html should call PlatformClient.call with the right options', async () => {
const req = await buildResultPreviewRequest(state, {uniqueId: '1'});
searchAPIClient.html(req);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import {Response} from 'cross-fetch';
import {buildResultPreviewRequest} from '../../../features/result-preview/result-preview-request-builder';
import {createMockState} from '../../../test';
import {buildMockCaseAssistAPIClient} from '../../../test/mock-case-assist-api-client';
import {PlatformClient} from '../../platform-client';
import {CaseAssistAPIClient} from './case-assist-api-client';
Expand Down Expand Up @@ -273,30 +270,4 @@ describe('case assist api client', () => {
});
});
});

describe('caseAssistAPIClient.html', () => {
function encodeUTF16(str: string) {
const buf = new ArrayBuffer(str.length * 2);
const bufView = new Uint16Array(buf);

for (let i = 0, strLen = str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}

return bufView;
}

it('when the response is UTF-16 encoded, it decodes the response correctly', async () => {
const state = createMockState();
const payload = encodeUTF16('hello');
const headers = {'content-type': 'text/html; charset=UTF-16'};
const response = new Response(payload, {headers});
PlatformClient.call = () => Promise.resolve(response);

const req = await buildResultPreviewRequest(state, {uniqueId: '1'});
const res = await client.html(req);

expect(res.success).toBe('hello');
});
});
});
15 changes: 0 additions & 15 deletions packages/samples/headless-react/jest.setup.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/samples/headless-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"build": "npm run build:client && npm run build:server",
"build:client": "tsc --noEmit && tsc --module commonjs --noEmit",
"build:server": "tsc --project ./tsconfig.server.json",
"test": "react-scripts test --env=./jest.setup.js",
"test": "react-scripts test",
"prod:ssr": "node ./build/server/server/server.js"
},
"browserslist": {
Expand Down

0 comments on commit 6cc58b5

Please sign in to comment.