Skip to content

Instantly share code, notes, and snippets.

@tomas-stefano
Created July 17, 2017 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomas-stefano/049a45f24f48c1fe8de18ed56508bf63 to your computer and use it in GitHub Desktop.
Save tomas-stefano/049a45f24f48c1fe8de18ed56508bf63 to your computer and use it in GitHub Desktop.
Notes. It is about karma
Install karma-cli globally:
* npm i -g karma-cli
Set up the project:
* npm init
* npm i --save-dev karma
* karma init
* Use the following responses when prompted:
* Which testing framework do you want to use?
* mocha
* Do you want to use Require.js?
* yes
* Do you want to capture any browsers automatically?
* phantomjs
* What is the location of your source and test files?
* app/assets/javascripts/**/*.js
* spec/javascripts/**/*_spec.js
* Should any of the files included by the previous patterns be excluded?
* app/assets/javascripts/application.js
* Do you wanna generate a bootstrap file for RequireJS?
* yes
* Do you want Karma to watch all the files and run the tests on change?
* no
Set up test-main.js
* move into test directory
* add paths to files to be tested, e.g.
* paths: {
* // Dough components
* GlobalNav: ‘app/assets/javascripts/components/wpcc/components/ConditionalMessaging’
* }
Set up karma.conf.js
* move into test directory
* set config.set
* basePath: ‘../‘,
* frameworks: [‘requirejs’, ‘mocha’, ‘chai’, ‘sinon’],
* files:
* /path/to/test-main.js
* [… {pattern: ‘javascripts/tests/*_spec.js’, included: false}]
To run
* ./node_modules/karma/bin/karma start spec/javascripts/karma.conf.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment