Skip to content

Commit bdaee5d

Browse files
authored
refactor: remove contract test got dependency (#1188)
<!-- CURSOR_SUMMARY --> > [!NOTE] > **Low Risk** > Low risk because changes are limited to contract-test helpers and build/lint configuration; main risk is contract tests failing in environments without a compatible global `fetch` implementation. > > **Overview** > Contract-test HTTP calls now use `fetch` instead of `got`, including big segment store callbacks, migration endpoint invocations, and `registerFlagChangeListener` notifications, with basic `response.ok`/status error handling. > > Removes `got` from `contract-tests/package.json` and `@launchdarkly/js-contract-test-utils` peer/dev dependencies, and drops the `tsconfig.server.json` path alias that existed to make `got` resolvable under ESM. > > Adds a `server-node` `.eslintrc.cjs` override for `contract-tests/**/*.ts`, and adjusts `tsconfig.eslint.json` includes/excludes to avoid linting `dist` and `contract-tests` by default. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit b4396a9. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/launchdarkly/js-core/pull/1188" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end -->
1 parent 4525cdc commit bdaee5d

8 files changed

Lines changed: 63 additions & 52 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
overrides: [
3+
{
4+
files: ['contract-tests/**/*.ts'],
5+
parserOptions: {
6+
project: './contract-tests/tsconfig.json',
7+
},
8+
},
9+
],
10+
};

