Skip to content

Commit

Permalink
Merge branch 'release/v2.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
budnix committed Oct 6, 2023
2 parents 084ae22 + 6d24462 commit 13e713c
Show file tree
Hide file tree
Showing 23 changed files with 1,258 additions and 558 deletions.
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion bin/hot-perf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node

require('../lib/cli.js');
require('../lib/cli.js');
86 changes: 58 additions & 28 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,91 @@
const program = require('caporal');
const semver = require('semver');
const config = require('./config');
const { version: packageVersion, engines } = require('./../package');
const program = require("caporal");
const semver = require("semver");
const config = require("./config");
const { version: packageVersion, engines } = require("./../package");

const appToServeMap = new Map([
['tr', 'test-runner'],
['bv', 'benchmark-viewer'],
["tr", "test-runner"],
["bv", "benchmark-viewer"],
]);
const hotVersionRegExp = /^(\d{1,3}\.\d{1,3}\.\d{1,3}|latest)$/;

function parseArgs() {
program
.version(packageVersion)
.description('JavaScript performance tests for Handsontable')
.command('local-server', 'Run a local server ("test-runner", "tr" or "benchmark-viewer", "bv").')
.alias('ls')
.argument('<app_to_serve>', 'Type of the application to serve ("test-runner" or "benchmark-viewer")', /^(test\-runner|tr|benchmark\-viewer|bv)$/, 'test-runner')
.option('--hot-version <version>', 'The Handsontable <version> which will be used for running a benchmark.', hotVersionRegExp)
.option('--hot-server <url>', 'The server <url> which will be used to serve Handsontable assets from.')
.description("JavaScript performance tests for Handsontable")
.command(
"local-server",
'Run a local server ("test-runner", "tr" or "benchmark-viewer", "bv").',
)
.alias("ls")
.argument(
"<app_to_serve>",
'Type of the application to serve ("test-runner" or "benchmark-viewer")',
/^(test\-runner|tr|benchmark\-viewer|bv)$/,
"test-runner",
)
.option(
"--hot-version <version>",
"The Handsontable <version> which will be used for running a benchmark.",
hotVersionRegExp,
)
.option(
"--hot-server <url>",
"The server <url> which will be used to serve Handsontable assets from.",
)
.action((args, options) => {
require('./commands/local-server')(
require("./commands/local-server")(
appToServeMap.get(args.appToServe) ?? args.appToServe,
parseInt(config.SERVER_PORT, 10) + 1,
options
options,
);
})
.command('run', 'Run a benchmark.')
.alias('r')
.option('--hot-version <version>', 'The Handsontable <version> which will be used for running a benchmark.', hotVersionRegExp)
.option('--hot-server <url>', 'The server <url> which will be used to serve Handsontable assets from.')
.option('--test-name <name>', 'The <name> name under which the test will be saved.')
.option('--cpu-throttle-rate <number>', 'The <number> CPU throttle rate.')
.command("run", "Run a benchmark.")
.alias("r")
.option(
"--hot-version <version>",
"The Handsontable <version> which will be used for running a benchmark.",
hotVersionRegExp,
)
.option(
"--hot-server <url>",
"The server <url> which will be used to serve Handsontable assets from.",
)
.option(
"--test-name <name>",
"The <name> name under which the test will be saved.",
)
.option("--cpu-throttle-rate <number>", "The <number> CPU throttle rate.")
.action(async (args, options) => {
await require('./commands/local-server')('test-runner', config.SERVER_PORT, options);
await require("./commands/local-server")(
"test-runner",
config.SERVER_PORT,
options,
);

const statsGenerator = require('./commands/protractor')(options);
const statsGenerator = require("./commands/protractor")(options);

await require('./storage').saveByReplace(statsGenerator);
await require("./storage").saveByReplace(statsGenerator);

process.exit(0);
})
;
});

program.parse(process.argv);
}

(function main() {
try {
if (!semver.satisfies(process.versions.node, engines.node)) {
throw Error(`The project requires Node.js${engines.node} for running. You've currently installed version ${process.versions.node}.`);
throw Error(
`The project requires Node.js${engines.node} for running. You've currently installed version ${process.versions.node}.`,
);
}

parseArgs();
} catch (ex) {
/* eslint-disable no-console */
console.log(ex.message);
console.log('');
console.log("");
process.exit(2);
}
}());
})();
46 changes: 25 additions & 21 deletions lib/commands/local-server/index.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,49 @@
const Hapi = require('@hapi/hapi');
const path = require('path');
const config = require('./../../config');
const { loadAll } = require('./../../storage');
const Hapi = require("@hapi/hapi");
const path = require("path");
const config = require("./../../config");
const { loadAll } = require("./../../storage");

module.exports = async function(appName, customPort = config.SERVER_PORT, { hotVersion = 'latest', hotServer, testName } = {}) {
module.exports = async function (
appName,
customPort = config.SERVER_PORT,
{ hotVersion = "latest", hotServer, testName } = {},
) {
const server = Hapi.server({
port: customPort,
host: config.SERVER_HOST,
routes: {
files: {
relativeTo: __dirname + path.sep + 'public',
}
relativeTo: __dirname + path.sep + "public",
},
},
});

await server.register(require('@hapi/vision'));
await server.register(require('@hapi/inert'));
await server.register(require("@hapi/vision"));
await server.register(require("@hapi/inert"));

server.views({
engines: {
html: require('handlebars'),
html: require("handlebars"),
},
relativeTo: __dirname,
path: 'templates',
path: "templates",
});

server.route({
method: 'GET',
path: '/{param*}',
method: "GET",
path: "/{param*}",
handler: {
directory: {
path: '.',
path: ".",
redirectToSlash: true,
index: true,
}
}
},
},
});

server.route({
method: 'GET',
path: '/',
method: "GET",
path: "/",
handler: async function (request, h) {
const stats = await loadAll();

Expand All @@ -48,16 +52,16 @@ module.exports = async function(appName, customPort = config.SERVER_PORT, { hotV
stats: JSON.stringify(Array.from(stats.entries())),
urls: getHotUrl({ hotVersion, hotServer }),
});
}
},
});

await server.start();

console.log(`Server running at: ${server.info.uri}`);
}
};

function getHotUrl({ hotVersion, hotServer } = {}) {
const urls = { script: '', style: '' };
const urls = { script: "", style: "" };

if (hotServer) {
urls.script = `${hotServer}/dist/handsontable.full.js`;
Expand Down
Loading

0 comments on commit 13e713c

Please sign in to comment.