From f796deb58117f5b9cfab847f246fb2edf2a3dae5 Mon Sep 17 00:00:00 2001 From: Tim Lancina Date: Mon, 20 Jul 2015 14:25:14 -0500 Subject: [PATCH] snapshot --- gulpfile.js | 96 ++++++++++++++++++++++++++++++- package.json | 2 + scripts/e2e/e2e.template.js | 2 +- scripts/snapshot/snapshot.task.js | 2 +- 4 files changed, 99 insertions(+), 3 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 115d35810e..fac7d809af 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -260,6 +260,100 @@ gulp.task('examples', function() { } }); +var e2eBabelOptions = { + optional: ['es7.decorators'], + modules: "system", + moduleIds: true, + getModuleId: function(name) { + return "dist/e2e/" + name.split('/test').join(''); + } +}; + +gulp.task('e2e', function() { + var buildTest = lazypipe() + //.pipe(traceur, traceurOptions) + .pipe(tsc, tscOptions, null, tscReporter) + .pipe(babel, e2eBabelOptions) + + var buildE2ETest = lazypipe() + //.pipe(traceur, traceurOptions) + .pipe(tsc, tscOptions, null, tscReporter) + .pipe(babel) + + var indexTemplate = _.template( + fs.readFileSync('scripts/e2e/ionic.template.html') + )({ + buildConfig: buildConfig + + }) + var testTemplate = _.template( fs.readFileSync('scripts/e2e/e2e.template.js') ) + + var platforms = [ + 'android', + 'core', + 'ios', + ]; + + // Get each test folder with gulp.src + return gulp.src(['ionic/components/*/test/*/**/*', '!ionic/components/*/test/*/**/*.spec.ts']) + .pipe(cache('e2e', { optimizeMemory: true })) + .pipe(gulpif(/e2e.ts$/, buildE2ETest())) + .pipe(gulpif(/.ts$/, buildTest())) + .on('error', function (err) { + console.log("ERROR: " + err.message); + this.emit('end'); + }) + .pipe(gulpif(/index.js$/, createIndexHTML())) //TSC changes .ts to .js + .pipe(rename(function(file) { + file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep) + })) + .pipe(gulpif(/e2e.js$/, createPlatformTests())) + .pipe(gulp.dest('dist/e2e/')) + + function createIndexHTML() { + return through2.obj(function(file, enc, next) { + var self = this; + + var module = path.dirname(file.path) + .replace(__dirname, '') + .replace('/ionic/components/', 'dist/e2e/') + .replace('/test/', '/') + + '/index'; + + var indexContents = indexTemplate.replace('{{MODULE}}', module); + + self.push(new VinylFile({ + base: file.base, + contents: new Buffer(indexContents), + path: path.join(path.dirname(file.path), 'index.html'), + })); + next(null, file); + }); + } + + function createPlatformTests(file) { + return through2.obj(function(file, enc, next) { + var self = this + var relativePath = path.dirname(file.path.replace(/^.*?ionic(\/|\\)components(\/|\\)/, '')) + var contents = file.contents.toString() + platforms.forEach(function(platform) { + var platformContents = testTemplate({ + contents: contents, + buildConfig: buildConfig, + relativePath: relativePath, + platform: platform + }) + self.push(new VinylFile({ + base: file.base, + contents: new Buffer(platformContents), + path: file.path.replace(/e2e.js$/, platform + '.e2e.js') + })) + }) + next() + }) + } +}); + gulp.task('sass', function() { return gulp.src('ionic/ionic.scss') .pipe(sass({ @@ -293,7 +387,7 @@ gulp.task('karma-watch', function() { return karma.start({ configFile: __dirname + '/scripts/test/karma-watch.conf.js' }) }); -gulp.task('e2e', ['sass'], function() { +gulp.task('e2e.old', ['sass'], function() { var indexContents = _.template( fs.readFileSync('scripts/e2e/index.template.html') )({ buildConfig: buildConfig }); diff --git a/package.json b/package.json index f2cd6b5564..56945aa85f 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "gulp-sass": "^1.3.3", "gulp-shell": "^0.4.0", "gulp-typescript": "^2.7.7", + "gulp-util": "^3.0.6", "gulp-watch": "^4.2.4", "gulp-wrap": "^0.11.0", "karma": "^0.12.31", @@ -27,6 +28,7 @@ "lodash": "^2.4.1", "node-libs-browser": "^0.5.2", "node-uuid": "^1.4.1", + "q": "^1.4.1", "request": "^2.53.0", "run-sequence": "^1.1.0", "serve-static": "^1.9.2", diff --git a/scripts/e2e/e2e.template.js b/scripts/e2e/e2e.template.js index 9e00cda641..08293aca21 100644 --- a/scripts/e2e/e2e.template.js +++ b/scripts/e2e/e2e.template.js @@ -1,7 +1,7 @@ describe('<%= relativePath %>: <%= platform %>', function() { it('should init', function() { - browser.get('http://localhost:<%= buildConfig.protractorPort %>/e2e/<%= relativePath %>/index.html?ionicplatform=<%= platform %>'); + browser.get('http://localhost:<%= buildConfig.protractorPort %>/dist/e2e/<%= relativePath %>/index.html?ionicplatform=<%= platform %>'); }); <%= contents %> diff --git a/scripts/snapshot/snapshot.task.js b/scripts/snapshot/snapshot.task.js index 5fb111992c..8babda7965 100644 --- a/scripts/snapshot/snapshot.task.js +++ b/scripts/snapshot/snapshot.task.js @@ -15,7 +15,7 @@ module.exports = function(gulp, argv, buildConfig) { var snapshotValues = _.merge(snapshotConfig.platformDefauls, argv); gulp.task('protractor-server', function() { - var app = connect().use(serveStatic(projectRoot + '/' + buildConfig.dist)); // serve everything that is static + var app = connect().use(serveStatic(projectRoot)); // serve everything that is static protractorHttpServer = http.createServer(app).listen(buildConfig.protractorPort); console.log('Serving `dist` on http://localhost:' + buildConfig.protractorPort); });