Skip to content
This repository was archived by the owner on Jan 8, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[package.json]
indent_size = 2
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules/
.DS_Store
.DS_Store

.public
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For now, you can just clone this repo and...
1. Npm or Yarn install its deps: `npm install`
1. Build your own application you wanna test and serve it on a local port (i.e. 9999)
1. Use [angular.spec.js](https://github.com/manekinekko/perfy/blob/master/specs/angular.spec.js) as an example
1. Run `npm test`. This will run the perf compain tests
1. Run `npm start`. This will run the perf compain tests
1. All reports will be generated in the [public](https://github.com/manekinekko/perfy/tree/master/public) folder
1. Run a local server to serve the public folder
1. Enjoy 🎉
Expand Down
6 changes: 3 additions & 3 deletions lib/index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="lib/plotly.min.js"></script>
<script>

load(###FILES###)
load(/*###FILES###*/)
.then((metrics) => {

const canvas = document.getElementById('canvas');
Expand Down Expand Up @@ -40,7 +40,7 @@
type: 'scatter'
});
})

const layout = {
title: metrics[0].description.metrics[metricName],
xaxis: {
Expand Down Expand Up @@ -93,4 +93,4 @@
}

</script>
<div id="canvas"></div>
<div id="canvas"></div>
20 changes: 15 additions & 5 deletions lib/merge-reporters.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
var path = require('path');
var glob = require('glob');
'use strict';

const path = require('path');
const glob = require('glob');

module.exports = (pattern) => {
return new Promise( (resolve, reject) => {
glob(pattern, (error, files) => {
if (error) {
return reject(error);
}

const filesContent = files.map(file => {
return {file, content: require(file)};
});

const uniqueFilesNames = Array.from(new Set(files.map( file => file.replace(/_\d+\.json/, '.json') )));

let filesContent = files.map( file => { return { file, content: require(path.join(__dirname, path.resolve(file))) } });
let uniqueFilesNames = Array.from(new Set(files.map( file => file.replace(/_\d+\.json/, '.json') )));
const merge = (file, index) => {
const completeSample = [];
const validSample = [];
Expand Down Expand Up @@ -36,4 +46,4 @@ module.exports = (pattern) => {
resolve(uniqueFilesNames.map( merge ));
});
});
}
};
63 changes: 53 additions & 10 deletions lib/write-files.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,69 @@
var fs = require('fs');
var path = require('path');
var merge = require('./merge-reporters');
'use strict';

const p = pp => path.join(__dirname, pp);
const fs = require('fs');
const path = require('path');

const mkdirpSync = require('mkdirp').sync;
const cpFileSync = require('cp-file').sync;

module.exports = (pattern) => {
const merge = require('./merge-reporters');

const p = pp => path.join(__dirname, pp);
const LIB_FILES = [
'node_modules/plotly.js/dist/plotly.min.js'
];

merge(pattern)
module.exports = options => {
const {publicDir, pattern} = options;
const reportFiles = path.join(publicDir, 'reports', pattern);
merge(reportFiles)
.then( mergedContents => {
mergedContents.map( content => fs.writeFileSync(content.file, JSON.stringify(content, null, 2)));
return mergedContents;
})
.then( mergedContents => {
const indexContent = fs.readFileSync(p('./index.template.html'), 'utf-8').toString();
const filesList = JSON.stringify(mergedContents.map(c => c.file.replace('public/', '')), null, 2);
fs.writeFileSync(p('../public/index.html'), indexContent.replace('###FILES###', filesList));
const filesList = JSON.stringify(mergedContents.map(c => c.file.replace(`${publicDir}/`, '')), null, 2);

mkdirpSync(publicDir);
fs.writeFileSync(path.join(publicDir, 'index.html'), indexContent.replace('/*###FILES###*/', filesList));

copyLib(path.join(publicDir, 'lib'));

return filesList;
})
.then( filesList => console.log( filesList === '[]' ? 'no samples found' : 'merged %d samples \n%s', filesList.split(','), filesList) )
.then( filesList => {
const filesCount = Number.isNaN(filesList.split(',')) ?
filesList === '[]' ? 0 : 1 :
filesList.split(',').length;

console.log(filesCount === 0 ?
'no samples found' :
'merged %d sample%s \n%s', filesCount, filesCount > 1 ? 's' : '', filesList);
})
.catch( error => {
console.error(error);
process.exit(1);
});
};

function copyLib(libDir) {
if (fs.existsSync(libDir)) {
return;
}

mkdirpSync(libDir);

LIB_FILES.forEach(copyFile.bind(null, libDir));
}

function copyFile(rootDir, source) {
const fileName = path.basename(source);
const dest = path.join(rootDir, fileName);

if (fs.existsSync(dest)) {
return;
}

}
cpFileSync(source, dest);
}
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"description": "The perfect companion for Benchpress Performance Toolkit",
"main": "index.js",
"scripts": {
"pretest": "webdriver-manager update",
"test": "protractor protractor.conf.js"
"postinstall": "webdriver-manager update",
"start": "protractor protractor.conf.js",
"test:e2e": "mocha",
"test": "node ./scripts/e2e-test.js",
"watch:test": "node ./scripts/e2e-test.js --watch"
},
"homepage": "https://github.com/manekinekko/perfy",
"bugs": "https://github.com/manekinekko/perfy/issues",
Expand All @@ -22,8 +25,18 @@
"dependencies": {
"@angular/benchpress": "0.1.0",
"asyncawait": "1.0.6",
"cp-file": "^4.1.0",
"glob": "7.1.1",
"mkdirp": "^0.5.1",
"plotly.js": "^1.19.2",
"protractor": "4.0.0",
"zone.js": "^0.6.21"
},
"devDependencies": {
"cross-spawn": "^5.0.1",
"del": "^2.2.2",
"execa": "^0.5.0",
"http-server": "^0.9.0",
"mocha": "^3.1.2"
}
}
15 changes: 12 additions & 3 deletions protractor.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

const path = require('path')

exports.config = {

perfyOptions: {
publicDir: path.join(__dirname, 'public'),
pattern: '*_*.json'
},

allScriptsTimeout: 11000,

directConnect: true,
Expand Down Expand Up @@ -50,8 +59,8 @@ exports.config = {
},

onComplete: () => {
console.log('[Protractor] onComplete');
require('./lib/write-files')('public/reports/*_*.json');
console.log('[Protractor] onComplete');
return require('./lib/write-files')(this.config.perfyOptions);
},

onCleanUp: () => {
Expand All @@ -61,4 +70,4 @@ exports.config = {
afterLaunch: () => {
console.log('[Protractor] afterLaunch');
}
};
};
63 changes: 0 additions & 63 deletions public/lib/plotly.min.js

This file was deleted.

66 changes: 66 additions & 0 deletions scripts/e2e-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict';

const path = require('path');
const crossSpawn = require('cross-spawn');
const {createServer} = require('http-server');
const portfinder = require('portfinder');

//

const port = parseInt(process.env.PORT, 10) || 9999;
// HACK(douglasduteil): cheat code because only one option
const watchMode = process.argv[2] === '--watch';
const host = 'localhost';

const options = {
root: path.resolve(__dirname, '..')
};
const server = createServer(options);

//

Promise.resolve()
.then(openServer)
.then(launchTests.bind(null, watchMode))
.then(closeServer)
.catch((error) => {
console.error(error);
closeServer(1);
})
;

//

process.on('SIGINT',closeServer);
process.on('SIGTERM', closeServer);

//

function launchTests (watchMode) {
return new Promise ((resolve, reject) => {
const watchArgs = watchMode ? ['--watch'] : [];
const child = crossSpawn('yarn', ['run', 'test:e2e', '--'].concat(watchArgs), {stdio: 'inherit'});
child.on('error', reject);
child.on('close', resolve);
})
}
function openServer () {
return new Promise ((resolve) => {
server.listen(port, host, function () {
console.log(`
Starting up http-server, serving ${server.root}
Available on:
http://${host}:${port}

Hit CTRL-C to stop the server
`);
resolve();
});
})
}

function closeServer (exitCode) {
server.close();
console.log('http-server stopped.');
process.exit(exitCode || 0)
}
24 changes: 24 additions & 0 deletions test/fixtures/long-execution-time/benchpress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const path = require('path');

const mkdirpSync = require('mkdirp').sync;
const delSync = require('del').sync;

const defaultBenchpressOptionsFn = require('../../../benchpress.config.js').options;
const perfyConfig = require('./perfy.conf.js').config;

const tmpReportDir = path.join(perfyConfig.publicDir, 'reports');

delSync(perfyConfig.publicDir);
mkdirpSync(perfyConfig.publicDir);
mkdirpSync(tmpReportDir);

exports.options = function longExecutionTimeBenchpressOptionsFn(benchpress) {
const defaultOptions = defaultBenchpressOptionsFn(benchpress);

return [
...defaultOptions,
{provide: benchpress.JsonFileReporter.PATH, useValue: tmpReportDir}
];
};
Loading