From fe2a09bc7f62d755ee7ecbd6d85ec023cc852f37 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Tue, 6 Jan 2015 15:19:22 -0800 Subject: [PATCH] refactor(perf): e2e tests and benchpress should be written in es6 --- README.md | 12 ++- gulpfile.js | 75 +++++++++++++++++-- .../change_detection_perf.es6} | 2 +- .../compiler_perf.es6} | 2 +- .../perf/di_perf.js => e2e_test/di_perf.es6} | 2 +- .../element_injector_perf.es6} | 2 +- .../tree_perf.js => e2e_test/tree_perf.es6} | 2 +- .../compiler_perf.es6} | 2 +- .../tree_perf.js => e2e_test/tree_perf.es6} | 2 +- protractor-perf-shared.js | 5 +- tools/benchpress/{benchpress.js => index.es6} | 4 +- .../{commands.js => src/commands.es6} | 0 .../{reporter.js => src/reporter.es6} | 0 tools/benchpress/{stats.js => src/stats.es6} | 0 .../time_benchmark.es6} | 0 tools/benchpress/{tools.js => src/tools.es6} | 0 tools/build/benchpress.js | 6 ++ 17 files changed, 96 insertions(+), 20 deletions(-) rename modules/benchmarks/{test/perf/change_detection_perf.js => e2e_test/change_detection_perf.es6} (93%) rename modules/benchmarks/{test/perf/compiler_perf.js => e2e_test/compiler_perf.es6} (93%) rename modules/benchmarks/{test/perf/di_perf.js => e2e_test/di_perf.es6} (95%) rename modules/benchmarks/{test/perf/element_injector_perf.js => e2e_test/element_injector_perf.es6} (94%) rename modules/benchmarks/{test/perf/tree_perf.js => e2e_test/tree_perf.es6} (93%) rename modules/benchmarks_external/{test/perf/compiler_perf.js => e2e_test/compiler_perf.es6} (93%) rename modules/benchmarks_external/{test/perf/tree_perf.js => e2e_test/tree_perf.es6} (92%) rename tools/benchpress/{benchpress.js => index.es6} (58%) rename tools/benchpress/{commands.js => src/commands.es6} (100%) rename tools/benchpress/{reporter.js => src/reporter.es6} (100%) rename tools/benchpress/{stats.js => src/stats.es6} (100%) rename tools/benchpress/{time_benchmark.js => src/time_benchmark.es6} (100%) rename tools/benchpress/{tools.js => src/tools.es6} (100%) create mode 100644 tools/build/benchpress.js diff --git a/README.md b/README.md index 1196f3f64d..634432e5a0 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ 1. `npm install` 2. `npm install -g gulp karma karma-cli` +3. `npm install -g protractor` +4. `webdriver-manager update` 3. Optionally install Dart SDK (only if you plan on building Dart applications) 1. [Install the Dart SDK](https://www.dartlang.org/tools/sdk/) 2. [Add the Dart SDK's `bin` directory to your system path](https://www.dartlang.org/tools/pub/installing.html) @@ -34,18 +36,24 @@ 2. `gulp clean` -> cleans the `dist` folder -### Tests: +### Unit tests: 1. `karma start karma-js.conf.js`: JS tests 2. `karma start karma-dart.conf.js`: Dart tests -Notes for all tests: +Notes for transpiler tests: The karma preprocessor is setup in a way so that after every test run the transpiler is reloaded. With that it is possible to make changes to the preprocessor and run the tests without exiting karma (just touch a test file that you would like to run). +### Performance tests + +1. `gulp build.cjs` (builds benchpress and tests into `dist/cjs` folder) +2. `protractor protractor-perf-js.conf.js`: JS performance tests +3. `protractor protractor-perf-dart2js.conf.js`: Dart2JS performance tests + ### Examples: To see the examples, first build the project as described above. diff --git a/gulpfile.js b/gulpfile.js index 9d7225a095..a8c2ea0578 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -27,6 +27,18 @@ var _COMPILER_CONFIG_JS_DEFAULT = { modules: 'instantiate' }; +var CJS_COMPILER_OPTIONS = { + sourceMaps: true, + annotations: false, // parse annotations + types: false, // parse types + // TODO(tbosch): Right now, traceur generates imports that + // rely on absolute paths. This is why we are not using this... + script: true, // parse as a script + memberVariables: false, // parse class fields + typeAssertions: false, + modules: null // not needed +}; + var _HTLM_DEFAULT_SCRIPTS_JS = [ {src: '/deps/traceur-runtime.js', mimeType: 'text/javascript'}, {src: '/rtts_assert/lib/rtts_assert.js', mimeType: 'text/javascript'}, @@ -51,7 +63,12 @@ var CONFIG = { prod: 'dist/js/prod', dart2js: 'dist/js/dart2js' }, - dart: 'dist/dart' + dart: 'dist/dart', + cjs: { + all: 'dist/cjs', + tools: 'dist/cjs/tools', + e2eTest: 'dist/cjs/e2e_test' + } }, srcFolderMapping: { 'default': 'lib', @@ -72,12 +89,20 @@ var CONFIG = { }, transpile: { src: { - js: ['modules/**/*.js', 'modules/**/*.es6', '!modules/**/perf/**/*'], - dart: ['modules/**/*.js', '!modules/**/perf/**/*'] + js: ['modules/**/*.js', 'modules/**/*.es6', '!modules/**/e2e_test/**'], + dart: ['modules/**/*.js', '!modules/**/e2e_test/**'], + cjs: { + tools: ['tools/**/*.es6', '!tools/transpiler/**'], + e2eTest: ['modules/**/e2e_test/**/*.es6'] + } }, copy: { - js: ['modules/**/*.es5', '!modules/**/perf/**/*'], - dart: ['modules/**/*.dart', '!modules/**/perf/**/*'] + js: ['modules/**/*.es5', '!modules/**/e2e_test/**'], + dart: ['modules/**/*.dart', '!modules/**/e2e_test/**'], + cjs: { + tools: ['tools/**/*.es5', '!tools/transpiler/**'], + e2eTest: ['modules/**/e2e_test/**/*.es5'] + } }, options: { js: { @@ -96,7 +121,8 @@ var CONFIG = { script: false, // parse as a module memberVariables: true, // parse class fields outputLanguage: 'dart' - } + }, + cjs: CJS_COMPILER_OPTIONS } }, html: { @@ -134,6 +160,11 @@ gulp.task('build/clean.dart', clean(gulp, gulpPlugins, { path: CONFIG.dest.dart })); +gulp.task('build/clean.cjs', clean(gulp, gulpPlugins, { + path: CONFIG.dest.cjs.all +})); + + // ------------ // deps @@ -177,6 +208,28 @@ gulp.task('build/transpile.dart', transpile(gulp, gulpPlugins, { srcFolderMapping: CONFIG.srcFolderMapping })); +gulp.task('build/transpile/tools.cjs', transpile(gulp, gulpPlugins, { + src: CONFIG.transpile.src.cjs.tools, + copy: CONFIG.transpile.copy.cjs.tools, + dest: CONFIG.dest.cjs.tools, + outputExt: 'js', + options: CONFIG.transpile.options.cjs, + srcFolderMapping: { + 'default': 'src' + } +})); + +gulp.task('build/transpile/e2eTest.cjs', transpile(gulp, gulpPlugins, { + src: CONFIG.transpile.src.cjs.e2eTest, + copy: CONFIG.transpile.copy.cjs.e2eTest, + dest: CONFIG.dest.cjs.e2eTest, + outputExt: 'js', + options: CONFIG.transpile.options.cjs, + srcFolderMapping: { + 'default': 'src' + } +})); + // ------------ // html @@ -339,8 +392,14 @@ gulp.task('build.js.prod', function() { ); }); +gulp.task('build.cjs', function() { + return runSequence( + ['build/transpile/tools.cjs', 'build/transpile/e2eTest.cjs'] + ); +}); + gulp.task('build.js', ['build.js.dev', 'build.js.prod']); -gulp.task('clean', ['build/clean.js', 'build/clean.dart']); +gulp.task('clean', ['build/clean.js', 'build/clean.dart', 'build/clean.cjs']); -gulp.task('build', ['build.js', 'build.dart']); +gulp.task('build', ['build.js', 'build.dart', 'build.cjs']); diff --git a/modules/benchmarks/test/perf/change_detection_perf.js b/modules/benchmarks/e2e_test/change_detection_perf.es6 similarity index 93% rename from modules/benchmarks/test/perf/change_detection_perf.js rename to modules/benchmarks/e2e_test/change_detection_perf.es6 index 315b02dc6c..442b11dbad 100644 --- a/modules/benchmarks/test/perf/change_detection_perf.js +++ b/modules/benchmarks/e2e_test/change_detection_perf.es6 @@ -1,5 +1,5 @@ "use strict"; -var benchpress = require('../../../../tools/benchpress/benchpress.js'); +var benchpress = require('../../../tools/benchpress/index.js'); describe('ng2 change detection benchmark', function () { diff --git a/modules/benchmarks/test/perf/compiler_perf.js b/modules/benchmarks/e2e_test/compiler_perf.es6 similarity index 93% rename from modules/benchmarks/test/perf/compiler_perf.js rename to modules/benchmarks/e2e_test/compiler_perf.es6 index f3e5da3113..e01259efef 100644 --- a/modules/benchmarks/test/perf/compiler_perf.js +++ b/modules/benchmarks/e2e_test/compiler_perf.es6 @@ -1,5 +1,5 @@ "use strict"; -var benchpress = require('../../../../tools/benchpress/benchpress.js'); +var benchpress = require('../../../tools/benchpress/index.js'); describe('ng2 compiler benchmark', function () { diff --git a/modules/benchmarks/test/perf/di_perf.js b/modules/benchmarks/e2e_test/di_perf.es6 similarity index 95% rename from modules/benchmarks/test/perf/di_perf.js rename to modules/benchmarks/e2e_test/di_perf.es6 index cb289d4a0e..b07809bfe1 100644 --- a/modules/benchmarks/test/perf/di_perf.js +++ b/modules/benchmarks/e2e_test/di_perf.es6 @@ -1,5 +1,5 @@ "use strict"; -var benchpress = require('../../../../tools/benchpress/benchpress.js'); +var benchpress = require('../../../tools/benchpress/index.js'); describe('ng2 di benchmark', function () { diff --git a/modules/benchmarks/test/perf/element_injector_perf.js b/modules/benchmarks/e2e_test/element_injector_perf.es6 similarity index 94% rename from modules/benchmarks/test/perf/element_injector_perf.js rename to modules/benchmarks/e2e_test/element_injector_perf.es6 index 50a2a017b5..de69facba1 100644 --- a/modules/benchmarks/test/perf/element_injector_perf.js +++ b/modules/benchmarks/e2e_test/element_injector_perf.es6 @@ -1,5 +1,5 @@ "use strict"; -var benchpress = require('../../../../tools/benchpress/benchpress.js'); +var benchpress = require('../../../tools/benchpress/index.js'); describe('ng2 element injector benchmark', function () { diff --git a/modules/benchmarks/test/perf/tree_perf.js b/modules/benchmarks/e2e_test/tree_perf.es6 similarity index 93% rename from modules/benchmarks/test/perf/tree_perf.js rename to modules/benchmarks/e2e_test/tree_perf.es6 index 2ee6fd5c43..f1ee059ebd 100644 --- a/modules/benchmarks/test/perf/tree_perf.js +++ b/modules/benchmarks/e2e_test/tree_perf.es6 @@ -1,5 +1,5 @@ "use strict"; -var benchpress = require('../../../../tools/benchpress/benchpress.js'); +var benchpress = require('../../../tools/benchpress/index.js'); describe('ng2 tree benchmark', function () { diff --git a/modules/benchmarks_external/test/perf/compiler_perf.js b/modules/benchmarks_external/e2e_test/compiler_perf.es6 similarity index 93% rename from modules/benchmarks_external/test/perf/compiler_perf.js rename to modules/benchmarks_external/e2e_test/compiler_perf.es6 index 9ce85e385c..b149e86c7a 100644 --- a/modules/benchmarks_external/test/perf/compiler_perf.js +++ b/modules/benchmarks_external/e2e_test/compiler_perf.es6 @@ -1,5 +1,5 @@ "use strict"; -var benchpress = require('../../../../tools/benchpress/benchpress.js'); +var benchpress = require('../../../tools/benchpress/index.js'); describe('ng1.x compiler benchmark', function () { diff --git a/modules/benchmarks_external/test/perf/tree_perf.js b/modules/benchmarks_external/e2e_test/tree_perf.es6 similarity index 92% rename from modules/benchmarks_external/test/perf/tree_perf.js rename to modules/benchmarks_external/e2e_test/tree_perf.es6 index 7966e5a1dc..ce2adf2af5 100644 --- a/modules/benchmarks_external/test/perf/tree_perf.js +++ b/modules/benchmarks_external/e2e_test/tree_perf.es6 @@ -1,5 +1,5 @@ "use strict"; -var benchpress = require('../../../../tools/benchpress/benchpress.js'); +var benchpress = require('../../../tools/benchpress/index.js'); describe('ng1.x tree benchmark', function () { diff --git a/protractor-perf-shared.js b/protractor-perf-shared.js index 550a11f2ba..4436f428b8 100644 --- a/protractor-perf-shared.js +++ b/protractor-perf-shared.js @@ -1,6 +1,9 @@ +// load traceur runtime as our tests are written in es6 +require('traceur/bin/traceur-runtime.js'); + var config = exports.config = { - specs: ['modules/*/test/**/*_perf.js'], + specs: ['dist/cjs/**/*_perf.js'], params: { timeBenchmark: { diff --git a/tools/benchpress/benchpress.js b/tools/benchpress/index.es6 similarity index 58% rename from tools/benchpress/benchpress.js rename to tools/benchpress/index.es6 index ef33d0657f..ded2d8d211 100644 --- a/tools/benchpress/benchpress.js +++ b/tools/benchpress/index.es6 @@ -1,5 +1,5 @@ -var timeBenchmark = require('./time_benchmark'); -var tools = require('./tools'); +var timeBenchmark = require('./src/time_benchmark'); +var tools = require('./src/tools'); module.exports = { runTimeBenchmark: timeBenchmark.runTimeBenchmark, diff --git a/tools/benchpress/commands.js b/tools/benchpress/src/commands.es6 similarity index 100% rename from tools/benchpress/commands.js rename to tools/benchpress/src/commands.es6 diff --git a/tools/benchpress/reporter.js b/tools/benchpress/src/reporter.es6 similarity index 100% rename from tools/benchpress/reporter.js rename to tools/benchpress/src/reporter.es6 diff --git a/tools/benchpress/stats.js b/tools/benchpress/src/stats.es6 similarity index 100% rename from tools/benchpress/stats.js rename to tools/benchpress/src/stats.es6 diff --git a/tools/benchpress/time_benchmark.js b/tools/benchpress/src/time_benchmark.es6 similarity index 100% rename from tools/benchpress/time_benchmark.js rename to tools/benchpress/src/time_benchmark.es6 diff --git a/tools/benchpress/tools.js b/tools/benchpress/src/tools.es6 similarity index 100% rename from tools/benchpress/tools.js rename to tools/benchpress/src/tools.es6 diff --git a/tools/build/benchpress.js b/tools/build/benchpress.js new file mode 100644 index 0000000000..7ccbbc923e --- /dev/null +++ b/tools/build/benchpress.js @@ -0,0 +1,6 @@ +module.exports = function(gulp, plugins, config) { + return function(done) { + del(config.path, done); + }; +}; +