From 40e02d5d28e59dbeb6134afdce12536c602e6aa5 Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Fri, 10 Jan 2025 13:09:50 +0100 Subject: Implement manual following (#82) --- js_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'js_test.go') diff --git a/js_test.go b/js_test.go index 4b08720..1141f9c 100644 --- a/js_test.go +++ b/js_test.go @@ -260,6 +260,27 @@ func TestJSScrapeParamScrapeDeep(t *testing.T) { }, result) } +func TestJSScrapeParamFollow(t *testing.T) { + js := ` + export default function({ follow }) { + follow("/foo") + } + ` + exports, err := flyscrape.Compile(js, nil) + require.NoError(t, err) + + var followedURL string + _, err = exports.Scrape(flyscrape.ScrapeParams{ + HTML: html, + URL: "http://localhost/", + Follow: func(url string) { + followedURL = url + }, + }) + require.NoError(t, err) + require.Equal(t, "http://localhost/foo", followedURL) +} + func TestJSCompileError(t *testing.T) { exports, err := flyscrape.Compile("import foo;", nil) require.Error(t, err) -- cgit v1.2.3