How can I integrate karma testing tool in backbone...
# general
p
How can I integrate karma testing tool in backbone which will be compatible
b
Pick a supported test framework, write tests using that test framework, setup the matching karma test runner and write a karma config file, then run karma
p
I am using Jasmine Framework to test. Can you help me with the configuration of karma and gulp to test the application.
b
which browsers do you plan on using
anyways, you install the karma packages that you require using npm
an example is:
npm install karma-jasmine karma-chrome-launcher jasmine-core --save-dev
npm install -g karma-cli
first one installs the karma plugins and test runner required, I assumed you wanted chrome
the second one installs the karma-cli, which is useful to make sure you setup karma correctly
p
Okay I have installed both of them
b
your config file should look something like
Copy code
module.exports = function (config) {
  config.set({
    frameworks: ['jasmine'],
    files: [
      'path/to/your/src',
      'path/to/your/spec'
    ],
    exclude: [
      'path/to/exclude/if/necessary'
    ],
    browsers: ['Chrome']
  });
};
p
right
b
keep in mind that the paths are globs
you probably want to include multiple src files, so it should look something like
'src/**/*.js'
the config file should be in your project root and named
karma.conf.js
p
okay
b
keep in mind the default current working directory used by the paths in the glob is the directory of karma.conf.js
p
but I am getting Couldn't install when I am trying to install karma
b
that weird, what error is it
p
Could not install /Users/file1/webportal/node_modules/suitetalk4node
b
that has nothing to do with karma
what command are you running that is giving you that error
p
this is the command which I am trying npm install karma-jasmine karma-chrome-launcher jasmine-core --save-dev
b
what is the cwd of your terminal
ideally you should be starting at your project root
p
Ya I am starting it at project root itself
b
what does your package.json file look like
p
"name": "suitecommerce-builder", "version": "0.0.1", "description": "Sets of tasks to build a Reference Implementation", "main": "gulpfile.js", "private": true, "scripts": { "test": "./node_modules/.bin/nightwatch" }, "author": "", "license": "ISC", "dependencies": { "amd-optimize": "0.3.1", "archiver": "0.13.0", "async": "0.9.0", "cli-spinner": "0.1.5", "credentials-inquirer": "file:./ns_npm_repository/credentials-inquirer", "del": "0.1.1", "escodegen": "1.6.1", "esprima": "1.2.5", "estraverse": "1.9.3", "express": "4.13.3", "glob": "4.0.4", "gulp": "^3.9.1", "gulp-add": "0.0.2", "gulp-bless": "3.0.1", "gulp-changed": "1.0.0", "gulp-chmod": "2.0.0", "gulp-concat": "2.3.3", "gulp-cssfmt": "^1.0.0", "gulp-handlebars": "3.0.1", "gulp-if": "1.2.5", "gulp-insert": "0.4.0", "gulp-jshint": "1.9.0", "gulp-jst": "0.1.1", "gulp-less": "1.3.6", "gulp-livereload": "2.1.1", "gulp-minify-css": "0.3.13", "gulp-sass": "2.1.0", "gulp-sourcemaps": "1.2.8", "gulp-svg2ttf": "1.0.3", "gulp-ttf2eot": "1.0.1", "gulp-ttf2woff": "1.0.1", "gulp-uglify": "0.3.1", "gulp-util": "3.0.1", "handlebars": "2.0.0", "inquirer": "0.5.1", "is-my-json-valid": "2.13.1", "jshint-stylish": "1.0.0", "jsonlint": "1.6.2", "jsonpath-plus": "0.15.0", "lazypipe": "0.2.2", "lodash": "2.4.1", "map-stream": "0.1.0", "mime": "1.2.11", "moment": "2.8.3", "node-sass": "3.9.3", "ns-uploader": "file:./ns_npm_repository/ns-uploader", "preconditions": "file:./ns_npm_repository/preconditions", "progress": "1.1.7", "q": "1.0.1", "request": "2.39.0", "run-sequence": "^1.2.2", "serve-index": "1.7.2", "shelljs": "^0.5.3", "short-jsdoc": "0.2.4", "sourcemap-to-ast": "0.0.2", "suitetalk": "file:./ns_npm_repository/suitetalk4node", "testarmada-magellan": "^10.0.8", "testarmada-magellan-local-executor": "^2.0.0", "testarmada-magellan-nightwatch-plugin": "^7.0.0", "testarmada-nightwatch-extra": "^4.2.4", "through": "2.3.6", "through2": "0.6.3", "underscore": "1.6.0", "vinyl": "0.4.6", "xml2js": "0.4.5", "yargs": "1.3.1" }, "optionalDependencies": { "minijasminenode2": "1.0.0", "gulp-jasmine-phantom": "1.1.2" }, "devDependencies": { "chromedriver": "^2.30.1", "eslint-config-standard": "^10.2.1", "eslint-plugin-import": "^2.8.0", "eslint-plugin-node": "^5.2.1", "eslint-plugin-promise": "^3.6.0", "eslint-plugin-standard": "^3.0.1", "mocha-nightwatch": "^3.2.2", "nightwatch": "^0.9.16", "selenium-download": "^2.0.10", "selenium-standalone-jar": "^3.0.1" }
this is my package.json file
b
your error is npm not being able to install the suitetalk package
does ./ns_npm_repository/suitetalk4node exist?
p
Ya it exists
b
is it an actual npm package?
p
suitetalk4node package.json looks like
"name": "suitetalk", "version": "1.1.0", "description": "suitetalk API for nodejs. For version 2015_1 to 2016_1.", "main": "src/index.js", "scripts": { "test": "node node_modules/jasmine/bin/jasmine.js" }, "author": "PSG Ecommerce", "dependencies": { "handlebars": "3.0.1", "q": "1.0.1", "request": "2.39.0", "underscore": "1.6.0", "xml2js": "0.4.5" }, "devDependencies": { "jasmine": "~2.3.1" }
b
i dont know what to tell you, npm is telling you that it cant install suitetalk4node
p
Okay I will check it out. And Thank You so much for helping me out @battk
b
if you sort out your npm problem
you also need to install karma
npm install karma --save-dev
afterwards, hopefully you can run karma
karma start
p
Ya sure will do that
Currently getting this error karma-jasmine@2.0.1 requires a peer of karma@* but none was installed
b
install karma first
p
Ya I install karma then to the error remains the same
b
what does the output of npm view karma look like
p
karma
b
that sounds wrong
is karma in the devDependencies of your package.json
p
No there is no entry of karma in package.json
b
npm install karma --save-dev
p
okay will try it out