Skip to content

Commit ff2372c

Browse files
feat(javascript): add requester-testing package (#3684) (generated) [skip ci]
Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 52e1b57 commit ff2372c

36 files changed

+146
-143
lines changed

clients/algoliasearch-client-javascript/packages/algoliasearch/package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"scripts": {
1111
"build": "yarn clean && yarn tsup && yarn rollup -c rollup.config.js",
1212
"clean": "rm -rf ./dist || true",
13-
"test": "jest",
13+
"test": "vitest --run",
1414
"test:bundle": "publint . && attw --pack ."
1515
},
1616
"name": "algoliasearch",
@@ -80,17 +80,16 @@
8080
"@algolia/requester-node-http": "5.3.2"
8181
},
8282
"devDependencies": {
83+
"@algolia/requester-testing": "0.0.0",
8384
"@arethetypeswrong/cli": "0.15.4",
84-
"@babel/preset-env": "7.25.4",
85-
"@babel/preset-typescript": "7.24.7",
86-
"@types/jest": "29.5.12",
8785
"@types/node": "22.5.1",
88-
"jest": "29.7.0",
89-
"jest-environment-miniflare": "2.14.3",
86+
"jsdom": "25.0.0",
9087
"publint": "0.2.10",
9188
"rollup": "4.21.2",
9289
"tsup": "8.2.4",
93-
"typescript": "5.5.4"
90+
"typescript": "5.5.4",
91+
"vitest": "2.0.5",
92+
"vitest-environment-miniflare": "2.14.3"
9493
},
9594
"engines": {
9695
"node": ">= 14.0.0"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4-
"types": ["node", "jest"],
4+
"types": ["node", "@cloudflare/workers-types", "vitest-environment-miniflare/globals", "vitest/globals"],
55
"outDir": "dist"
66
},
77
"include": ["src", "model", "builds"],
88
"exclude": ["dist", "node_modules"]
9-
}
9+
}

clients/algoliasearch-client-javascript/packages/algoliasearch/vitest.workspace.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@ export default defineWorkspace([
55
{
66
resolve: {
77
alias: {
8-
'@algolia/client-search': '../../client-search/builds/node'
9-
}
8+
'@algolia/client-search': '../../client-search/builds/node',
9+
},
1010
},
1111
test: {
12-
include: [ '__tests__/algoliasearch.node.test.ts' ],
12+
include: ['__tests__/algoliasearch.node.test.ts'],
1313
name: 'node',
1414
environment: 'node',
1515
},
1616
},
1717
{
1818
resolve: {
1919
alias: {
20-
'@algolia/client-search': '../../client-search/builds/browser'
21-
}
20+
'@algolia/client-search': '../../client-search/builds/browser',
21+
},
2222
},
2323
test: {
24-
include: [ '__tests__/algoliasearch.browser.test.ts', '__tests__/algoliasearch.common.test.ts' ],
24+
include: ['__tests__/algoliasearch.browser.test.ts', '__tests__/algoliasearch.common.test.ts'],
2525
name: 'jsdom',
2626
environment: 'jsdom',
2727
},
2828
},
2929
{
3030
resolve: {
3131
alias: {
32-
'@algolia/client-search': '../../client-search/builds/fetch'
33-
}
32+
'@algolia/client-search': '../../client-search/builds/fetch',
33+
},
3434
},
3535
test: {
36-
include: [ '__tests__/algoliasearch.fetch.test.ts' ],
36+
include: ['__tests__/algoliasearch.fetch.test.ts'],
3737
name: 'miniflare',
3838
environment: 'miniflare',
3939
},

clients/algoliasearch-client-javascript/packages/client-abtesting/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
},
66
"include": ["src", "model", "builds"],
77
"exclude": ["dist", "node_modules"]
8-
}
8+
}

clients/algoliasearch-client-javascript/packages/client-analytics/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
},
66
"include": ["src", "model", "builds"],
77
"exclude": ["dist", "node_modules"]
8-
}
8+
}

clients/algoliasearch-client-javascript/packages/client-insights/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
},
66
"include": ["src", "model", "builds"],
77
"exclude": ["dist", "node_modules"]
8-
}
8+
}

clients/algoliasearch-client-javascript/packages/client-personalization/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
},
66
"include": ["src", "model", "builds"],
77
"exclude": ["dist", "node_modules"]
8-
}
8+
}

clients/algoliasearch-client-javascript/packages/client-query-suggestions/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
},
66
"include": ["src", "model", "builds"],
77
"exclude": ["dist", "node_modules"]
8-
}
8+
}

clients/algoliasearch-client-javascript/packages/client-search/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
},
66
"include": ["src", "model", "builds"],
77
"exclude": ["dist", "node_modules"]
8-
}
8+
}

clients/algoliasearch-client-javascript/packages/client-usage/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
},
66
"include": ["src", "model", "builds"],
77
"exclude": ["dist", "node_modules"]
8-
}
8+
}

clients/algoliasearch-client-javascript/packages/ingestion/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
},
66
"include": ["src", "model", "builds"],
77
"exclude": ["dist", "node_modules"]
8-
}
8+
}

