-
-
Save rdig/f80a4ca1a4a4d3fbc1c73a6543c8bff6 to your computer and use it in GitHub Desktop.
Initial setup of `colony-wallet` performance testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/.babelrc b/.babelrc | |
index eb8457f..516cf7e 100644 | |
--- a/.babelrc | |
+++ b/.babelrc | |
@@ -10,7 +10,8 @@ | |
], | |
"ignore": [ | |
"__tests__", | |
- "__mocks__" | |
+ "__mocks__", | |
+ "__performance__" | |
], | |
"env": { | |
"es": { | |
diff --git a/.eslintignore b/.eslintignore | |
index e1010ae..1c78b01 100644 | |
--- a/.eslintignore | |
+++ b/.eslintignore | |
@@ -2,4 +2,5 @@ node_modules | |
scripts | |
flow-typed | |
jest.config.js | |
+jest-perf.config.js | |
webpack.config.js | |
diff --git a/.flowconfig b/.flowconfig | |
index 09db309..2585d9c 100644 | |
--- a/.flowconfig | |
+++ b/.flowconfig | |
@@ -4,6 +4,7 @@ | |
[ignore] | |
.*/__tests__/.* | |
.*/__mocks__/.* | |
+.*/__performance__/.* | |
.*/lib/.* | |
[libs] | |
diff --git a/jest-perf.config.js b/jest-perf.config.js | |
new file mode 100644 | |
index 0000000..e087fe3 | |
--- /dev/null | |
+++ b/jest-perf.config.js | |
@@ -0,0 +1,6 @@ | |
+module.exports = { | |
+ rootDir: 'src', | |
+ testMatch: [ | |
+ '**/__performance__/**/*.test.js?(x)', | |
+ ], | |
+}; | |
diff --git a/jest.config.js b/jest.config.js | |
index aa0b358..4a1ea8d 100644 | |
--- a/jest.config.js | |
+++ b/jest.config.js | |
@@ -12,4 +12,8 @@ module.exports = { | |
'qrcode': '<rootDir>/src/__mocks__/qrcode.js', | |
'ethereum-blockies': '<rootDir>/src/__mocks__/ethereum-blockies.js', | |
}, | |
+ testPathIgnorePatterns: [ | |
+ '/node_modules/', | |
+ '/__performance__/', | |
+ ], | |
}; | |
diff --git a/package.json b/package.json | |
index 4acd2f7..e07adb3 100644 | |
--- a/package.json | |
+++ b/package.json | |
@@ -27,6 +27,7 @@ | |
"test:watch": "NODE_ENV=test jest --watchAll", | |
"test:coverage": "NODE_ENV=test jest --coverage", | |
"test:ci": "jest --clearCache && NODE_ENV=test jest --ci --coverage --verbose=true --testResultsProcessor='jest-junit'", | |
+ "test:perf": "jest --clearCache && NODE_ENV=test jest --config jest-perf.config.js", | |
"lockfile:update": "greenkeeper-lockfile-update", | |
"lockfile:upload": "greenkeeper-lockfile-upload" | |
}, | |
diff --git a/scripts/jobs.js b/scripts/jobs.js | |
index 82315f8..0dd61bb 100644 | |
--- a/scripts/jobs.js | |
+++ b/scripts/jobs.js | |
@@ -32,7 +32,14 @@ const cjsModules = message => run( | |
); | |
const flowTypes = message => run( | |
- `flow-copy-source --ignore "${paths.globs.tests}" --ignore "${paths.globs.mocks}" --ignore "${paths.files.defaults}" --ignore "${paths.files.messages}" ${paths.source} ${paths.modules}`, | |
+ 'flow-copy-source ' + | |
+ `--ignore "${paths.globs.tests}" ` + | |
+ `--ignore "${paths.globs.mocks}" ` + | |
+ `--ignore "${paths.globs.performance}" ` + | |
+ `--ignore "${paths.files.defaults}" ` + | |
+ `--ignore "${paths.files.messages}" ` + | |
+ `${paths.source} ` + | |
+ `${paths.modules}`, | |
{}, | |
message | |
); | |
diff --git a/scripts/paths.js b/scripts/paths.js | |
index 253e3d7..670b8ba 100644 | |
--- a/scripts/paths.js | |
+++ b/scripts/paths.js | |
@@ -26,6 +26,7 @@ const files = { | |
const globs = { | |
tests: "**/__tests__/**", | |
mocks: "**/__mocks__/**", | |
+ performance: "**/__performance__/**", | |
}; | |
diff --git a/scripts/watch.js b/scripts/watch.js | |
index bc5a64c..e804d2e 100644 | |
--- a/scripts/watch.js | |
+++ b/scripts/watch.js | |
@@ -16,7 +16,11 @@ const files = {}; | |
* Initialize watcher | |
*/ | |
const sourceWatch = chokidar.watch(paths.source, { | |
- ignored: ['**/__tests__', '**/__mocks__'], | |
+ ignored: [ | |
+ paths.globs.tests, | |
+ paths.globs.mocks, | |
+ paths.globs.performance, | |
+ ], | |
awaitWriteFinish: true | |
}); | |
diff --git a/src/__performance__/.eslintrc b/src/__performance__/.eslintrc | |
new file mode 100644 | |
index 0000000..7d09b83 | |
--- /dev/null | |
+++ b/src/__performance__/.eslintrc | |
@@ -0,0 +1,8 @@ | |
+{ | |
+ "env": { | |
+ "jest": true, | |
+ }, | |
+ "rules": { | |
+ "flowtype/require-valid-file-annotation": [0], | |
+ }, | |
+} | |
diff --git a/src/__performance__/performanceUtils.js b/src/__performance__/performanceUtils.js | |
new file mode 100644 | |
index 0000000..bf0cbb2 | |
--- /dev/null | |
+++ b/src/__performance__/performanceUtils.js | |
@@ -0,0 +1,16 @@ | |
+export const performanceRunner = (runs = 10, callback) => { | |
+ let timeStart = 0; | |
+ const timeAccumulator = []; | |
+ for (let i = 0; i < runs; i += 1) { | |
+ timeStart = Date.now(); | |
+ callback(); | |
+ timeAccumulator.push(Date.now() - timeStart); | |
+ } | |
+ return timeAccumulator; | |
+}; | |
+ | |
+const perfomanceUtils = { | |
+ performanceRunner, | |
+}; | |
+ | |
+export default perfomanceUtils; | |
diff --git a/src/__performance__/wallet/create.test.js b/src/__performance__/wallet/create.test.js | |
new file mode 100644 | |
index 0000000..28f1ed6 | |
--- /dev/null | |
+++ b/src/__performance__/wallet/create.test.js | |
@@ -0,0 +1,21 @@ | |
+import { performanceRunner } from '../performanceUtils'; | |
+import { create } from '../../softwareWallet'; | |
+ | |
+jest.unmock('ethers/wallet'); | |
+ | |
+describe('Wallet Preformance', () => { | |
+ test('Wallet creation duration', () => { | |
+ const runs = 10; | |
+ /* | |
+ * This is super HIGH just because the Jest runner is slow. | |
+ * In a browser environment this would be at ~100 ms | |
+ */ | |
+ const threshold = 700; | |
+ const times = performanceRunner(runs, create); | |
+ const totalTimes = times.reduce( | |
+ (totalTime, currentTime) => totalTime + currentTime, | |
+ 0, | |
+ ); | |
+ expect(totalTimes / runs).toBeLessThan(threshold); | |
+ }); | |
+}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment