Skip to content

Commit e79ad36

Browse files
committed
init test
1 parent 92020a0 commit e79ad36

File tree

8 files changed

+130
-16
lines changed

8 files changed

+130
-16
lines changed

karma.conf.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Karma configuration
2+
3+
const webpack = require('webpack')
4+
5+
module.exports = function (config) {
6+
config.set({
7+
8+
// base path that will be used to resolve all patterns (eg. files, exclude)
9+
basePath: './',
10+
11+
12+
// frameworks to use
13+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
14+
frameworks: [ 'mocha', 'chai' ],
15+
16+
17+
// list of files / patterns to load in the browser
18+
files: [
19+
'tests.webpack.js'
20+
],
21+
22+
// list of files to exclude
23+
exclude: [
24+
],
25+
26+
27+
// preprocess matching files before serving them to the browser
28+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
29+
preprocessors: {
30+
'tests.webpack.js': [ 'webpack', 'sourcemap' ]
31+
},
32+
33+
webpack: {
34+
devtool: 'inline-source-map',
35+
module: {
36+
loaders: [
37+
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel' }
38+
]
39+
},
40+
plugins: [
41+
new webpack.DefinePlugin({
42+
'process.env.NODE_ENV': JSON.stringify('test')
43+
})
44+
]
45+
},
46+
47+
webpackMiddleware: {
48+
noInfo: true
49+
},
50+
51+
// test results reporter to use
52+
// possible values: 'dots', 'progress'
53+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
54+
reporters: [ 'mocha' ],
55+
56+
// web server port
57+
port: 9876,
58+
59+
60+
// enable / disable colors in the output (reporters and logs)
61+
colors: true,
62+
63+
64+
// level of logging
65+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
66+
logLevel: config.LOG_INFO,
67+
68+
69+
// enable / disable watching file and executing tests whenever any file changes
70+
autoWatch: false,
71+
72+
73+
// start these browsers
74+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
75+
browsers: [ 'PhantomJS' ],
76+
77+
78+
// Continuous Integration mode
79+
// if true, Karma captures browsers, runs the tests and exits
80+
singleRun: true,
81+
82+
// Concurrency level
83+
// how many browser should be started simultaneous
84+
concurrency: Infinity
85+
})
86+
}

module/__tests__/index.test.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

package.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "lib/index.js",
66
"scripts": {
77
"build": "babel module --out-dir lib",
8-
"prepublish": "npm run build"
8+
"prepublish": "npm run build",
9+
"test": "karma start"
910
},
1011
"repository": {
1112
"type": "git",
@@ -29,16 +30,30 @@
2930
"babel-cli": "^6.1.18",
3031
"babel-eslint": "^4.1.5",
3132
"babel-jest": "^9.0.3",
33+
"babel-loader": "~6.2.4",
3234
"babel-plugin-syntax-class-properties": "^6.1.18",
3335
"babel-plugin-transform-class-properties": "^6.1.20",
3436
"babel-preset-es2015": "^6.1.18",
3537
"babel-preset-react": "^6.1.18",
3638
"babel-preset-stage-0": "^6.1.18",
39+
"chai": "~3.5.0",
3740
"eslint": "^1.9.0",
3841
"jest-cli": "^0.9.2",
42+
"karma": "~0.13.22",
43+
"karma-chai": "~0.1.0",
44+
"karma-chrome-launcher": "~0.2.3",
45+
"karma-mocha": "~0.2.2",
46+
"karma-mocha-reporter": "~2.0.0",
47+
"karma-phantomjs-launcher": "~1.0.0",
48+
"karma-sourcemap-loader": "~0.3.7",
49+
"karma-webpack": "~1.7.0",
50+
"mocha": "~2.4.5",
51+
"phantomjs-prebuilt": "~2.1.7",
3952
"react": "^0.14.7",
4053
"react-addons-test-utils": "^0.14.7",
41-
"react-dom": "^0.14.7"
54+
"react-dom": "^0.14.7",
55+
"sinon": "~1.17.3",
56+
"webpack": "~1.12.14"
4257
},
4358
"dependencies": {
4459
"hoist-non-react-statics": "^1.0.3"

module/index.js renamed to src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component, PropTypes as T } from 'react'
22
import hoistStatics from 'hoist-non-react-statics'
3-
import { isDefined, newScript, series } from './utils'
3+
import { isDefined, newScript, series, noop } from './utils'
44

55
const loadedScript = []
66
let failedScript = []
@@ -32,7 +32,7 @@ const scriptLoader = (...scripts) => (WrappedComponent) => {
3232
};
3333

3434
static defaultProps = {
35-
onScriptLoaded: () => {}
35+
onScriptLoaded: noop
3636
};
3737

3838
constructor (props, context) {

module/utils.js renamed to src/utils.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export const isDefined = val => val != null
2-
export const isFunction = val => {
3-
return typeof val === 'function'
4-
}
2+
export const isFunction = val => typeof val === 'function'
3+
export const noop = _ => { }
54

65
export const newScript = (src) => (cb) => {
76
const script = document.createElement('script')

test/index.spec.js

Whitespace-only changes.

test/utils.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { newScript, parallel, series } = require('../src/utils')
2+
3+
describe('Test util functions', _ => {
4+
5+
it('[utils/newScript] A thunk task, append new script tag', function (done) {
6+
const testScript = '//cdn.bootcss.com/jquery/2.2.1/jquery.min.js'
7+
const task = newScript(testScript)
8+
9+
task(function (err, src) {
10+
const tag = document.querySelector(`script[src='${testScript}']`)
11+
12+
expect(err).to.not.exist
13+
expect(src).to.equal(testScript)
14+
expect(tag).to.exist
15+
16+
done()
17+
})
18+
})
19+
})

tests.webpack.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// require all modules ending in ".spec.js" from the
2+
// current directory and all subdirectories
3+
var testsContext = require.context("./test", true, /\.spec\.js$/)
4+
testsContext.keys().forEach(testsContext)

0 commit comments

Comments
 (0)