Skip to content

Commit 1ce09b4

Browse files
committed
Merge branch 'release/v2.0.0'
2 parents 1f8f4ce + 41bc704 commit 1ce09b4

37 files changed

+4801
-1949
lines changed

.bowerrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
.idea
22
.DS_Store
33
node_modules
4-
test/public/lib/handsontable/enabled_all_modules
5-
test/public/lib/handsontable/disabled_plugins
6-
benchmark/bower_components
4+
temp/

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(The MIT License)
22

33
Copyright (c) 2012-2014 Marcin Warpechowski
4-
Copyright (c) 2015 Handsoncode sp. z o.o. <hello@handsontable.com>
4+
Copyright (c) 2019 Handsoncode sp. z o.o. <hello@handsontable.com>
55

66
Permission is hereby granted, free of charge, to any person obtaining
77
a copy of this software and associated documentation files (the

README.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,62 @@ JavaScript performance tests for Handsontable (http://handsontable.github.io/per
44

55
## Install
66

7-
Install dependencies via [NPM](http://npmjs.com/)
7+
The minimal Node version which this project can run on is 11. Make sure that your version meets that criteria before
8+
you continue with the installation.
9+
10+
Install dependencies via [NPM](https://npmjs.com/)
811

912
```sh
1013
$ npm install
1114
```
1215

13-
and [Bower](http://bower.io/)
16+
Test results are stored in MongoDB instance so it is necessary to set up the DB before you run the script. If you have
17+
[docker](https://www.docker.com/) installed you can run services using [docker-compose](https://github.com/docker/compose).
1418

1519
```sh
16-
$ bower install
20+
docker-compose -f docker/docker-compose.yml up
1721
```
1822

19-
## Example
23+
## Run It
2024

21-
To run performance tests execute script
25+
To run performance tests and save the results to the DB execute
2226

2327
```sh
24-
$ ./bin/hot-perf
28+
$ ./bin/hot-perf run
2529
```
2630

27-
or
31+
or
2832

2933
```sh
30-
$ npm test
34+
$ npm run start
3135
```
3236

33-
Once completed you can view generated tests report in `benchmark/results` directory. You can compare them in our
34-
benchmark viewer at `benchmark/index.html`.
37+
Performance tests are defined in the `test/spec` directory. Each test contains code which prepares Handsontable for tests
38+
and block of code which then executes several times (defined as SAMPLE_SIZE in the `lib/config.js` file). After each
39+
call, stats are collected and after the amount of iteration hit the SAMPLE_SIZE the result is saved to the database.
40+
41+
Once completed you can view generated test reports by running `./bin/hot-perf local-server benchmark-viewer`.
42+
It serves a page where you can compare your generated results between different Handsontable versions and different test cases.
3543

3644
## Usage
3745

38-
##### ```> ./bin/hot-perf```
46+
##### ```> ./bin/hot-perf run```
47+
48+
It runs a benchmark by running all spec files defined in the `test/spec` directory. Once completed results are saved to the database.
3949

40-
Run tests
50+
##### ```> ./bin/hot-perf local-server <app_to_serve>```
51+
52+
Runs a local server.
4153

4254
Arguments:
43-
- ```--hot-branch``` - Select version of Handsontable to test or branch name from Handsontable repository.
44-
- ```--gen-map-file``` - Regenerate `results/map.json` file which contains all available generated report paths.
45-
- ```--server``` - Run local HTTP server.
55+
- ```test-runner``` - It serves a test runner page which is used by protractor to test the Handsontable.
56+
- ```benchmark-viewer``` - It serves a page which is used to view results generated by the `run` command.
57+
58+
### Global options:
59+
- ```--hot-version``` - Selects version of the Handsontable to test (it has to be a version which is accessible through [jsdelivr](https://www.jsdelivr.com/)). If not specified the `latest` tag is used. For example `--hot-version=6.2.2`.
60+
- ```--hot-server``` - Selects a server to be used to serve the Handsontable assets. For example `--hot-server=http://localhost:8082`. If
61+
used the assets are loaded from `dist` directory, such as `http://localhost:8082/dist/handsontable.full.css`.
4662

4763
## License
4864

49-
[MIT License](http://opensource.org/licenses/MIT)
65+
[MIT License](https://opensource.org/licenses/MIT)

benchmark/js/main.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

bower.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

docker/docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Docker services prepared for development purposes.
3+
#
4+
version: "3.7"
5+
services:
6+
mongo:
7+
container_name: performance-lab-mongodb
8+
image: mongo:4
9+
command: --smallfiles
10+
ports:
11+
- 27017:27017
12+
environment:
13+
MONGO_INITDB_ROOT_USERNAME: root
14+
MONGO_INITDB_ROOT_PASSWORD: root
15+
volumes:
16+
- ./../temp/mongodb:/data/db
17+
18+
mongo-express:
19+
container_name: performance-lab-dbviewer
20+
image: mongo-express
21+
ports:
22+
- 8081:8081
23+
environment:
24+
ME_CONFIG_MONGODB_ADMINUSERNAME: root
25+
ME_CONFIG_MONGODB_ADMINPASSWORD: root
26+
depends_on:
27+
- mongo

lib/cli.js

Lines changed: 46 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,49 @@
1-
2-
var argv = require('minimist')(process.argv.slice(2));
3-
var dirTree = require('dir-tree');
4-
var fs = require('fs-extra');
5-
var hotBuilder = require('hot-builder');
6-
var httpServer = require('http-server');
7-
var merge = require('merge');
8-
var path = require('path');
9-
var Promise = require('promise');
10-
11-
var TESTS_DIR = 'test';
12-
var RESULTS_DIR = 'benchmark/results';
13-
var SAMPLE_SIZE = 100;
14-
var SERVER_HOST = 'localhost';
15-
var SERVER_PORT = '8080';
16-
17-
var BASE_URL = 'http://' + SERVER_HOST + ':' + SERVER_PORT + '/';
18-
var hotVersion = null;
19-
var hotBranch = argv['hot-branch'];
20-
var runServer = argv['server'];
21-
var genMapFile = argv['gen-map-file'];
22-
23-
if (runServer) {
24-
console.log('Running HTTP server (http://' + SERVER_HOST + ':' + 8080 + ')...');
25-
runHttpServer();
26-
27-
return;
1+
const program = require('caporal');
2+
const semver = require('semver');
3+
const config = require('./config');
4+
const { version: packageVersion, engines } = require('./../package');
5+
6+
const hotVersionRegExp = /^\d{1,3}\.\d{1,3}\.\d{1,3}$/;
7+
8+
function parseArgs() {
9+
program
10+
.version(packageVersion)
11+
.description('JavaScript performance tests for Handsontable')
12+
.command('local-server', 'Run a local server ("test-runner" or "benchmark-viewer").')
13+
.argument('<app_to_serve>', 'Type of the application to serve ("test-runner" or "benchmark-viewer")', /^(test\-runner|benchmark\-viewer)$/, 'test-runner')
14+
.option('--hot-version <version>', 'The Handsontable <version> which will be used for running a benchmark.', hotVersionRegExp)
15+
.option('--hot-server <url>', 'The server <url> which will be used to serve Handsontable assets from.')
16+
.action((args, options) => {
17+
require('./commands/local-server')(args.appToServe, parseInt(config.SERVER_PORT, 10) + 1, options);
18+
})
19+
.command('run', 'Run a benchmark.')
20+
.option('--hot-version <version>', 'The Handsontable <version> which will be used for running a benchmark.', hotVersionRegExp)
21+
.option('--hot-server <url>', 'The server <url> which will be used to serve Handsontable assets from.')
22+
.action(async (args, options) => {
23+
await require('./commands/local-server')('test-runner', config.SERVER_PORT, options);
24+
25+
const statsGenerator = require('./commands/protractor')(options);
26+
27+
await require('./storage').saveByReplace(statsGenerator);
28+
29+
process.exit(0);
30+
})
31+
;
32+
33+
program.parse(process.argv);
2834
}
29-
if (genMapFile) {
30-
console.log('Generating map file...');
31-
32-
new Promise(function(resolve, reject) {
33-
fs.mkdirs(RESULTS_DIR, function(err) {
34-
if (err) {
35-
return reject(err);
36-
}
37-
resolve();
38-
});
39-
}).then(function() {
40-
return dirTree(RESULTS_DIR);
4135

42-
}).then(function(tree) {
43-
return new Promise(function(resolve, reject) {
44-
fs.writeFile(path.resolve(RESULTS_DIR + '/map.json'), JSON.stringify(tree), function(err) {
45-
if (err) {
46-
return reject(err);
47-
}
48-
resolve();
49-
});
50-
});
51-
}).then(function() {
52-
console.log('Generated map file in ' + RESULTS_DIR + '/map.json');
53-
}).catch(function(error) {
54-
console.error('Error generating map ->', error);
55-
});
56-
57-
return;
58-
}
59-
60-
buildHandsontable({
61-
hotBranch: hotBranch,
62-
outputDir: TESTS_DIR + '/public/lib/handsontable/disabled_plugins',
63-
include: ['SheetClip', 'autoResize', 'copyPaste', 'jsonpatch'],
64-
includeTypes: [] // without plugins
65-
}).then(function() {
66-
return buildHandsontable({
67-
outputDir: TESTS_DIR + '/public/lib/handsontable/enabled_all_modules',
68-
includeTypes: ['all'] // all modules
69-
});
70-
}).then(function(builder) {
71-
hotVersion = builder.entryFile.getFile('handsontable').package.version;
72-
73-
if (hotBranch && ['latest', 'master', 'link'].indexOf(hotBranch) === -1) {
74-
hotVersion = hotBranch.replace(/\//g, '-');
36+
(function main() {
37+
try {
38+
if (!semver.satisfies(process.versions.node, engines.node)) {
39+
throw Error(`The project requires Node.js${engines.node} for running. You've currently installed version ${process.versions.node}.`);
40+
}
41+
42+
parseArgs();
43+
} catch (ex) {
44+
/* eslint-disable no-console */
45+
console.log(ex.message);
46+
console.log('');
47+
process.exit(2);
7548
}
76-
fs.ensureDirSync('./' + RESULTS_DIR);
77-
78-
runHttpServer();
79-
runCmd('./node_modules/.bin/protractor', ['protractor.conf.js']);
80-
}).catch(function(error) {
81-
console.error(error.message);
82-
});
83-
84-
/**
85-
* Build handsontable
86-
*
87-
* @returns {Promise}
88-
*/
89-
function buildHandsontable(options) {
90-
var defaultOptions = {
91-
disableUI: true,
92-
includeTypes: [],
93-
minify: false
94-
};
95-
96-
options = merge(defaultOptions, options);
97-
98-
return new Promise(function(resolve, reject) {
99-
var builder = new hotBuilder(null, options);
100-
101-
builder.on('complete', function() {
102-
resolve(builder);
103-
});
104-
builder.on('error', reject);
105-
});
106-
}
107-
108-
/**
109-
* Run HTTP Server
110-
*/
111-
function runHttpServer() {
112-
httpServer.createServer({
113-
showDir: false,
114-
root: './' + TESTS_DIR + '/public'
115-
}).listen(SERVER_PORT, SERVER_HOST);
116-
}
117-
118-
/**
119-
* Run shell command
120-
*
121-
* @param {String} cmd
122-
* @param {Array} args
123-
*/
124-
function runCmd(cmd, args) {
125-
var
126-
fork = require('child_process').fork,
127-
toExport = {},
128-
child;
129-
130-
toExport.BASE_URL = BASE_URL;
131-
toExport.TESTS_DIR = TESTS_DIR;
132-
toExport.RESULTS_DIR = RESULTS_DIR;
133-
toExport.SAMPLE_SIZE = SAMPLE_SIZE;
134-
toExport.SERVER_HOST = SERVER_HOST;
135-
toExport.SERVER_PORT = SERVER_PORT;
136-
toExport.hotVersion = hotVersion;
137-
138-
child = fork(cmd, args);
139-
child.send({
140-
toExport: toExport
141-
});
142-
child.on('exit', function() {
143-
process.exit(0);
144-
});
145-
}
49+
}());

0 commit comments

Comments
 (0)