mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
make snapshot e2e tests work, except main.js/main.html only
This commit is contained in:
50
gulpfile.js
50
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) {
|
||||
|
@ -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": {
|
||||
|
@ -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',
|
||||
},
|
||||
|
9
scripts/e2e/e2e.template.js
Normal file
9
scripts/e2e/e2e.template.js
Normal file
@ -0,0 +1,9 @@
|
||||
describe('<%= relativePath %>', function() {
|
||||
|
||||
it('should init', function() {
|
||||
browser.get('http://localhost:<%= buildConfig.protractorPort %>/<%= relativePath %>');
|
||||
});
|
||||
|
||||
<%= contents %>
|
||||
|
||||
});
|
@ -21,7 +21,6 @@
|
||||
</script>
|
||||
</head>
|
||||
<body ion-app>
|
||||
<%= contents %>
|
||||
</body>
|
||||
<script>
|
||||
System.import('app/main');
|
||||
|
@ -8,7 +8,7 @@ exports.config = {
|
||||
// Spec patterns are relative to the location of the spec file. They may
|
||||
// include glob patterns.
|
||||
specs: [
|
||||
path.resolve(projectRoot, 'dist/e2e/**/e2e.js'),
|
||||
path.resolve(projectRoot, 'dist/e2e/**/*.e2e.js'),
|
||||
],
|
||||
|
||||
// Options to be passed to Jasmine-node.
|
||||
@ -21,9 +21,27 @@ exports.config = {
|
||||
baseUrl: 'http://localhost:' + buildConfig.protractorPort,
|
||||
|
||||
onPrepare: function() {
|
||||
beforeEach(function() {
|
||||
patchProtractorWait(global.browser);
|
||||
});
|
||||
|
||||
var snapshotConfig = require('./snapshot.config').config;
|
||||
var ionicSnapshot = require('./ionic.snapshot');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
<aside-app style="position:absolute; left:0;top:0;right:0;bottom:0;"></aside-app>
|
@ -4,13 +4,13 @@ import {View} from 'ionic2/components/view/view';
|
||||
import {Template, Component, bootstrap} from 'angular2/angular2';
|
||||
|
||||
@Component({
|
||||
selector: 'aside-app'
|
||||
selector: '[ion-app]'
|
||||
})
|
||||
@Template({
|
||||
directives: [Aside, Content, View],
|
||||
url: 'main.html'
|
||||
})
|
||||
class AsideApp {
|
||||
class App {
|
||||
}
|
||||
|
||||
bootstrap(AsideApp);
|
||||
bootstrap(App);
|
||||
|
0
src/components/button/test/button-block/test.e2e.js
Normal file
0
src/components/button/test/button-block/test.e2e.js
Normal file
@ -1,6 +0,0 @@
|
||||
|
||||
describe('Protractor Demo App', function() {
|
||||
it('should just be', function() {
|
||||
browser.get('http://localhost:8876/examples/button/button-block/');
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user