File tree Expand file tree Collapse file tree 1 file changed +72
-0
lines changed Expand file tree Collapse file tree 1 file changed +72
-0
lines changed Original file line number Diff line number Diff line change
1
+ import puppeteer from "puppeteer" ;
2
+ import Webpack from "webpack" ;
3
+ import { fs } from "memfs" ;
4
+
5
+ import webpackConfig from "../webpack.config.js" ;
6
+
7
+ /**
8
+ * Validate a URL
9
+ * @param {URL } url
10
+ * @returns {boolean }
11
+ */
12
+ const validateUrl = ( url ) => {
13
+ try {
14
+ return new URL ( url ) ;
15
+ } catch ( _e ) {
16
+ return false ;
17
+ }
18
+ } ;
19
+
20
+ if ( ! process . argv [ 2 ] ) {
21
+ console . error ( "Usage: yarn test '<url>'" ) ;
22
+ process . exit ( 1 ) ;
23
+ }
24
+
25
+ if ( ! validateUrl ( process . argv [ 2 ] ) ) {
26
+ console . error ( "Invalid URL (hint: include http:// or https://)" ) ;
27
+ process . exit ( 1 ) ;
28
+ }
29
+
30
+ const config = webpackConfig ( { } , { mode : "development" } ) ;
31
+
32
+ const compiler = Webpack ( config ) ;
33
+ compiler . outputFileSystem = fs ;
34
+
35
+ const browser = await puppeteer . launch ( { headless : false , devtools : true } ) ;
36
+ const page = await browser . newPage ( ) ;
37
+
38
+ const _watching = compiler . watch ( { } , async ( err , stats ) => {
39
+ if ( err ) {
40
+ console . error ( err ) ;
41
+ console . error ( "Not opening browser" ) ;
42
+ return ;
43
+ }
44
+ console . log (
45
+ stats . toString ( {
46
+ colors : true ,
47
+ preset : "summary" ,
48
+ } ) ,
49
+ ) ;
50
+ const behaviorScript = fs . readFileSync ( "dist/behaviors.js" , "utf8" ) ;
51
+
52
+ await page . goto ( validateUrl ( process . argv [ 2 ] ) ) ;
53
+
54
+ await page . evaluate (
55
+ behaviorScript +
56
+ `
57
+ self.__bx_behaviors.init({
58
+ autofetch: true,
59
+ autoplay: true,
60
+ autoscroll: true,
61
+ siteSpecific: true,
62
+ });
63
+ ` ,
64
+ ) ;
65
+
66
+ // call and await run on top frame and all child iframes
67
+ await Promise . allSettled (
68
+ page
69
+ . frames ( )
70
+ . map ( async ( frame ) => frame . evaluate ( "self.__bx_behaviors.run()" ) ) ,
71
+ ) ;
72
+ } ) ;
You can’t perform that action at this time.
0 commit comments