Skip to content

Instantly share code, notes, and snippets.

@koba04
Last active Dec 21, 2018
Embed
What would you like to do?
karma + mocha + browserify + babel + power-assert
node_modules/
// 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
})
}
{
"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"
}
}
import assert from 'power-assert';
import sum from './sum';
describe("sum", () => {
it("2 + 2 = 5", () => {
assert(sum(2, 2) === 5);
});
});
export default function sum(a, b) {
return a + b;
}
@koba04

This comment has been minimized.

Copy link
Owner Author

@koba04 koba04 commented May 21, 2015

Updated browserify transform.(removed espowerify, added babel-plugin-espower)

@nicholasnet

This comment has been minimized.

Copy link

@nicholasnet nicholasnet commented Jul 29, 2015

If you don't mind would you please share how to run this code including the package.json.

@SebT

This comment has been minimized.

Copy link

@SebT SebT commented Nov 4, 2015

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?

@kn9ts

This comment has been minimized.

Copy link

@kn9ts kn9ts commented Dec 15, 2015

@koba04 Could you share your package.json to see the packages necessary to run this

@koba04

This comment has been minimized.

Copy link
Owner Author

@koba04 koba04 commented Apr 7, 2016

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

> karma-conf@1.0.0 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