make snapshot e2e tests work, except main.js/main.html only

This commit is contained in:
Andrew
2015-03-27 13:28:17 -06:00
parent b660777ffa
commit 013e94d5b2
10 changed files with 70 additions and 26 deletions

View File

@ -2,12 +2,15 @@
// Mostly stolen from https://github.com/pkozlowski-opensource/ng2-play // 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 SystemJsBuilder = require('systemjs-builder')
var exec = require('child_process').exec var exec = require('child_process').exec
var fs = require('fs');
var gulp = require('gulp') var gulp = require('gulp')
var karma = require('karma').server var karma = require('karma').server
var path = require('path') var path = require('path')
var buildConfig = require('./scripts/build/config') var VinylFile = require('vinyl');
var argv = require('yargs').argv var argv = require('yargs').argv
var concat = require('gulp-concat') var concat = require('gulp-concat')
@ -21,7 +24,8 @@ var sass = require('gulp-sass')
var shell = require('gulp-shell') var shell = require('gulp-shell')
var through2 = require('through2') var through2 = require('through2')
var traceur = require('gulp-traceur') var traceur = require('gulp-traceur')
var wrap = require('gulp-wrap')
require('./scripts/snapshot/snapshot.task')(gulp, argv, buildConfig)
gulp.task('default', ['build', 'lib', 'e2e']) gulp.task('default', ['build', 'lib', 'e2e'])
@ -75,23 +79,43 @@ gulp.task('clean', function(done) {
}) })
gulp.task('e2e', ['build'], function() { gulp.task('e2e', ['build'], function() {
var e2eSrc = path.join(__dirname, 'src/components/**/test/**/*') var indexContents = _.template( fs.readFileSync('scripts/e2e/index.template.html') )({
var templateSrc = path.join(__dirname, 'scripts/e2e/index.template.html') buildConfig: buildConfig
var e2eDest = path.join(__dirname, 'dist/e2e/') })
var testTemplate = _.template( fs.readFileSync('scripts/e2e/e2e.template.js') )
return gulp.src(e2eSrc) function wrapContents(file, template, data) {
.pipe(gulpif(/index.html/, wrap( var contents = file.contents.toString();
{ src: templateSrc }, contents = template(_.defaults(data || {}, {
{ buildConfig: buildConfig } contents: contents,
))) buildConfig: buildConfig,
}))
file.contents = new Buffer(contents);
}
return gulp.src(buildConfig.src.e2e)
.pipe(rename(function(file) { .pipe(rename(function(file) {
file.dirname = file.dirname.replace('/test/', '/') 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/ // Take es6 files from angular2's output, rename to js, and move to dist/lib/
gulp.task('ng2-rename', function(done) { gulp.task('ng2-rename', function(done) {
exec('test -e node_modules/angular-master', function(err) { exec('test -e node_modules/angular-master', function(err) {

View File

@ -23,6 +23,7 @@
"systemjs": "^0.11.3", "systemjs": "^0.11.3",
"systemjs-builder": "^0.9.1", "systemjs-builder": "^0.9.1",
"traceur-runtime": "0.0.59", "traceur-runtime": "0.0.59",
"vinyl": "^0.4.6",
"yargs": "^3.6.0" "yargs": "^3.6.0"
}, },
"dependencies": { "dependencies": {

View File

@ -4,7 +4,7 @@ module.exports = {
src: { src: {
test: ['src/**/test/*.spec.js'], test: ['src/**/test/*.spec.js'],
js: ['src/**/*.js', '!src/**/test/**/*.js'], js: ['src/**/*.js', '!src/**/test/**/*.js'],
e2e: ['src/**/test/*/**/*'], e2e: ['src/components/*/test/*/**/*'],
html: 'src/**/*.html', html: 'src/**/*.html',
scss: 'src/components/**/*.scss', scss: 'src/components/**/*.scss',
}, },

View File

@ -0,0 +1,9 @@
describe('<%= relativePath %>', function() {
it('should init', function() {
browser.get('http://localhost:<%= buildConfig.protractorPort %>/<%= relativePath %>');
});
<%= contents %>
});

View File

@ -21,7 +21,6 @@
</script> </script>
</head> </head>
<body ion-app> <body ion-app>
<%= contents %>
</body> </body>
<script> <script>
System.import('app/main'); System.import('app/main');

View File

@ -8,7 +8,7 @@ exports.config = {
// Spec patterns are relative to the location of the spec file. They may // Spec patterns are relative to the location of the spec file. They may
// include glob patterns. // include glob patterns.
specs: [ specs: [
path.resolve(projectRoot, 'dist/e2e/**/e2e.js'), path.resolve(projectRoot, 'dist/e2e/**/*.e2e.js'),
], ],
// Options to be passed to Jasmine-node. // Options to be passed to Jasmine-node.
@ -21,9 +21,27 @@ exports.config = {
baseUrl: 'http://localhost:' + buildConfig.protractorPort, baseUrl: 'http://localhost:' + buildConfig.protractorPort,
onPrepare: function() { onPrepare: function() {
beforeEach(function() {
patchProtractorWait(global.browser);
});
var snapshotConfig = require('./snapshot.config').config; var snapshotConfig = require('./snapshot.config').config;
var ionicSnapshot = require('./ionic.snapshot'); var ionicSnapshot = require('./ionic.snapshot');
ionicSnapshot(snapshotConfig); ionicSnapshot(snapshotConfig);
} }
}; };
// From https://github.com/angular/angular/blob/master/protractor-shared.js
// Disable waiting for Angular as we don't have an integration layer yet...
// TODO remove this once protractor supports angular2
function patchProtractorWait(browser) {
browser.ignoreSynchronization = true;
var _get = browser.get;
var sleepInterval = process.env.TRAVIS || process.env.JENKINS_URL ? 7000 : 3000;
browser.get = function() {
var result = _get.apply(this, arguments);
browser.sleep(sleepInterval);
return result;
}
}

View File

@ -1 +0,0 @@
<aside-app style="position:absolute; left:0;top:0;right:0;bottom:0;"></aside-app>

View File

@ -4,13 +4,13 @@ import {View} from 'ionic2/components/view/view';
import {Template, Component, bootstrap} from 'angular2/angular2'; import {Template, Component, bootstrap} from 'angular2/angular2';
@Component({ @Component({
selector: 'aside-app' selector: '[ion-app]'
}) })
@Template({ @Template({
directives: [Aside, Content, View], directives: [Aside, Content, View],
url: 'main.html' url: 'main.html'
}) })
class AsideApp { class App {
} }
bootstrap(AsideApp); bootstrap(App);

View File

@ -1,6 +0,0 @@
describe('Protractor Demo App', function() {
it('should just be', function() {
browser.get('http://localhost:8876/examples/button/button-block/');
});
});