diff options
| author | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-08-11 18:31:20 +0200 |
|---|---|---|
| committer | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-08-11 18:31:20 +0200 |
| commit | 062b36fe5725d1267c66db2e506b4131d78ce772 (patch) | |
| tree | 998e5260feb1babac8dae512b56d67d8f20f7266 /js_test.go | |
| parent | 7e4cf39a0ba6ccbd5cc036700a8b1ff9358ecc3d (diff) | |
simplify project structure
Diffstat (limited to 'js_test.go')
| -rw-r--r-- | js_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/js_test.go b/js_test.go new file mode 100644 index 0000000..34c4183 --- /dev/null +++ b/js_test.go @@ -0,0 +1,38 @@ +package flyscrape_test + +import ( + "os" + "testing" + + "flyscrape" + + "github.com/stretchr/testify/require" +) + +var html = ` +<html> + <body> + <main> + <h1>Plugins</h1> + <p>The plugin API allows you to inject code into various parts of the build process.</p> + </main> + </body> +</html>` + +func TestV8(t *testing.T) { + data, err := os.ReadFile("examples/esbuild.github.io.js") + require.NoError(t, err) + + opts, run, err := flyscrape.Compile(string(data)) + require.NoError(t, err) + require.NotNil(t, opts) + require.NotNil(t, run) + + extract, err := run(flyscrape.ScrapeParams{ + HTML: html, + }) + + require.NoError(t, err) + require.Equal(t, "Plugins", extract.(map[string]any)["headline"]) + require.Equal(t, "The plugin API allows you to inject code into various parts of the build process.", extract.(map[string]any)["body"]) +} |