mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
make protractor tests work
This commit is contained in:
110
gulpfile.js
110
gulpfile.js
@@ -85,7 +85,6 @@ gulp.task('e2e', ['ionic-js', 'sass'], function() {
|
||||
var indexContents = _.template( fs.readFileSync('scripts/e2e/index.template.html') )({
|
||||
buildConfig: buildConfig
|
||||
});
|
||||
var platformJsTemplate = _.template( fs.readFileSync('scripts/e2e/platform.template.js') )
|
||||
var testTemplate = _.template( fs.readFileSync('scripts/e2e/e2e.template.js') )
|
||||
|
||||
var platforms = [
|
||||
@@ -94,76 +93,47 @@ gulp.task('e2e', ['ionic-js', 'sass'], function() {
|
||||
'ios',
|
||||
]
|
||||
|
||||
return gulp.src(buildConfig.src.e2eTest)
|
||||
.pipe(through2.obj(function(file, enc, next) {
|
||||
var self = this
|
||||
gulp.src(file.path + '/**/*', {
|
||||
base: file.path
|
||||
})
|
||||
.pipe(gulpif(/main.html$/, processMainHtml()))
|
||||
.on('data', function(file) {
|
||||
if (file.stat && !file.stat.isFile()) return;
|
||||
|
||||
file.path = file.path.replace(/(\\|\/)test/, '')
|
||||
file.base = path.join(__dirname, 'src', 'components');
|
||||
var dirname = path.dirname(file.path)
|
||||
var basename = path.basename(file.path);
|
||||
|
||||
platforms.forEach(function(platform) {
|
||||
var platformDir = dirname + '-' + platform;
|
||||
var platformFilePath = file.path.replace(dirname, platformDir);
|
||||
self.push(new VinylFile({
|
||||
path: platformFilePath,
|
||||
base: file.base,
|
||||
contents: file.contents.slice()
|
||||
}));
|
||||
|
||||
// Add a new platform.js file beside each index.html
|
||||
if (basename === 'index.html') {
|
||||
self.push(new VinylFile({
|
||||
path: platformFilePath.replace(/index.html$/, 'platform.js'),
|
||||
base: file.base,
|
||||
contents: new Buffer(platformJsTemplate({
|
||||
platform: platform
|
||||
}))
|
||||
}))
|
||||
}
|
||||
})
|
||||
})
|
||||
.on('end', next)
|
||||
|
||||
function processMainHtml() {
|
||||
return through2.obj(function(file, enc, next) {
|
||||
this.push(new VinylFile({
|
||||
base: file.base,
|
||||
contents: new Buffer(indexContents),
|
||||
path: file.path.replace(/main.html$/, 'index.html'),
|
||||
}))
|
||||
next(null, file)
|
||||
})
|
||||
}
|
||||
// Get each test folder with gulp.src
|
||||
return gulp.src(buildConfig.src.e2e)
|
||||
.pipe(rename(function(file) {
|
||||
file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
|
||||
}))
|
||||
.pipe(gulp.dest(buildConfig.dist + '/e2e'));
|
||||
// .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 relativePath = path.dirname(file.path.replace(/^.*?src.components/, ''))
|
||||
// var contents = file.contents.toString()
|
||||
// contents = testTemplate({
|
||||
// contents: contents,
|
||||
// buildConfig: buildConfig,
|
||||
// relativePath: relativePath
|
||||
// })
|
||||
// file.contents = new Buffer(contents)
|
||||
// next(null, file)
|
||||
// })))
|
||||
// .pipe(gulpif({ isFile: true }, gulp.dest(buildConfig.dist + '/e2e')))
|
||||
.pipe(gulpif(/main.html$/, processMainHtml()))
|
||||
.pipe(gulpif(/e2e.js$/, createPlatformTests()))
|
||||
.pipe(gulp.dest(buildConfig.dist + '/e2e'))
|
||||
|
||||
function processMainHtml() {
|
||||
return through2.obj(function(file, enc, next) {
|
||||
this.push(new VinylFile({
|
||||
base: file.base,
|
||||
contents: new Buffer(indexContents),
|
||||
path: file.path.replace(/main.html$/, '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(/^.*?src(\/|\\)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()
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
// Take es6 files from angular2's output, rename to js, and move to dist/lib/
|
||||
|
||||
@@ -4,7 +4,6 @@ module.exports = {
|
||||
src: {
|
||||
spec: ['src/**/test/*.spec.js'],
|
||||
js: ['src/**/*.js', '!src/**/test/**/*.js'],
|
||||
e2eTest: ['src/components/*/test/*/'],
|
||||
e2e: ['src/components/*/test/*/**/*'],
|
||||
html: 'src/**/*.html',
|
||||
scss: 'src/components/**/*.scss',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
describe('<%= relativePath %>', function() {
|
||||
describe('<%= relativePath %>: <%= platform %>', function() {
|
||||
|
||||
it('should init', function() {
|
||||
browser.get('http://localhost:<%= buildConfig.protractorPort %>/<%= relativePath %>');
|
||||
browser.get('http://localhost:<%= buildConfig.protractorPort %>/e2e/<%= relativePath %>?ionic-platform=<%= platform %>');
|
||||
});
|
||||
|
||||
<%= contents %>
|
||||
|
||||
@@ -18,14 +18,9 @@
|
||||
'rx/dist/rx.all': 'rx.all',
|
||||
}
|
||||
})
|
||||
System.import('app/main');
|
||||
</script>
|
||||
<script src="platform.js"></script>
|
||||
</head>
|
||||
<body ion-app>
|
||||
</body>
|
||||
<script>
|
||||
System.import('app/main');
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
//TODO find a better override than window
|
||||
window.IONIC_PLATFORM = '<%= platform %>';
|
||||
@@ -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.
|
||||
|
||||
@@ -18,7 +18,7 @@ module.exports = function(gulp, argv, buildConfig) {
|
||||
console.log('Serving `dist` on http://localhost:' + buildConfig.protractorPort);
|
||||
});
|
||||
|
||||
gulp.task('snapshot', ['e2e', 'protractor-server'], function(done) {
|
||||
gulp.task('snapshot', ['build', 'protractor-server'], function(done) {
|
||||
var protractorConfigFile = path.resolve(projectRoot, 'scripts/snapshot/protractor.config.js');
|
||||
snapshot(done, protractorConfigFile);
|
||||
});
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
}
|
||||
|
||||
.checkbox[aria-disabled=true] {
|
||||
pointer-events: none;
|
||||
opacity: 0.5;
|
||||
color: gray;
|
||||
|
||||
@@ -35,8 +34,3 @@
|
||||
color: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
.checkbox .item-media,
|
||||
.checkbox .item-content {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
1
src/components/checkbox/test/basic/e2e.js
Normal file
1
src/components/checkbox/test/basic/e2e.js
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export function run() {
|
||||
}
|
||||
@@ -1,70 +1,77 @@
|
||||
import * as util from 'ionic2/util';
|
||||
import * as util from 'ionic2/util'
|
||||
|
||||
const queryPlatform = (util.readQueryParams()['ionic-platform'] || '').toLowerCase()
|
||||
|
||||
class Platform {
|
||||
constructor(options) {
|
||||
util.extend(this, options);
|
||||
util.extend(this, options)
|
||||
}
|
||||
}
|
||||
|
||||
class PlatformController {
|
||||
current: Platform;
|
||||
constructor() {
|
||||
this.registry = [];
|
||||
this.registry = []
|
||||
}
|
||||
|
||||
set(platform) {
|
||||
this.current = platform;
|
||||
this.current = platform
|
||||
}
|
||||
|
||||
get() {
|
||||
return this.current;
|
||||
return this.current
|
||||
}
|
||||
|
||||
register(platform) {
|
||||
if (!platform instanceof Platform) {
|
||||
platform = new Platform(platform);
|
||||
}
|
||||
this.registry.push(platform);
|
||||
if (!platform instanceof Platform) platform = new Platform(platform)
|
||||
this.registry.push(platform)
|
||||
}
|
||||
|
||||
setDefaultPlatform(platform) {
|
||||
if (!platform instanceof Platform) platform = new Platform(platform)
|
||||
this.defaultPlatform = platform
|
||||
}
|
||||
|
||||
isRegistered(platformName) {
|
||||
return this.registry.some(platform => {
|
||||
return platform.name === platformName;
|
||||
});
|
||||
return platform.name === platformName
|
||||
})
|
||||
}
|
||||
|
||||
detect() {
|
||||
for (let platform of this.registry) {
|
||||
if (platform.matcher()) {
|
||||
return platform;
|
||||
return platform
|
||||
}
|
||||
}
|
||||
return this.defaultPlatform
|
||||
}
|
||||
}
|
||||
|
||||
export let platform = new PlatformController();
|
||||
export let platform = new PlatformController()
|
||||
|
||||
// TODO(ajoslin): move this to a facade somewhere else?
|
||||
var ua = window.navigator.userAgent;
|
||||
var ua = window.navigator.userAgent
|
||||
|
||||
// TODO(ajoslin): move these to their own files
|
||||
platform.register({
|
||||
name: 'android',
|
||||
matcher() {
|
||||
//TODO Make a better override than window
|
||||
return window.IONIC_PLATFORM == 'android' || /android/i.test(ua);
|
||||
return queryPlatform == 'android' || /android/i.test(ua)
|
||||
}
|
||||
});
|
||||
})
|
||||
platform.register({
|
||||
name: 'ios',
|
||||
// For now always default to ios
|
||||
matcher() {
|
||||
return window.IONIC_PLATFORM === 'ios' || /ipad|iphone|ipod/i.test(ua);
|
||||
return queryPlatform === 'ios' || /ipad|iphone|ipod/i.test(ua)
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
// Last case is a catch-all
|
||||
platform.register({
|
||||
name: 'default',
|
||||
matcher() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
platform.setDefaultPlatform({
|
||||
name: 'default'
|
||||
})
|
||||
|
||||
|
||||
platform.set( platform.detect() );
|
||||
platform.set( platform.detect() )
|
||||
|
||||
29
src/util.js
29
src/util.js
@@ -28,10 +28,10 @@ export function defaults(dest) {
|
||||
return dest;
|
||||
}
|
||||
|
||||
export let isString = val => typeof val === 'string';
|
||||
export let isFunction = val => typeof val === 'function';
|
||||
export let isDefined = val => typeof val === 'undefined';
|
||||
export let isObject = val => typeof val === 'object';
|
||||
export let isString = val => typeof val === 'string'
|
||||
export let isFunction = val => typeof val === 'function'
|
||||
export let isDefined = val => typeof val === 'undefined'
|
||||
export let isObject = val => typeof val === 'object'
|
||||
|
||||
export function pascalCaseToDashCase(str = '') {
|
||||
return str.charAt(0).toLowerCase() + str.substring(1).replace(/[A-Z]/g, match => {
|
||||
@@ -42,10 +42,10 @@ export function pascalCaseToDashCase(str = '') {
|
||||
export let array = {
|
||||
unique(array) {
|
||||
return array.filter((value, index) => {
|
||||
return array.indexOf(value) === index;
|
||||
});
|
||||
return array.indexOf(value) === index
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export class Log {
|
||||
static log(...args) {
|
||||
@@ -64,3 +64,18 @@ export class Log {
|
||||
console.error.apply(console, args)
|
||||
}
|
||||
}
|
||||
|
||||
export function readQueryParams() {
|
||||
var queryParams = {}
|
||||
const startIndex = window.location.href.indexOf('?')
|
||||
if (startIndex !== -1) {
|
||||
const queries = window.location.href.slice(startIndex + 1).split('&')
|
||||
if (queries.length) {
|
||||
queries.forEach((param) => {
|
||||
var split = param.split('=')
|
||||
queryParams[split[0]] = split[1]
|
||||
})
|
||||
}
|
||||
}
|
||||
return queryParams
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user