Skip to content

Commit

Permalink
CHG: use karma for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
farthinker committed Jun 22, 2016
1 parent ac41dfa commit f157d40
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 151 deletions.
36 changes: 0 additions & 36 deletions build/helpers/coverage.coffee

This file was deleted.

48 changes: 0 additions & 48 deletions build/helpers/mocha-phantomjs.coffee

This file was deleted.

9 changes: 1 addition & 8 deletions build/helpers/umd.coffee
Expand Up @@ -4,14 +4,7 @@ _ = require 'lodash'
pkg = require '../../package'

module.exports = (opts) ->
opts = _.extend
globalName: _.upperFirst _.camelCase pkg.name
dependencies:
cjs: ['jquery']
global: ['jQuery']
params: ['$']
, opts

opts = _.extend {}, pkg.umd, opts
opts.dependencies.cjs = opts.dependencies.cjs.map (name) ->
"require('#{name}')"
.join ','
Expand Down
2 changes: 1 addition & 1 deletion build/templates/umd.js
Expand Up @@ -2,7 +2,7 @@
if (typeof module === 'object' && module.exports) {
module.exports = factory(<%= dependencies.cjs %>);
} else {
root.<%= globalName %> = factory(<%= dependencies.global %>);
root.<%= name %> = factory(<%= dependencies.global %>);
}
}(this, function (<%= dependencies.params %>) {
var define, module, exports;
Expand Down
37 changes: 6 additions & 31 deletions build/test.coffee
@@ -1,36 +1,11 @@
gulp = require 'gulp'
coffeelint = require './helpers/coffeelint'
coverage = require './helpers/coverage'
mochaPhantomjs = require './helpers/mocha-phantomjs'
rename = require './helpers/rename'
browserify = require './helpers/browserify'
umd = require './helpers/umd'
karma = require 'karma'

compileTest = ->
gulp.src 'test/simple-module.coffee'
.pipe coffeelint()
.pipe browserify()
.pipe rename
suffix: '-test'
.pipe gulp.dest('test/runner')
compileTest.displayName = 'compile-test'

compileSrc = (done) ->
gulp.src 'src/simple-module.coffee'
.pipe coffeelint()
.pipe coverage()
.pipe gulp.dest('test/runner')
.on 'end', ->
gulp.src 'test/runner/simple-module.js'
.pipe browserify()
.pipe umd()
.pipe gulp.dest('test/runner')
.on 'end', ->
done()
compileSrc.displayName = 'compile-src'

test = gulp.parallel compileSrc, compileTest, (done) ->
mochaPhantomjs 'test/runner/index.html', done
test = (done) ->
server = new karma.Server
configFile: "#{process.cwd()}/karma.coffee"
, done
server.start()

gulp.task 'test', test
module.exports = test
2 changes: 1 addition & 1 deletion dist/simple-module.js
Expand Up @@ -6,7 +6,7 @@
* Released under the MIT license
* http://mycolorway.github.io/simple-module/license.html
*
* Date: 2016-06-21
* Date: 2016-06-22
*/
;(function(root, factory) {
if (typeof module === 'object' && module.exports) {
Expand Down
87 changes: 87 additions & 0 deletions karma.coffee
@@ -0,0 +1,87 @@
coveragify = require 'browserify-coffee-coverage'

module.exports = (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: ['browserify', 'mocha', 'chai']


# list of files / patterns to load in the browser
files: [
'node_modules/jquery/dist/jquery.js'
'src/simple-module.coffee',
'test/simple-module.coffee'
]


# list of files to exclude
exclude: [
]


# preprocess matching files before serving them to the browser
# available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors:
'src/simple-module.coffee': ['browserify']
'test/simple-module.coffee': ['browserify']


browserify:
transform: [coveragify]
extensions: ['.js', '.coffee']


coverageReporter:
dir: 'coverage'
subdir: '.'
reporters: [
{ type: 'lcovonly' }
{ type: 'text-summary' }
]

# test results reporter to use
# possible values: 'dots', 'progress'
# available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['coverage', 'dots']


# 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: false


# start these browsers
# available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS']


# Continuous Integration mode
# if true, Karma captures browsers, runs the tests and exits
singleRun: true

# Concurrency level
# how many browser should be started simultaneous
concurrency: Infinity
21 changes: 17 additions & 4 deletions package.json
Expand Up @@ -18,25 +18,38 @@
"start": "gulp",
"test": "gulp test"
},
"umd": {
"name": "SimpleModule",
"dependencies": {
"cjs": ["jquery"],
"global": ["jQuery"],
"params": ["$"]
}
},
"dependencies": {
"jquery": "^3.0.0"
},
"devDependencies": {
"browserify": "^13.0.0",
"browserify-coffee-coverage": "^1.1.1",
"chai": "^3.5.0",
"coffee-coverage": "^1.0.1",
"coffee-script": "^1.10.0",
"coffeelint": "^1.15.0",
"coveralls": "^2.11.8",
"gulp": "github:gulpjs/gulp#4.0",
"gulp-util": "^3.0.7",
"istanbul": "^0.4.2",
"karma": "^0.13.22",
"karma-browserify": "^5.0.5",
"karma-chai": "^0.1.0",
"karma-coverage": "^1.0.0",
"karma-mocha": "^1.0.1",
"karma-phantomjs-launcher": "^1.0.0",
"lodash": "^4.13.1",
"mocha": "^2.4.5",
"mocha-phantomjs-core": "^2.0.0",
"mocha": "^2.5.3",
"node-sass": "^3.8.0",
"phantomjs-prebuilt": "^2.1.7",
"through2": "^2.0.1",
"uglify-js": "^2.6.2"
}
}
}
22 changes: 0 additions & 22 deletions test/runner/index.html

This file was deleted.

1 change: 1 addition & 0 deletions test/simple-module.coffee
@@ -1,3 +1,4 @@
SimpleModule = require '../src/simple-module'
expect = chai.expect

describe 'SimpleModule', ->
Expand Down

0 comments on commit f157d40

Please sign in to comment.