This commit is contained in:
Wei Wei 2016-08-23 16:48:47 +08:00
Родитель 7636ca9ab0
Коммит 4529adf3a5
7 изменённых файлов: 86 добавлений и 44 удалений

Просмотреть файл

@ -14,6 +14,7 @@ var del = require('del');
// coveralls
var coveralls = require('gulp-coveralls');
// coveralls-end
var jsdoc = require('gulp-jsdoc3');
function webpackBuild(configFilePath) {
return function (cb) {
@ -50,37 +51,13 @@ gulp.task('download-selenium', function (cb) {
function startSeleniumServer() {
var filePath = getSeleniumFilePath();
return childProcess.spawn('java', ['-jar', filePath], { stdio: 'inherit' });
return childProcess.spawn('java', ['-jar', filePath], {
stdio: 'inherit',
env: { path: path.join(__dirname, 'node_modules', '.bin') },
});
}
//
// Don't use Karma API for now
// For karma version 0.13.19 - 0.13.22, there's issue 1788
// -- Karma 0.13.19 taking long time to complete when run via gulp
// https://github.com/karma-runner/karma/issues/1788
// We should switch back to Karma API when the issue is fixed
//
// var Server = require('karma').Server;
//
gulp.task('test:unit', function (cb) {
var handler = function (code) {
if (code) {
cb(new Error('test failure'));
} else {
cb();
}
};
//
// Don't use Karma API for now
//
// new Server({
// configFile: path.join(__dirname, 'karma.conf.js'),
// singleRun: true,
// }, handler).start();
//
function testWithKarmaCmd(handler) {
var karmaCmd = path.resolve('./node_modules/.bin/karma');
if (process.platform === 'win32') {
@ -91,6 +68,27 @@ gulp.task('test:unit', function (cb) {
'start',
'--single-run',
], { stdio: 'inherit' }).on('close', handler);
}
/*
function testWithKarmaAPI(handler) {
var Server = require('karma').Server;
new Server({
configFile: path.join(__dirname, 'karma.conf.js'),
singleRun: true,
}, handler).start();
}
*/
gulp.task('test:unit', function (cb) {
var handler = function (code) {
if (code) {
cb(new Error('test failure'));
} else {
cb();
}
};
testWithKarmaCmd(handler);
});
// coveralls
@ -105,13 +103,18 @@ gulp.task('coveralls', ['test'], function () {
// coveralls-end
gulp.task('static', function () {
return gulp.src('**/*.js')
return gulp.src(['js/**/*.js', 'demos/**/*.js', 'spec/**/*.js'])
.pipe(excludeGitignore())
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('docs', function (cb) {
gulp.src(['README.md', './src/**/*.js'], { read: false })
.pipe(jsdoc(require('./jsdoc.json'), cb));
});
gulp.task('webpack', webpackBuild('./webpack.config'));
gulp.task('demos', function () {
@ -143,7 +146,7 @@ gulp.task('test:demos', ['download-selenium'], function (done) {
});
});
gulp.task('test', ['test:unit', 'test:demos']);
gulp.task('test', ['test:unit']);
gulp.task('prepublish', ['webpack']);
@ -160,7 +163,6 @@ gulp.task('clean', ['clean:build', 'clean:test']);
gulp.task('default', [
'static',
'webpack',
'examples',
// coveralls
'coveralls',
// coveralls-end

18
js/util.js Normal file
Просмотреть файл

@ -0,0 +1,18 @@
import _ from 'underscore';
export function parseSelector(selector) {
const classes = [];
const ids = [];
const regex = /([#\.])([^#\.]+)/g;
let match = null;
while ((match = regex.exec(selector)) !== null) {
if (match[1] === '#') {
ids.push(match[2]);
} else if (match[1] === '.') {
classes.push(match[2]);
}
}
return { classes, id: _.first(ids) };
}

Просмотреть файл

@ -5,13 +5,15 @@ function getWebpackConfig() {
var webpackConfig = _.omit(require('./webpack.config'), 'entry', 'externals');
_.defaults(webpackConfig, { module: {} });
webpackConfig.module.preLoaders = [
{
test: /\.js$/,
include: path.resolve('./js/'),
loader: 'istanbul-instrumenter',
},
].concat(webpackConfig.module.preLoaders || []);
webpackConfig.module.preLoaders = [{
test: /\.js$/,
include: path.resolve('./js/'),
loader: 'babel',
}, {
test: /\.js$/,
include: path.resolve('./js/'),
loader: 'isparta',
}].concat(webpackConfig.module.preLoaders || []);
return webpackConfig;
}
@ -35,7 +37,7 @@ module.exports = function (config) {
reporters: ['mocha', 'coverage'],
preprocessors: {
'speclist.js': ['webpack'],
'speclist.js': 'webpack',
},
webpack: getWebpackConfig(),
@ -49,8 +51,8 @@ module.exports = function (config) {
},
browsers: [
'PhantomJS',
// 'Chrome',
// 'PhantomJS',
'Firefox',
],
});
};

Просмотреть файл

@ -44,15 +44,18 @@
"gulp-eslint": "^3.0.1",
"gulp-exclude-gitignore": "^1.0.0",
"gulp-file": "^0.3.0",
"gulp-jsdoc3": "^0.3.0",
"gulp-util": "^3.0.7",
"imports-loader": "^0.6.5",
"isparta-loader": "^2.0.0",
"istanbul-instrumenter-loader": "^0.2.0",
"jade": "^1.11.0",
"jade-loader": "^0.8.0",
"jquery": "^3.1.0",
"jquery": "^2.2.4",
"karma": "^1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-firefox-launcher": "^1.0.0",
"karma-mocha": "^1.1.1",
"karma-mocha-reporter": "^2.1.0",
"karma-phantomjs-launcher": "^1.0.1",
@ -73,5 +76,10 @@
"webdriverio": "^4.2.7",
"webpack": "^1.13.2",
"webpack-stream": "^3.2.0"
},
"peerDependencies": {
"backbone": "^1.3.3",
"jquery": "^2.2.4",
"underscore": "^1.8.3"
}
}

Просмотреть файл

@ -2,6 +2,5 @@ var expect = require('chai').expect;
describe('backbone-toolbar', function () {
it('should have test cases', function () {
expect.fail();
});
});

13
spec/util.js Normal file
Просмотреть файл

@ -0,0 +1,13 @@
import chai from 'chai';
import { parseSelector } from '../js/util.js';
const expect = chai.expect;
describe('parseSelector', function () {
it('should parse classes correctly', function () {
const selector = '.foo.foo-bar';
const classes = ['foo', 'foo-bar'];
expect(parseSelector(selector)).to.deep.equal({ classes });
});
});

Просмотреть файл