summaryrefslogtreecommitdiff
path: root/js_test.go
diff options
context:
space:
mode:
authorPhilipp Tanlak <philipp.tanlak@gmail.com>2025-01-10 13:09:50 +0100
committerGitHub <noreply@github.com>2025-01-10 13:09:50 +0100
commit40e02d5d28e59dbeb6134afdce12536c602e6aa5 (patch)
tree24c84c4084cf72e552804397eecc9f5bb3c2d4be /js_test.go
parentbf99c233a18c3165e0d4d251b41224e5bc6eb93d (diff)
Implement manual following (#82)
Diffstat (limited to 'js_test.go')
-rw-r--r--js_test.go21
1 files changed, 21 insertions, 0 deletions
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)