Commit 727f2a61 authored by 姚广胤's avatar 姚广胤

更改项目名称

parent e2b98a2b
{ {
"name": "warden", "name": "warden",
"description": "an automate performance watcher", "description": "an automate performance test tool",
"version": "1.0.0", "version": "1.0.0",
"author": "jsholic <junhe0723@gmail.com>", "author": "jsholic <junhe0723@gmail.com>",
"contributors": [ "contributors": [
......
{ {
"name": "warden", "name": "warden",
"description": "an automate performance watcher", "description": "an automate performance test tool",
"version": "1.0.0", "version": "1.0.0",
"main": "app.js", "main": "app.js",
"scripts": { "scripts": {
......
...@@ -7,15 +7,19 @@ const iPhone = devices['iPhone 6']; ...@@ -7,15 +7,19 @@ const iPhone = devices['iPhone 6'];
* *
*/ */
const iterateTimes = async (task, n = 2) => { const iterateTimes = async (task, n = 2) => {
console.info('iterateTimes start');
const allTaskResult = []; const allTaskResult = [];
for (let i = 0; i < n; i++) { for (let i = 0; i < n; i++) {
allTaskResult.push(await runBrowser(task)); allTaskResult.push(await runBrowser(task));
} }
console.info('iterateTimes end');
return await groupPage(allTaskResult, task); return await groupPage(allTaskResult, task);
}; };
const groupPage = async (allTaskResult, task) => { const groupPage = async (allTaskResult, task) => {
console.info('groupPage start');
const taskCopy = JSON.parse(JSON.stringify(task)); const taskCopy = JSON.parse(JSON.stringify(task));
allTaskResult.forEach(taskResult => { allTaskResult.forEach(taskResult => {
...@@ -29,7 +33,7 @@ const groupPage = async (allTaskResult, task) => { ...@@ -29,7 +33,7 @@ const groupPage = async (allTaskResult, task) => {
unitTaskCopy['arr'].push(page); unitTaskCopy['arr'].push(page);
}); });
}); });
console.info('groupPage end');
return taskCopy; return taskCopy;
}; };
...@@ -37,6 +41,7 @@ const groupPage = async (allTaskResult, task) => { ...@@ -37,6 +41,7 @@ const groupPage = async (allTaskResult, task) => {
* 启用无头浏览器,根据任务里的页面地址去循环执行 * 启用无头浏览器,根据任务里的页面地址去循环执行
*/ */
const runBrowser = async task => { const runBrowser = async task => {
console.info('runBrowser start');
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox'] args: ['--no-sandbox', '--disable-setuid-sandbox']
}); });
...@@ -48,6 +53,7 @@ const runBrowser = async task => { ...@@ -48,6 +53,7 @@ const runBrowser = async task => {
browser.close(); browser.close();
console.info('runBrowser end');
return taskResult; return taskResult;
}; };
...@@ -58,9 +64,10 @@ const runBrowser = async task => { ...@@ -58,9 +64,10 @@ const runBrowser = async task => {
* @param {*} unitTask * @param {*} unitTask
*/ */
const runPage = async (browser, unitTask) => { const runPage = async (browser, unitTask) => {
console.info('runPage start');
try { try {
const page = await browser.newPage(); const page = await browser.newPage();
const { href, arr } = unitTask; const { href } = unitTask;
await page.emulate(iPhone); await page.emulate(iPhone);
...@@ -72,6 +79,7 @@ const runPage = async (browser, unitTask) => { ...@@ -72,6 +79,7 @@ const runPage = async (browser, unitTask) => {
await page.close(); await page.close();
console.info('runPage end');
return testResult; return testResult;
} catch (err) { } catch (err) {
throw err; throw err;
...@@ -85,6 +93,8 @@ const runPage = async (browser, unitTask) => { ...@@ -85,6 +93,8 @@ const runPage = async (browser, unitTask) => {
* @param {*} unitTask * @param {*} unitTask
*/ */
const collectTiming = async page => { const collectTiming = async page => {
console.info('collectTiming start');
return await page.evaluate(() => { return await page.evaluate(() => {
const pt = window.performance.timing; const pt = window.performance.timing;
......
{ {
"name": "warden", "name": "warden",
"description": "an automate performance watcher", "description": "an automate performance test tool",
"version": "1.0.0", "version": "1.0.0",
"author": "jsholic <junhe0723@gmail.com>", "author": "jsholic <junhe0723@gmail.com>",
"contributors": [ "contributors": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment