search-web-api 1.0.169 → 1.0.170

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -308,3 +308,27 @@ app/
308
308
  │ └── engine-descriptions.ts
309
309
  └── index.ts # Main entry point
310
310
  ```
311
+
312
+ ## Testing
313
+
314
+ ```bash
315
+ bun run test # the suites CI gates on — no network
316
+ bun run test:coverage # the same, with coverage (writes coverage/lcov.info)
317
+ bun run test:live # adds the suites that call the real search engines
318
+ ```
319
+
320
+ `bun run test` runs only deterministic suites: `test/sources-unit.test.ts`
321
+ exercises every engine against mocked responses, and
322
+ `src/search/__tests__/public-searxng.test.ts` covers the SearXNG client.
323
+
324
+ `test/api.test.ts`, `test/search.test.ts`, `test/sources.test.ts`,
325
+ `test/engine-health-suite.test.ts` and `test/autocomplete-ai.test.ts` really do
326
+ query the upstream engines, so whether they pass depends on third-party
327
+ availability and on whether an engine feels like rate-limiting your IP. They
328
+ are excluded unless `RUN_LIVE_TESTS=1` is set — which is what `test:live` does
329
+ — and they are the right thing to run by hand when you change an engine, since
330
+ a mock only proves the parser still matches the fixture.
331
+
332
+ `examples/autocomplete-engines.ts` (`bun run example:autocomplete`) prints what
333
+ each autocomplete backend answers. It asserts nothing, so it is an example
334
+ rather than a suite.
@@ -3,6 +3,10 @@
3
3
  *
4
4
  * Demonstrates how to use the autocomplete functionality
5
5
  * to get search query suggestions from various search engines.
6
+ *
7
+ * Run it with `bun run example:autocomplete`. It calls the live engines and
8
+ * prints what they answer; it asserts nothing, which is why it lives here and
9
+ * not in `test/` — Vitest fails a `*.test.ts` file that declares no suite.
6
10
  */
7
11
 
8
12
  import {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "search-web-api",
3
3
  "description": "70+ search engines across 10 categories and Scrape Extract API",
4
4
  "type": "module",
5
- "version": "1.0.169",
5
+ "version": "1.0.170",
6
6
  "author": "vtempest",
7
7
  "license": "rights.institute/PROSPER",
8
8
  "repository": {
@@ -26,7 +26,9 @@
26
26
  "dev": "bun --watch demo/index.ts",
27
27
  "start": "bun demo/index.ts",
28
28
  "test": "vitest run",
29
- "test:coverage": "vitest run --coverage"
29
+ "test:live": "RUN_LIVE_TESTS=1 vitest run",
30
+ "test:coverage": "vitest run --coverage",
31
+ "example:autocomplete": "bun examples/autocomplete-engines.ts"
30
32
  },
31
33
  "dependencies": {
32
34
  "@huggingface/transformers": "^4.2.0",
@@ -606,7 +606,10 @@ function getMockForUrl(url: string, options?: RequestInit): Response {
606
606
  if (u.includes("google.com/search") && !u.includes("tbm=isch") && !u.includes("news.google.com")) return makeMockResponse({ html: GOOGLE_HTML });
607
607
  if (u.includes("bing.com/search")) return makeMockResponse({ html: BING_HTML });
608
608
  if (u.includes("duckduckgo.com/html")) return makeMockResponse({ html: DUCKDUCKGO_HTML });
609
- if (u.includes("search.yahoo.com/search")) return makeMockResponse({ html: YAHOO_HTML });
609
+ // `news.search.yahoo.com` ends in this host, so the news engine would be
610
+ // served the general-search page and parse nothing out of it — the same
611
+ // trap the `news.google.com` guard above sidesteps.
612
+ if (u.includes("search.yahoo.com/search") && !u.includes("news.search.yahoo.com")) return makeMockResponse({ html: YAHOO_HTML });
610
613
  if (u.includes("api.qwant.com")) return makeMockResponse({ json: { data: { result: { items: [{ url: "https://example.com", title: "Qwant Title", desc: "Qwant description." }] } } } });
611
614
  if (u.includes("startpage.com/sp/search")) return makeMockResponse({ html: STARTPAGE_HTML });
612
615
  if (u.includes("search.brave.com")) return makeMockResponse({ html: BRAVE_HTML });
package/vitest.config.ts CHANGED
@@ -1,15 +1,37 @@
1
- import { defineConfig } from 'vitest/config';
1
+ import { defineConfig, configDefaults } from 'vitest/config';
2
+
3
+ /**
4
+ * Suites that call the real search engines over the network. Whether they pass
5
+ * is decided by third-party availability and by whether the engine feels like
6
+ * rate-limiting the runner's IP that minute, so they are opt-in
7
+ * (`bun run test:live`) instead of gating every push. `test/sources-unit.test.ts`
8
+ * covers the same engines against mocked responses and does gate CI.
9
+ */
10
+ const LIVE_NETWORK_SUITES = [
11
+ 'test/api.test.ts',
12
+ 'test/autocomplete-ai.test.ts',
13
+ 'test/engine-health-suite.test.ts',
14
+ 'test/search.test.ts',
15
+ 'test/sources.test.ts'
16
+ ];
17
+
18
+ const includeLive = process.env.RUN_LIVE_TESTS === '1';
2
19
 
3
20
  export default defineConfig({
4
21
  test: {
5
22
  globals: true,
6
23
  environment: 'node',
24
+ exclude: [
25
+ ...configDefaults.exclude,
26
+ ...(includeLive ? [] : LIVE_NETWORK_SUITES)
27
+ ],
7
28
  coverage: {
8
29
  provider: 'v8',
9
- reporter: ['text', 'json', 'html'],
30
+ reporter: ['text', 'json', 'html', 'lcov'],
10
31
  exclude: [
11
32
  'node_modules/**',
12
33
  'dist/**',
34
+ 'examples/**',
13
35
  '**/*.test.ts',
14
36
  '**/__tests__/**'
15
37
  ]