blob: f25c95b65f48b45da26ddc4fa1c2fec34650c943 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package js_test
import (
"io"
"net/http"
"testing"
"flyscrape/flyscrape"
"flyscrape/js"
"github.com/stretchr/testify/require"
)
func TestV8(t *testing.T) {
opts, run, err := js.Compile("../examples/esbuild.github.io.js")
require.NoError(t, err)
require.NotNil(t, opts)
require.NotNil(t, run)
html := fetch(opts.URL)
json, err := run(flyscrape.ScrapeParams{
HTML: html,
})
require.NoError(t, err)
t.Log(json)
}
func fetch(url string) string {
resp, err := http.Get(url)
if err != nil {
return ""
}
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
if err != nil {
return ""
}
return string(b)
}
|