Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Commit

Permalink
Use karma instead of gulp and jsdom
Browse files Browse the repository at this point in the history
  • Loading branch information
yuku committed Jun 28, 2016
1 parent 7d3a8e1 commit 1db95b5
Show file tree
Hide file tree
Showing 23 changed files with 201 additions and 159 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dist
karma.conf.js
lib
powered-test
src/doc
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ dist
lib
node_modules
npm-debug.log
powered-test
textcomplete
/textcomplete-*
npm-debug.log.*
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ coverage
doc
lib/main.js
npm-debug.log
powered-test
src
test
textcomplete
Expand Down
37 changes: 0 additions & 37 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,43 +56,6 @@ gulp.task('compile', ['browserify'], () => {
.pipe(gulp.dest(paths.dist));
});

gulp.task('lint', () => {
var eslint = require('gulp-eslint');
return gulp.src([paths.src, paths.test])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('istanbul', () => {
var isparta = require('isparta');
var istanbul = require('gulp-istanbul');
return gulp.src(paths.src)
.pipe(istanbul({
instrumenter: isparta.Instrumenter,
}))
.pipe(istanbul.hookRequire());
});

gulp.task('power-assert', () => {
require('babel-register');
var espower = require('gulp-espower');
return gulp.src(paths.test)
.pipe(espower())
.pipe(gulp.dest(paths.powered));
});

gulp.task('mocha', ['power-assert', 'istanbul'], () => {
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var path = require('path');
return gulp.src(path.join(paths.powered, paths.testrunner))
.pipe(mocha())
.pipe(istanbul.writeReports());
});

gulp.task('test', ['lint', 'mocha']);

gulp.task('server', () => {
return connect.server({ root: './', livereload: true });
});
Expand Down
57 changes: 57 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'browserify'],
browserify: {
transform: [
['babelify', {plugins: ['babel-plugin-espower']}]
]
},
client: {
mocha: {
// change Karma's debug.html to the mocha web reporter
reporter: 'html'
}
},
// list of files / patterns to load in the browser
files: [
'src/*.js',
'test/unit/*_spec.js'
],
// list of files to exclude
exclude: [
'src/doc/*.js'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'src/*.js': 'browserify',
'test/**/*_spec.js': 'browserify'
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['mocha'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
31 changes: 22 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"gh-release": "npm pack textcomplete && gh-release -a textcomplete-$(cat package.json|jq -r .version).tgz",
"prepare": "git tag v$(jq -r .version package.json) && gulp clean compile",
"start": "gulp server watch",
"test": "gulp test"
"test": "karma start"
},
"repository": {
"type": "git",
Expand All @@ -20,6 +20,7 @@
},
"homepage": "https://github.com/yuku-t/textcomplete#readme",
"devDependencies": {
"babel-plugin-espower": "^2.3.1",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.4.3",
"babelify": "^7.2.0",
Expand All @@ -30,30 +31,30 @@
"gulp": "^3.9.0",
"gulp-babel": "^6.1.2",
"gulp-connect": "^2.3.1",
"gulp-eslint": "^1.1.1",
"gulp-espower": "^1.0.2",
"gulp-gh-pages": "^0.5.4",
"gulp-istanbul": "^0.10.3",
"gulp-jade": "^1.1.0",
"gulp-livereload": "^3.8.1",
"gulp-mocha": "^2.2.0",
"gulp-postcss": "^6.1.0",
"gulp-rename": "^1.2.2",
"gulp-shell": "^0.5.2",
"gulp-sourcemaps": "^1.6.0",
"gulp-uglify": "^1.5.1",
"gulp-util": "^3.0.7",
"highlight.js": "^9.2.0",
"isparta": "^4.0.0",
"jsdoc": "^3.4.0",
"jsdom": "^8.0.2",
"karma": "^1.0.0",
"karma-browserify": "^5.0.5",
"karma-chrome-launcher": "^1.0.1",
"karma-mocha": "^1.0.1",
"karma-mocha-reporter": "^2.0.4",
"keysim": "git://github.com/yuku-t/keysim.js.git#input-event",
"lodash.isnumber": "^3.0.3",
"lodash.isundefined": "^3.0.1",
"mocha": "^2.5.3",
"postcss-cssnext": "^2.4.0",
"postcss-import": "^8.0.2",
"power-assert": "^1.2.0",
"sinon": "^1.17.3",
"power-assert": "^1.4.1",
"sinon": "^1.17.4",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.7.0"
Expand All @@ -67,5 +68,17 @@
"lodash.isstring": "^4.0.1",
"lodash.uniqueid": "^4.0.0",
"textarea-caret": "^3.0.1"
},
"browserify": {
"transform": [
[
"babelify",
{
"presets": [
"es2015"
]
}
]
]
}
}
2 changes: 2 additions & 0 deletions test/integration/basic_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('../test_helper');

import Textcomplete from '../../src/textcomplete';
import Textarea from '../../src/textarea';

Expand Down
2 changes: 2 additions & 0 deletions test/integration/dropdown_option_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('../test_helper');

import Textcomplete from '../../src/textcomplete';
import Textarea from '../../src/textarea';
import {CLASS_NAME} from '../../src/dropdown_item';
Expand Down
2 changes: 2 additions & 0 deletions test/integration/events_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('../test_helper');

import Textcomplete from '../../src/textcomplete';
import Textarea from '../../src/textarea';

Expand Down
2 changes: 2 additions & 0 deletions test/integration/strategy_parameters_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('../test_helper');

import Textcomplete from '../../src/textcomplete';
import Textarea from '../../src/textarea';

Expand Down
79 changes: 14 additions & 65 deletions test/test_helper.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,17 @@
import Dropdown from '../src/dropdown';
import DropdownItem from '../src/dropdown_item';
import Query from '../src/query';
import SearchResult from '../src/search_result';
import Strategy from '../src/strategy';
import Textarea from '../src/textarea';
import extend from 'lodash.assignin';
const sinon = require('sinon');

/**
* @returns {HTMLTextAreaElement}
*/
export function getHTMLTextAreaElement() {
return document.createElement('textarea');
}
beforeEach(function () {
this.sinon = sinon.sandbox.create();
});

/**
* @param {object} [props]
* @returns {Strategy}
*/
export function createStrategy(props) {
return new Strategy(extend({
match: /(^|\s)(\w*)$/,
search: function (term, callback) {
callback([term]);
},
replace: function (value) {
return `$1${value.toUpperCase()} `;
},
}, props));
}
afterEach(function () {
this.sinon.restore();

/**
* @param {object} [data]
* @param {string} [term]
* @param {object} [strategyProps]
* @returns {Strategy}
*/
export function createSearchResult(data='hello', term='he', strategyProps) {
return new SearchResult(data, term, createStrategy(strategyProps));
}

/**
* @returns {Textarea}
*/
export function createTextarea() {
return new Textarea(getHTMLTextAreaElement());
}

/**
* @param {Strategy} [strategy]
* @param {string} [term]
* @param {string[]} [match]
* @returns {Query}
*/
export function createQuery(strategy=createStrategy(), term='he', match=['he', '', 'he']) {
return new Query(strategy, term, match);
}

/**
* @param {Dropdown} dropdown
* @param {SearchResult} [searchResult]
* @returns {DropdownItem}
*/
export function createDropdownItem(dropdown=new Dropdown(), searchResult=createSearchResult()) {
var dropdownItem = new DropdownItem(searchResult);
dropdown.append([dropdownItem]);
return dropdownItem;
}
const elements = document.getElementsByClassName('textcomplete-dropdown');
for (let i = 0, l = elements.length; i < l; i++) {
const element = elements[i];
if (element) {
element.parentNode.removeChild(element);
}
}
});
35 changes: 0 additions & 35 deletions test/test_runner.js

This file was deleted.

Loading

0 comments on commit 1db95b5

Please sign in to comment.