d2974a9ff6
* refactor(adapters): convert adapter layer from TypeScript to JavaScript Core framework stays TypeScript; adapter layer moves to JS-first. Adapters are essentially "executable config + browser scripts" that barely use TS features — this simplifies the build/distribution pipeline by removing the dist/clis/ intermediate compilation step. Changes: - Convert all 753 adapter files in clis/ from .ts to .js - Update tsconfig to exclude clis/ from compilation - Simplify build-manifest to scan clis/*.js directly (no dist/clis/) - Update discovery, main, fetch-adapters to load JS adapters from clis/ - Update generate-verified to output .js artifacts - Update package.json files field: dist/clis/ → clis/ - Fix all test files for the .ts → .js transition * fix(main): use findPackageRoot for BUILTIN_CLIS path The previous relative path (../../clis from __dirname) only worked for dist/src/main.js but broke dev mode (tsx src/main.ts) where __dirname is <repo>/src — resolving to /clis instead of <repo>/clis. Use findPackageRoot() which works for both dev and prod paths.
45 lines
2.0 KiB
JavaScript
45 lines
2.0 KiB
JavaScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { __test__, loadSubstackArchive, loadSubstackFeed } from './utils.js';
|
|
function createPageMock(evaluateResult) {
|
|
return {
|
|
goto: vi.fn().mockResolvedValue(undefined),
|
|
evaluate: vi.fn().mockResolvedValue(evaluateResult),
|
|
snapshot: vi.fn().mockResolvedValue(undefined),
|
|
click: vi.fn().mockResolvedValue(undefined),
|
|
typeText: vi.fn().mockResolvedValue(undefined),
|
|
pressKey: vi.fn().mockResolvedValue(undefined),
|
|
scrollTo: vi.fn().mockResolvedValue(undefined),
|
|
getFormState: vi.fn().mockResolvedValue({}),
|
|
wait: vi.fn().mockResolvedValue(undefined),
|
|
tabs: vi.fn().mockResolvedValue([]),
|
|
selectTab: vi.fn().mockResolvedValue(undefined),
|
|
networkRequests: vi.fn().mockResolvedValue([]),
|
|
consoleMessages: vi.fn().mockResolvedValue([]),
|
|
scroll: vi.fn().mockResolvedValue(undefined),
|
|
autoScroll: vi.fn().mockResolvedValue(undefined),
|
|
installInterceptor: vi.fn().mockResolvedValue(undefined),
|
|
getInterceptedRequests: vi.fn().mockResolvedValue([]),
|
|
getCookies: vi.fn().mockResolvedValue([]),
|
|
screenshot: vi.fn().mockResolvedValue(''),
|
|
waitForCapture: vi.fn().mockResolvedValue(undefined),
|
|
};
|
|
}
|
|
describe('substack utils wait selectors', () => {
|
|
it('waits for both feed link shapes before scraping the feed', async () => {
|
|
const page = createPageMock([]);
|
|
await loadSubstackFeed(page, 'https://substack.com/', 5);
|
|
expect(page.wait).toHaveBeenCalledWith({
|
|
selector: __test__.FEED_POST_LINK_SELECTOR,
|
|
timeout: 5,
|
|
});
|
|
});
|
|
it('waits for archive post links before scraping archive pages', async () => {
|
|
const page = createPageMock([]);
|
|
await loadSubstackArchive(page, 'https://example.substack.com', 5);
|
|
expect(page.wait).toHaveBeenCalledWith({
|
|
selector: __test__.ARCHIVE_POST_LINK_SELECTOR,
|
|
timeout: 5,
|
|
});
|
|
});
|
|
});
|