Last active
December 21, 2018 02:21
-
-
Save koba04/7a18677b583e1ec43fca to your computer and use it in GitHub Desktop.
karma + mocha + browserify + babel + power-assert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Karma configuration | |
// Generated on Thu Apr 07 2016 10:06:49 GMT+0900 (JST) | |
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: ['browserify', 'mocha'], | |
browserify: { | |
debug: true, | |
transform: [ | |
['babelify', {plugins: ['babel-plugin-espower']}] | |
] | |
}, | |
// list of files / patterns to load in the browser | |
files: [ | |
'*-test.js' | |
], | |
// 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: { | |
'*-test.js': 'browserify' | |
}, | |
// test results reporter to use | |
// possible values: 'dots', 'progress' | |
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | |
reporters: ['progress'], | |
// 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 | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "karma-conf", | |
"version": "1.0.0", | |
"description": "", | |
"main": "karma.conf.js", | |
"scripts": { | |
"test": "karma start" | |
}, | |
"browserify": { | |
"transform": [ | |
[ | |
"babelify", | |
{ | |
"presets": [ | |
"es2015" | |
] | |
} | |
] | |
] | |
}, | |
"repository": { | |
"type": "git", | |
"url": "git+https://gist.github.com/7a18677b583e1ec43fca.git" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"bugs": { | |
"url": "https://gist.github.com/7a18677b583e1ec43fca" | |
}, | |
"homepage": "https://gist.github.com/7a18677b583e1ec43fca", | |
"devDependencies": { | |
"babel-plugin-espower": "^2.1.2", | |
"babel-preset-es2015": "^6.6.0", | |
"babelify": "^7.2.0", | |
"browserify": "^13.0.0", | |
"karma": "^0.13.22", | |
"karma-browserify": "^5.0.3", | |
"karma-chrome-launcher": "^0.2.3", | |
"karma-mocha": "^0.2.2", | |
"mocha": "^2.4.5", | |
"power-assert": "^1.3.1", | |
"watchify": "^3.7.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import assert from 'power-assert'; | |
import sum from './sum'; | |
describe("sum", () => { | |
it("2 + 2 = 5", () => { | |
assert(sum(2, 2) === 5); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function sum(a, b) { | |
return a + b; | |
} |
If you don't mind would you please share how to run this code including the package.json.
When a test fails, the stack trace line numbers refer to the generated bundle. Do you know how I can use source maps for karma please?
@koba04 Could you share your package.json
to see the packages necessary to run this
I didn't notice your comments because gist doesn't have any notifications...
Anyway, I've updated my karma.conf.js and Added all files including package.json
😄
➜ npm test
> [email protected] test /Users/koba04/repos/gist/karma-conf
> karma start
07 04 2016 10:16:21.950:INFO [framework.browserify]: registering rebuild (autoWatch=true)
07 04 2016 10:16:28.871:INFO [framework.browserify]: 1500424 bytes written (6.19 seconds)
07 04 2016 10:16:28.891:INFO [framework.browserify]: bundle built
07 04 2016 10:16:28.895:WARN [karma]: No captured browser, open http://localhost:9876/
07 04 2016 10:16:28.903:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
07 04 2016 10:16:28.909:INFO [launcher]: Starting browser Chrome
07 04 2016 10:16:34.127:INFO [Chrome 49.0.2623 (Mac OS X 10.11.4)]: Connected on socket /#sp0tTaUu5Vcj2ufIAAAA with id 32952404
Chrome 49.0.2623 (Mac OS X 10.11.4) sum 2 + 2 = 5 FAILED
AssertionError: # sum-test.js:6
assert(sum(2, 2) === 5)
| |
4 false
[number] 5
=> 5
[number] sum(2, 2)
=> 4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated browserify transform.(removed espowerify, added babel-plugin-espower)