From 013e94d5b24c7da120de9f28d7d10254789e8c96 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 27 Mar 2015 13:28:17 -0600 Subject: [PATCH] make snapshot e2e tests work, except main.js/main.html only --- gulpfile.js | 50 ++++++++++++++----- package.json | 1 + scripts/build/config.js | 2 +- scripts/e2e/e2e.template.js | 9 ++++ scripts/e2e/index.template.html | 1 - scripts/snapshot/protractor.config.js | 20 +++++++- src/components/aside/test/basic/index.html | 1 - src/components/aside/test/basic/main.js | 6 +-- .../button/test/button-block/test.e2e.js | 0 .../button/test/button-block/test.scenario.js | 6 --- 10 files changed, 70 insertions(+), 26 deletions(-) create mode 100644 scripts/e2e/e2e.template.js delete mode 100644 src/components/aside/test/basic/index.html create mode 100644 src/components/button/test/button-block/test.e2e.js delete mode 100644 src/components/button/test/button-block/test.scenario.js diff --git a/gulpfile.js b/gulpfile.js index 6cad7bace1..3f1a9cfa5e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,12 +2,15 @@ // Mostly stolen from https://github.com/pkozlowski-opensource/ng2-play ///// +var _ = require('lodash'); +var buildConfig = require('./scripts/build/config') var SystemJsBuilder = require('systemjs-builder') var exec = require('child_process').exec +var fs = require('fs'); var gulp = require('gulp') var karma = require('karma').server var path = require('path') -var buildConfig = require('./scripts/build/config') +var VinylFile = require('vinyl'); var argv = require('yargs').argv var concat = require('gulp-concat') @@ -21,7 +24,8 @@ var sass = require('gulp-sass') var shell = require('gulp-shell') var through2 = require('through2') var traceur = require('gulp-traceur') -var wrap = require('gulp-wrap') + +require('./scripts/snapshot/snapshot.task')(gulp, argv, buildConfig) gulp.task('default', ['build', 'lib', 'e2e']) @@ -75,23 +79,43 @@ gulp.task('clean', function(done) { }) gulp.task('e2e', ['build'], function() { - var e2eSrc = path.join(__dirname, 'src/components/**/test/**/*') - var templateSrc = path.join(__dirname, 'scripts/e2e/index.template.html') - var e2eDest = path.join(__dirname, 'dist/e2e/') + var indexContents = _.template( fs.readFileSync('scripts/e2e/index.template.html') )({ + buildConfig: buildConfig + }) + var testTemplate = _.template( fs.readFileSync('scripts/e2e/e2e.template.js') ) - return gulp.src(e2eSrc) - .pipe(gulpif(/index.html/, wrap( - { src: templateSrc }, - { buildConfig: buildConfig } - ))) + function wrapContents(file, template, data) { + var contents = file.contents.toString(); + contents = template(_.defaults(data || {}, { + contents: contents, + buildConfig: buildConfig, + })) + file.contents = new Buffer(contents); + } + + return gulp.src(buildConfig.src.e2e) .pipe(rename(function(file) { file.dirname = file.dirname.replace('/test/', '/') })) - .pipe(gulpif({ isFile: true }, gulp.dest(e2eDest))) + .pipe(gulpif(/main.html$/, through2.obj(function(file, enc, next) { + var indexClone = _.clone(file); + this.push(new VinylFile(_.assign(indexClone, { + contents: new Buffer(indexContents), + path: file.path.replace(/main.html$/, 'index.html'), + }))) + next(null, file) + }))) + .pipe(gulpif(/.e2e.js$/, through2.obj(function(file, enc, next) { + var basename = path.basename(file); + var relativePath = path.dirname(file.path.replace(/^.*?src.components/, '')) + wrapContents(file, testTemplate, { + relativePath: relativePath, + }); + next(null, file); + }))) + .pipe(gulpif({ isFile: true }, gulp.dest(buildConfig.dist + '/e2e'))) }) -require('./scripts/snapshot/snapshot.task')(gulp, argv, buildConfig) - // Take es6 files from angular2's output, rename to js, and move to dist/lib/ gulp.task('ng2-rename', function(done) { exec('test -e node_modules/angular-master', function(err) { diff --git a/package.json b/package.json index 992d4d370a..9ea5ab87b8 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "systemjs": "^0.11.3", "systemjs-builder": "^0.9.1", "traceur-runtime": "0.0.59", + "vinyl": "^0.4.6", "yargs": "^3.6.0" }, "dependencies": { diff --git a/scripts/build/config.js b/scripts/build/config.js index b6d00bdb0c..86513d7fb9 100644 --- a/scripts/build/config.js +++ b/scripts/build/config.js @@ -4,7 +4,7 @@ module.exports = { src: { test: ['src/**/test/*.spec.js'], js: ['src/**/*.js', '!src/**/test/**/*.js'], - e2e: ['src/**/test/*/**/*'], + e2e: ['src/components/*/test/*/**/*'], html: 'src/**/*.html', scss: 'src/components/**/*.scss', }, diff --git a/scripts/e2e/e2e.template.js b/scripts/e2e/e2e.template.js new file mode 100644 index 0000000000..575ea9ee97 --- /dev/null +++ b/scripts/e2e/e2e.template.js @@ -0,0 +1,9 @@ +describe('<%= relativePath %>', function() { + +it('should init', function() { + browser.get('http://localhost:<%= buildConfig.protractorPort %>/<%= relativePath %>'); +}); + +<%= contents %> + +}); diff --git a/scripts/e2e/index.template.html b/scripts/e2e/index.template.html index 6ac009cd00..390939f13f 100644 --- a/scripts/e2e/index.template.html +++ b/scripts/e2e/index.template.html @@ -21,7 +21,6 @@ - <%= contents %>