clients/algoliasearch-client-javascript/packages/monitoring/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
},
66
"include": ["src", "model", "builds"],
77
"exclude": ["dist", "node_modules"]
8-
}
8+
}

clients/algoliasearch-client-javascript/packages/recommend/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
},
66
"include": ["src", "model", "builds"],
77
"exclude": ["dist", "node_modules"]
8-
}
8+
}

tests/output/javascript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@algolia/ingestion": "link:../../../clients/algoliasearch-client-javascript/packages/ingestion",
1717
"@algolia/monitoring": "link:../../../clients/algoliasearch-client-javascript/packages/monitoring",
1818
"@algolia/recommend": "link:../../../clients/algoliasearch-client-javascript/packages/recommend",
19-
"@algolia/requester-node-http": "link:../../../clients/algoliasearch-client-javascript/packages/requester-node-http",
19+
"@algolia/requester-testing": "link:../../../clients/algoliasearch-client-javascript/packages/requester-testing",
2020
"algoliasearch": "link:../../../clients/algoliasearch-client-javascript/packages/algoliasearch"
2121
},
2222
"devDependencies": {

tests/output/javascript/src/benchmark/search.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const appId = 'test-app-id';
88
const apiKey = 'test-api-key';
99

1010
function createClient(): SearchClient {
11-
return searchClient(appId, apiKey, { requester: echoRequester() });
11+
return searchClient(appId, apiKey, { requester: nodeEchoRequester() });
1212
}
1313

1414
describe('benchmark', () => {

tests/output/javascript/src/client/abtesting.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
// @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines.
44
import type { AbtestingClient } from '@algolia/client-abtesting';
55
import { abtestingClient } from '@algolia/client-abtesting';
6-
import { echoRequester } from '@algolia/requester-node-http';
7-
import type { EchoResponse } from '@algolia/requester-node-http';
6+
import { nodeEchoRequester } from '@algolia/requester-testing';
7+
import type { EchoResponse } from '@algolia/requester-testing';
88

99
const appId = 'test-app-id';
1010
const apiKey = 'test-api-key';
1111

1212
function createClient(): AbtestingClient {
13-
return abtestingClient(appId, apiKey, 'us', { requester: echoRequester() });
13+
return abtestingClient(appId, apiKey, 'us', { requester: nodeEchoRequester() });
1414
}
1515

1616
describe('commonApi', () => {
@@ -51,15 +51,15 @@ describe('commonApi', () => {
5151

5252
describe('parameters', () => {
5353
test('fallbacks to the alias when region is not given', async () => {
54-
const client = abtestingClient('my-app-id', 'my-api-key', '', { requester: echoRequester() });
54+
const client = abtestingClient('my-app-id', 'my-api-key', '', { requester: nodeEchoRequester() });
5555

5656
const result = (await client.getABTest({ id: 123 })) as unknown as EchoResponse;
5757

5858
expect(result.host).toEqual('analytics.algolia.com');
5959
}, 15000);
6060

6161
test('uses the correct region', async () => {
62-
const client = abtestingClient('my-app-id', 'my-api-key', 'us', { requester: echoRequester() });
62+
const client = abtestingClient('my-app-id', 'my-api-key', 'us', { requester: nodeEchoRequester() });
6363

6464
const result = (await client.getABTest({ id: 123 })) as unknown as EchoResponse;
6565

@@ -68,7 +68,7 @@ describe('parameters', () => {
6868

6969
test('throws when incorrect region is given', async () => {
7070
try {
71-
const client = abtestingClient('my-app-id', 'my-api-key', 'not_a_region', { requester: echoRequester() });
71+
const client = abtestingClient('my-app-id', 'my-api-key', 'not_a_region', { requester: nodeEchoRequester() });
7272
throw new Error('test is expected to throw error');
7373
} catch (e) {
7474
expect((e as Error).message).toMatch('`region` must be one of the following: de, us');
@@ -102,11 +102,11 @@ describe('init', () => {
102102
test('sets authMode', async () => {
103103
const qpClient = abtestingClient('foo', 'bar', 'us', {
104104
authMode: 'WithinQueryParameters',
105-
requester: echoRequester(),
105+
requester: nodeEchoRequester(),
106106
});
107107
const headerClient = abtestingClient('foo', 'bar', 'us', {
108108
authMode: 'WithinHeaders',
109-
requester: echoRequester(),
109+
requester: nodeEchoRequester(),
110110
});
111111

112112
const qpResult = (await qpClient.customGet({

tests/output/javascript/src/client/analytics.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
// @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines.
44
import type { AnalyticsClient } from '@algolia/client-analytics';
55
import { analyticsClient } from '@algolia/client-analytics';
6-
import { echoRequester } from '@algolia/requester-node-http';
7-
import type { EchoResponse } from '@algolia/requester-node-http';
6+
import { nodeEchoRequester } from '@algolia/requester-testing';
7+
import type { EchoResponse } from '@algolia/requester-testing';
88

99
const appId = 'test-app-id';
1010
const apiKey = 'test-api-key';
1111

1212
function createClient(): AnalyticsClient {
13-
return analyticsClient(appId, apiKey, 'us', { requester: echoRequester() });
13+
return analyticsClient(appId, apiKey, 'us', { requester: nodeEchoRequester() });
1414
}
1515

1616
describe('commonApi', () => {
@@ -51,15 +51,15 @@ describe('commonApi', () => {
5151

5252
describe('parameters', () => {
5353
test('fallbacks to the alias when region is not given', async () => {
54-
const client = analyticsClient('my-app-id', 'my-api-key', '', { requester: echoRequester() });
54+
const client = analyticsClient('my-app-id', 'my-api-key', '', { requester: nodeEchoRequester() });
5555

5656
const result = (await client.getAverageClickPosition({ index: 'my-index' })) as unknown as EchoResponse;
5757

5858
expect(result.host).toEqual('analytics.algolia.com');
5959
}, 15000);
6060

6161
test('uses the correct region', async () => {
62-
const client = analyticsClient('my-app-id', 'my-api-key', 'de', { requester: echoRequester() });
62+
const client = analyticsClient('my-app-id', 'my-api-key', 'de', { requester: nodeEchoRequester() });
6363

6464
const result = (await client.customPost({ path: 'test' })) as unknown as EchoResponse;
6565

@@ -68,7 +68,7 @@ describe('parameters', () => {
6868

6969
test('throws when incorrect region is given', async () => {
7070
try {
71-
const client = analyticsClient('my-app-id', 'my-api-key', 'not_a_region', { requester: echoRequester() });
71+
const client = analyticsClient('my-app-id', 'my-api-key', 'not_a_region', { requester: nodeEchoRequester() });
7272
throw new Error('test is expected to throw error');
7373
} catch (e) {
7474
expect((e as Error).message).toMatch('`region` must be one of the following: de, us');
@@ -113,11 +113,11 @@ describe('init', () => {
113113
test('sets authMode', async () => {
114114
const qpClient = analyticsClient('foo', 'bar', 'us', {
115115
authMode: 'WithinQueryParameters',
116-
requester: echoRequester(),
116+
requester: nodeEchoRequester(),
117117
});
118118
const headerClient = analyticsClient('foo', 'bar', 'us', {
119119
authMode: 'WithinHeaders',
120-
requester: echoRequester(),
120+
requester: nodeEchoRequester(),
121121
});
122122

123123
const qpResult = (await qpClient.customGet({

tests/output/javascript/src/client/ingestion.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
// @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines.
44
import type { IngestionClient } from '@algolia/ingestion';
55
import { ingestionClient } from '@algolia/ingestion';
6-
import { echoRequester } from '@algolia/requester-node-http';
7-
import type { EchoResponse } from '@algolia/requester-node-http';
6+
import { nodeEchoRequester } from '@algolia/requester-testing';
7+
import type { EchoResponse } from '@algolia/requester-testing';
88

99
const appId = 'test-app-id';
1010
const apiKey = 'test-api-key';
1111

1212
function createClient(): IngestionClient {
13-
return ingestionClient(appId, apiKey, 'us', { requester: echoRequester() });
13+
return ingestionClient(appId, apiKey, 'us', { requester: nodeEchoRequester() });
1414
}
1515

1616
describe('commonApi', () => {
@@ -51,7 +51,7 @@ describe('commonApi', () => {
5151

5252
describe('parameters', () => {
5353
test('uses the correct region', async () => {
54-
const client = ingestionClient('my-app-id', 'my-api-key', 'us', { requester: echoRequester() });
54+
const client = ingestionClient('my-app-id', 'my-api-key', 'us', { requester: nodeEchoRequester() });
5555

5656
const result = (await client.getSource({
5757
sourceID: '6c02aeb1-775e-418e-870b-1faccd4b2c0f',
@@ -62,7 +62,7 @@ describe('parameters', () => {
6262

6363
test('throws when incorrect region is given', async () => {
6464
try {
65-
const client = ingestionClient('my-app-id', 'my-api-key', 'not_a_region', { requester: echoRequester() });
65+
const client = ingestionClient('my-app-id', 'my-api-key', 'not_a_region', { requester: nodeEchoRequester() });
6666
throw new Error('test is expected to throw error');
6767
} catch (e) {
6868
expect((e as Error).message).toMatch('`region` is required and must be one of the following: eu, us');
@@ -96,11 +96,11 @@ describe('init', () => {
9696
test('sets authMode', async () => {
9797
const qpClient = ingestionClient('foo', 'bar', 'us', {
9898
authMode: 'WithinQueryParameters',
99-
requester: echoRequester(),
99+
requester: nodeEchoRequester(),
100100
});
101101
const headerClient = ingestionClient('foo', 'bar', 'us', {
102102
authMode: 'WithinHeaders',
103-
requester: echoRequester(),
103+
requester: nodeEchoRequester(),
104104
});
105105

106106
const qpResult = (await qpClient.customGet({

0 commit comments

Comments
 (0)