import-url-importer.test.mjs
43 lines 1.4 KB
Raw
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 20 hours ago
1 /**
2 * URL importer integration (network: example.com).
3 * Skips when example.com is not resolvable (offline/sandbox) so `npm test` is reliable without network.
4 * CI and normal dev (with DNS) run the test.
5 */
6 import { describe, it } from 'node:test';
7 import assert from 'node:assert/strict';
8 import fs from 'fs';
9 import os from 'os';
10 import path from 'path';
11 import dns from 'node:dns/promises';
12 import { importUrl } from '../lib/importers/url.mjs';
13
14 let importUrlNetworkSkipReason;
15 try {
16 await dns.lookup('example.com');
17 importUrlNetworkSkipReason = false;
18 } catch (e) {
19 const msg = e && e.message ? String(e.message) : String(e);
20 importUrlNetworkSkipReason =
21 'example.com DNS not available (' + msg + '); set network access or use CI to run this integration test.';
22 }
23
24 describe('importUrl', () => {
25 it('dryRun fetches https://example.com with auto mode', { skip: importUrlNetworkSkipReason }, async () => {
26 const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kn-url-dry-'));
27 try {
28 const result = await importUrl('https://example.com/', {
29 vaultPath: dir,
30 outputBase: 'inbox',
31 project: null,
32 tags: [],
33 dryRun: true,
34 urlMode: 'auto',
35 });
36 assert.equal(result.count, 1);
37 assert.ok(result.imported[0].path.includes('imports/url/'));
38 assert.ok(result.imported[0].source_id);
39 } finally {
40 fs.rmSync(dir, { recursive: true, force: true });
41 }
42 });
43 });
File History 1 commit
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 20 hours ago