@@ -30,6 +30,7 @@ Copyright (c) 2017, Tetsuya Mori <
[email protected] >. All rights reserved.
30
30
let targetURL = 'https://localhost/components/thin-hook/demo/' ;
31
31
32
32
const puppeteer = require ( 'puppeteer' ) ;
33
+ const chai = require ( 'chai' ) ;
33
34
const fs = require ( 'fs' ) ;
34
35
const path = require ( 'path' ) ;
35
36
const del = require ( 'del' ) ;
@@ -60,12 +61,90 @@ default:
60
61
const browser = await puppeteer . launch ( { headless : true , args : [ '--disable-gpu' ] , executablePath : chromePath } ) ;
61
62
const page = await browser . newPage ( ) ;
62
63
await page . setViewport ( { width : 1200 , height : 800 } ) ;
64
+
65
+ /*
66
+ page.on('frameattached', function onFrameAttached() {
67
+ console.log('frameattached');
68
+ });
69
+
70
+ // for customized puppeteer/lib/Page.js
71
+ page.on('framestartedloading', async function onFrameStartedLoading() {
72
+ console.log('framestartedloading');
73
+ });
74
+ */
75
+
76
+ page . on ( 'domcontentloaded' , async function onDomContentLoaded ( ) {
77
+ console . log ( 'domcontentloaded' ) ;
78
+ } ) ;
79
+
80
+ page . on ( 'load' , function onLoad ( ) {
81
+ console . log ( 'load' ) ;
82
+ } ) ;
83
+
84
+
85
+ let result ;
86
+
87
+ // tests
88
+ await page . goto ( targetURL ) ;
89
+ console . log ( 'goto' , targetURL ) ;
90
+ await page . waitFor ( 15000 ) ;
91
+ console . log ( 'waitFor(15000)' ) ;
92
+ result = await page . evaluate ( function getCaches ( ) {
93
+ try {
94
+ return caches . constructor . name ;
95
+ }
96
+ catch ( error ) {
97
+ return error . message ;
98
+ }
99
+ } ) ;
100
+ console . log ( 'test: getCaches:' , result ) ;
101
+ chai . assert . equal ( result , 'Cannot read property \'constructor\' of undefined' , 'cannot access caches' ) ;
102
+ await page . waitFor ( 1000 ) ;
103
+ result = await page . evaluate ( function checkLocation ( ) {
104
+ try {
105
+ return location . href ;
106
+ }
107
+ catch ( error ) {
108
+ return error . message ;
109
+ }
110
+ } ) ;
111
+ console . log ( 'test: checkLocation:' , result ) ;
112
+ chai . assert . equal ( result , 'about:blank' , 'location is about:blank' ) ;
113
+
114
+ await page . goto ( targetURL ) ;
115
+ console . log ( 'goto' , targetURL ) ;
116
+ await page . waitFor ( 15000 ) ;
117
+ console . log ( 'waitFor(15000)' ) ;
118
+ result = await page . evaluate ( function getObjectIndirect ( ) {
119
+ try {
120
+ return this . __proto__ . __proto__ . __proto__ . __proto__ . constructor . name ;
121
+ }
122
+ catch ( error ) {
123
+ return error . message ;
124
+ }
125
+ } ) ;
126
+ console . log ( 'test: getObjectIndirect:' , result ) ;
127
+ chai . assert . equal ( result , 'Cannot read property \'name\' of undefined' , 'cannot access Object via constructor property' ) ;
128
+ await page . waitFor ( 1000 ) ;
129
+ result = await page . evaluate ( function checkLocation ( ) {
130
+ try {
131
+ return location . href ;
132
+ }
133
+ catch ( error ) {
134
+ return error . message ;
135
+ }
136
+ } ) ;
137
+ console . log ( 'test: checkLocation:' , result ) ;
138
+ chai . assert . equal ( result , 'about:blank' , 'location is about:blank' ) ;
139
+
140
+ // end of tests
141
+
142
+ // start generation of cache-bundle.json
63
143
await page . goto ( targetURL ) ;
64
144
console . log ( 'goto' , targetURL ) ;
65
145
await page . waitFor ( 15000 ) ;
66
146
console . log ( 'waitFor(15000)' ) ;
67
147
68
- let result ;
69
148
result = await page . evaluate ( function waitForBundleSetFetched ( ) {
70
149
return new Promise ( resolve => {
71
150
let intervalId = setInterval ( async ( ) => {
0 commit comments