Skip to content

Commit 782acd0

Browse files
committed
[stack] Add some puppeteer tests to cacheBundleGeneration.js
1 parent ad0d29e commit 782acd0

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

demo/cacheBundleGeneration.js

+80-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Copyright (c) 2017, Tetsuya Mori <[email protected]>. All rights reserved.
3030
let targetURL = 'https://localhost/components/thin-hook/demo/';
3131

3232
const puppeteer = require('puppeteer');
33+
const chai = require('chai');
3334
const fs = require('fs');
3435
const path = require('path');
3536
const del = require('del');
@@ -60,12 +61,90 @@ default:
6061
const browser = await puppeteer.launch({ headless: true, args: [ '--disable-gpu' ], executablePath: chromePath });
6162
const page = await browser.newPage();
6263
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
63143
await page.goto(targetURL);
64144
console.log('goto', targetURL);
65145
await page.waitFor(15000);
66146
console.log('waitFor(15000)');
67147

68-
let result;
69148
result = await page.evaluate(function waitForBundleSetFetched() {
70149
return new Promise(resolve => {
71150
let intervalId = setInterval(async () => {

0 commit comments

Comments
 (0)