packages/sdk/server-node/contract-tests/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"@launchdarkly/js-contract-test-utils": "workspace:^",
1616
"@launchdarkly/node-server-sdk": "workspace:^",
1717
"body-parser": "^1.19.0",
18-
"express": "^4.17.1",
19-
"got": "14.4.7"
18+
"express": "^4.17.1"
2019
},
2120
"devDependencies": {
2221
"@types/body-parser": "^1.19.2",

packages/sdk/server-node/contract-tests/src/BigSegmentTestStore.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import got from 'got';
2-
31
interface BigSegmentMetadata {
42
lastUpToDate?: number;
53
}
@@ -20,19 +18,24 @@ export default class BigSegmentTestStore {
2018
}
2119

2220
async getMetadata(): Promise<BigSegmentMetadata> {
23-
const data = await got.get(`${this._callbackUri}/getMetadata`, { retry: { limit: 0 } }).json();
21+
const response = await fetch(`${this._callbackUri}/getMetadata`);
22+
if (!response.ok) {
23+
throw new Error(`getMetadata request failed with status ${response.status}`);
24+
}
25+
const data = await response.json();
2426
return data as BigSegmentMetadata;
2527
}
2628

2729
async getUserMembership(contextHash: string): Promise<Record<string, boolean> | undefined> {
28-
const data = await got
29-
.post(`${this._callbackUri}/getMembership`, {
30-
retry: { limit: 0 },
31-
json: {
32-
contextHash,
33-
},
34-
})
35-
.json();
30+
const response = await fetch(`${this._callbackUri}/getMembership`, {
31+
method: 'POST',
32+
headers: { 'Content-Type': 'application/json' },
33+
body: JSON.stringify({ contextHash }),
34+
});
35+
if (!response.ok) {
36+
throw new Error(`getUserMembership request failed with status ${response.status}`);
37+
}
38+
const data = await response.json();
3639
return (data as BigSegmentMembership)?.values;
3740
}
3841

packages/sdk/server-node/contract-tests/src/sdkClientEntity.ts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import got from 'got';
2-
31
import {
42
CommandParams,
53
CreateInstanceParams,
@@ -184,11 +182,11 @@ function getExecution(order: string) {
184182
}
185183
}
186184

187-
function makeMigrationPostOptions(payload: any) {
185+
function makeMigrationPostOptions(payload: any): RequestInit {
188186
if (payload) {
189-
return { body: payload };
187+
return { method: 'POST', body: payload };
190188
}
191-
return {};
189+
return { method: 'POST' };
192190
}
193191

194192
function contextOrUser(
@@ -342,44 +340,56 @@ export async function newSdkClientEntity(options: CreateInstanceParams): Promise
342340
check: migrationOperation.trackConsistency ? (a, b) => a === b : undefined,
343341
readNew: async (payload) => {
344342
try {
345-
const res = await got.post(
343+
const res = await fetch(
346344
migrationOperation.newEndpoint,
347345
makeMigrationPostOptions(payload),
348346
);
349-
return LDMigrationSuccess(res.body);
347+
if (!res.ok) {
348+
throw new Error(`HTTP ${res.status}`);
349+
}
350+
return LDMigrationSuccess(await res.text());
350351
} catch (err: any) {
351352
return LDMigrationError(err.message);
352353
}
353354
},
354355
writeNew: async (payload) => {
355356
try {
356-
const res = await got.post(
357+
const res = await fetch(
357358
migrationOperation.newEndpoint,
358359
makeMigrationPostOptions(payload),
359360
);
360-
return LDMigrationSuccess(res.body);
361+
if (!res.ok) {
362+
throw new Error(`HTTP ${res.status}`);
363+
}
364+
return LDMigrationSuccess(await res.text());
361365
} catch (err: any) {
362366
return LDMigrationError(err.message);
363367
}
364368
},
365369
readOld: async (payload) => {
366370
try {
367-
const res = await got.post(
371+
const res = await fetch(
368372
migrationOperation.oldEndpoint,
369373
makeMigrationPostOptions(payload),
370374
);
371-
return LDMigrationSuccess(res.body);
375+
if (!res.ok) {
376+
throw new Error(`HTTP ${res.status}`);
377+
}
378+
return LDMigrationSuccess(await res.text());
372379
} catch (err: any) {
373380
return LDMigrationError(err.message);
374381
}
375382
},
376383
writeOld: async (payload) => {
377384
try {
378-
const res = await got.post(
385+
const res = await fetch(
379386
migrationOperation.oldEndpoint,
380387
makeMigrationPostOptions(payload),
381388
);
382-
return LDMigrationSuccess(res.body);
389+
if (!res.ok) {
390+
throw new Error(`HTTP ${res.status}`);
391+
}
392+
return LDMigrationSuccess(await res.text());
383393
} catch (err: any) {
384394
return LDMigrationError(err.message);
385395
}
@@ -423,14 +433,11 @@ export async function newSdkClientEntity(options: CreateInstanceParams): Promise
423433
const eventName = 'update';
424434

425435
const handler = (eventParams: { key: string }) => {
426-
got
427-
.post(p.callbackUri, {
428-
json: {
429-
listenerId: p.listenerId,
430-
flagKey: eventParams.key,
431-
},
432-
})
433-
.catch(() => {});
436+
fetch(p.callbackUri, {
437+
method: 'POST',
438+
headers: { 'Content-Type': 'application/json' },
439+
body: JSON.stringify({ listenerId: p.listenerId, flagKey: eventParams.key }),
440+
}).catch(() => {});
434441
};
435442

436443
const existing = listeners.get(p.listenerId);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"extends": "./tsconfig.json",
3-
"include": ["/**/*.ts"],
4-
"exclude": ["node_modules"]
3+
"include": ["**/*.ts"],
4+
"exclude": ["node_modules", "dist", "contract-tests"]
55
}

packages/tooling/contract-test-utils/package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,20 @@
4040
},
4141
"peerDependencies": {
4242
"@launchdarkly/js-client-sdk-common": "workspace:^",
43-
"@launchdarkly/js-server-sdk-common": "workspace:^",
44-
"got": "14.4.7"
43+
"@launchdarkly/js-server-sdk-common": "workspace:^"
4544
},
4645
"peerDependenciesMeta": {
4746
"@launchdarkly/js-client-sdk-common": {
4847
"optional": true
4948
},
5049
"@launchdarkly/js-server-sdk-common": {
5150
"optional": true
52-
},
53-
"got": {
54-
"optional": true
5551
}
5652
},
5753
"devDependencies": {
54+
"@launchdarkly/js-client-sdk-common": "workspace:^",
55+
"@launchdarkly/js-server-sdk-common": "workspace:^",
5856
"@types/node": "^18.11.9",
59-
"got": "14.4.7",
6057
"typescript": "^4.9.0"
6158
}
6259
}

packages/tooling/contract-test-utils/src/server-side/TestHook.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import got from 'got';
21
import { integrations, LDEvaluationDetail } from '@launchdarkly/js-server-sdk-common';
32
import { BaseTestHook } from '../shared/BaseTestHook.js';
43

54
export default class TestHook extends BaseTestHook implements integrations.Hook {
65
protected async _safePost(body: unknown): Promise<void> {
76
try {
8-
await got.post(this._endpoint, { json: body });
7+
await fetch(this._endpoint, {
8+
method: 'POST',
9+
headers: { 'Content-Type': 'application/json' },
10+
body: JSON.stringify(body),
11+
});
912
} catch {
1013
// The test could move on before the post, so we are ignoring
1114
// failed posts.
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
{
22
"extends": "./tsconfig.json",
3-
"compilerOptions": {
4-
// 'got' is a devDependency; this path alias is needed because TypeScript's
5-
// 'node' moduleResolution does not follow exports maps for ESM-only packages.
6-
"baseUrl": ".",
7-
"paths": {
8-
"got": ["../../../node_modules/got/dist/source"]
9-
}
10-
},
113
"include": ["src/**/*"],
124
"exclude": ["dist", "node_modules", "src/client.ts", "src/client-side/**"]
135
}

0 commit comments

Comments
 (0)