Skip to content

Commit 1ca5bcf

Browse files
committed
add karma
1 parent cb6e14c commit 1ca5bcf

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- '6'
5+
before_script:
6+
- export DISPLAY=:99.0
7+
- sh -e /etc/init.d/xvfb start

karma.conf.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
var webpackConfig = require('./webpack.config')
2+
// Karma configuration
3+
// node_modules/.bin/karma start --single-run
4+
module.exports = function(config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: '',
9+
10+
11+
// frameworks to use
12+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13+
frameworks: ['mocha'],
14+
15+
16+
// list of files / patterns to load in the browser
17+
files: [
18+
'test/test.js'
19+
],
20+
21+
// list of files to exclude
22+
exclude: [
23+
],
24+
25+
// preprocess matching files before serving them to the browser
26+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
27+
preprocessors: {
28+
'test/test.js': ['webpack', 'sourcemap']
29+
},
30+
31+
// test results reporter to use
32+
// possible values: 'dots', 'progress'
33+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
34+
reporters: ['progress'],
35+
36+
37+
// web server port
38+
port: 9876,
39+
40+
41+
// enable / disable colors in the output (reporters and logs)
42+
colors: true,
43+
44+
45+
// level of logging
46+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
47+
logLevel: config.LOG_INFO,
48+
49+
50+
// enable / disable watching file and executing tests whenever any file changes
51+
autoWatch: true,
52+
53+
54+
// start these browsers
55+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
56+
browsers: ['Firefox'],
57+
58+
webpack: webpackConfig,
59+
60+
webpackMiddleware: {
61+
noInfo: true
62+
},
63+
// Continuous Integration mode
64+
// if true, Karma captures browsers, runs the tests and exits
65+
singleRun: true
66+
});
67+
};

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"prepublish": "babel src -d dest",
8-
"test": "mocha"
8+
"test": "karma start --single-run"
99
},
1010
"author": "chemzqm@gmail.com",
1111
"license": "MIT",
@@ -18,6 +18,13 @@
1818
"ei-loader": "^0.1.1",
1919
"gulp": "^3.9.1",
2020
"gulp-util": "^3.0.8",
21+
"karma": "^1.3.0",
22+
"karma-cli": "^1.0.1",
23+
"karma-firefox-launcher": "^1.0.0",
24+
"karma-mocha": "^1.3.0",
25+
"karma-sourcemap-loader": "^0.3.7",
26+
"karma-webpack": "^1.8.1",
27+
"karma-wrap-preprocessor": "^0.1.0",
2128
"mocha": "^3.2.0",
2229
"mocha-loader": "^1.0.0",
2330
"stack-source-map": "^1.0.6",

test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717

1818
describe('downloadFile', () => {
1919
it('should download file', done => {
20-
downloadFile('https://pic1.zhimg.com/v2-953292cea62942adfcfe392fe29672e4_b.jpg').then(res => {
20+
downloadFile('http://assets.jiangwoo.com/11.jpg').then(res => {
2121
assert(res.statusCode)
2222
assert(res.tempFilePath)
2323
done()

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
debug: true,
66
module: {
77
loaders: [
8-
{ test: /\.js$/, exclude: /(node_modules|dest)/, loader: 'babel-loader' },
8+
{ test: /\.js$/, exclude: /(node_modules|dest)/, loader: 'babel?cacheDirectory' },
99
{ test: /\.et/, loader: 'ei-loader' }
1010
]
1111
}

0 commit comments

Comments
 (0)