It was a dark and stormy night.
The hero stepped forward.
package novelfire import ( "context" "strings" "testing" "github.com/libnovel/scraper/internal/browser" "github.com/libnovel/scraper/internal/scraper" ) // ── stub browser client ─────────────────────────────────────────────────────── // stubClient is a BrowserClient that returns a fixed HTML string for every // GetContent call. ScrapePage and CDPSession are not used by these tests. type stubClient struct { html string } func (s *stubClient) Strategy() browser.Strategy { return browser.StrategyContent } func (s *stubClient) GetContent(_ context.Context, _ browser.ContentRequest) (string, error) { return s.html, nil } func (s *stubClient) ScrapePage(_ context.Context, _ browser.ScrapeRequest) (browser.ScrapeResponse, error) { return browser.ScrapeResponse{}, nil } func (s *stubClient) CDPSession(_ context.Context, _ string, _ browser.CDPSessionFunc) error { return nil } // pagedStubClient returns a different HTML response for each successive call. // Once all pages are exhausted it returns an empty page (no chapter-list), // simulating the paginated chapter-list endpoint terminating correctly. type pagedStubClient struct { pages []string call int } func (c *pagedStubClient) Strategy() browser.Strategy { return browser.StrategyContent } func (c *pagedStubClient) GetContent(_ context.Context, _ browser.ContentRequest) (string, error) { if c.call < len(c.pages) { html := c.pages[c.call] c.call++ return html, nil } // Past the last page — return a page with no chapter-list to stop pagination. return `
`, nil } func (c *pagedStubClient) ScrapePage(_ context.Context, _ browser.ScrapeRequest) (browser.ScrapeResponse, error) { return browser.ScrapeResponse{}, nil } func (c *pagedStubClient) CDPSession(_ context.Context, _ string, _ browser.CDPSessionFunc) error { return nil } // ── helpers ─────────────────────────────────────────────────────────────────── func newScraper(html string) *Scraper { return New(&stubClient{html: html}, nil, &stubClient{html: html}) } func newPagedScraper(pages ...string) *Scraper { urlClient := &pagedStubClient{pages: pages} return New(&stubClient{}, nil, urlClient) } // ── ScrapeChapterText ───────────────────────────────────────────────────────── func TestScrapeChapterText_ExtractsInnerText(t *testing.T) { html := `It was a dark and stormy night.
The hero stepped forward.