GithubHelp home page GithubHelp logo

karma_jasmine_single_test's Introduction

Running Only One Jasmine Test in Karma

Jasmine is the preferred BDD JavaScript testing framework for our team and Karma is the test runner that we use. It is great for running all of our tests at once and neatly reporting the results. One of my developers asked me if we could easily isolate a particular suite of unit tests and only run them. He told me it would be great if we could override our gulp task and pass in a command line argument in order to specify a single spec file to test.

In a few minutes, we had modified our gulp task and we are now able to easily isolate a specific test. This repo contains example source code that demonstrates how we accomplished this.

There are certainly Node packages that can be used other than the ones I chose. Naming conventions and folder structures are based on our team's guidelines. There is some deviation, mostly in order to better focus on and demonstrate the solution.

The solution is quite simple and the only thing different than typical Jasmine tests ran with Karma is found in the karma.conf.js.

The karma.conf.js is as follows:

module.exports = function (config) {
	config.set({
		basePath: './',
		frameworks: ['jasmine'],
		files: getSpecs(),
		browsers: ['PhantomJS'],
		reporters: ['spec'],
		singleRun: true
	});
}

var specs = [
	'specs/**.spec.js'
];

function getSpecs() {
	var argv = require('yargs').argv;
	if (argv.file !== undefined) {
		return [argv.file];
	}
	return specs;
}

The gulp task can be run from the command line using gulp test or gulp test --file "specs/first.spec.js".

karma_jasmine_single_test's People

Contributors

jonathanburris avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.