npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

karma-cucumberjs

v0.0.3

Published

Karma adapter for running Cucumber.js specs

Downloads

79

Readme

#karma-cucumberjs

Run your Cucumber.js suite using Karma runner.

##Getting Started

npm install karma-cucumberjs --save-dev

Once you install the karma-cucumberjs adapter getting it working with your project is a matter of editing your Karma config file.

###Config The adapter requires that the files array in the karma config contain the files it will require to run your Cucumber feature suite. The adapter looks for the following files:

  • Cucumber reporter CSS
  • HTML/JS app template
  • feature files
  • karma-cucumberjs adapter
  • Project step definition JS files

After Karma finishes opening the browsers that you want to test against the adapter will load the HTML reporter CSS file, the app template, the feature files and the step definitions into the captured browsers.

files: [
  // These are not watched because they're not expected to change.
  // These are not included because they are not JavaScript files and Karma inserts 
  // these as <script> tags.
  // These are served however, as the adapter will load them into the captured browsers.
  // The cucumber-html.css file can be copied and customized, simply change the path.
  // The adapter will load any file ending with '.css' into the captured browsers.
  {pattern: 'node_modules/karma-cucumberjs/vendor/cucumber-html.css', watched: false, 
   included: false, served: true},
  {pattern: 'path/to/app.template', watched: false, included: false, served: true},


  // These are not included because they're text feature files and shouldn't go in script tags.
  // These are watched because feature files will change during dev and you want Karma to run
  // tests when these change.
  // These are served by Karma so the adapter can load their contents when its time to test.
  {pattern: 'path/to/features/**/*.feature', watched: true, included: false, served: true},
  


  // The step definitions should be loaded last so the adapter can load the global functions 
  // needed by the step defs.
  // The step defs are watched and served so Karma runs when they change.
  {pattern: 'path/to/features/step_definitions/**/*.js', watched: true, included: true, served: true}
],

frameworks: ['cucumberjs']
...

Step Definitions

Step definitions must be written slightly different than what you may be used to with Cucumber.js. Each set of step definitions in a JS file needs to be wrapped in a callback and added to the list of step definitions using the addStepDefinitions() function. An example is included below that is from features/step_definitions/Testing_steps.js.

// This addStepDefinitions() function is why the step definitions must 
// be configured to load after the adapter.
addStepDefinitions(function (scenario) {
  // Provide a custom World constructor. It's optional, a default one is supplied.
  scenario.World = function (callback) {
    callback();
  };


  // Define your World, here is where you can add some custom utlity functions you
  // want to use with your Cucumber step definitions, this is usually moved out
  // to its own file that you include in your Karma config
  var proto = scenario.World.prototype;
  proto.appSpecificUtilityFunction = function someHelperFunc() {
    // do some common stuff with your app
  };


  // Before scenario hoooks
  scenario.Before(function (callback) {
    // Use a custom utility function
    this.appSpecificUtilityFunction();

    callback();
  });


  scenario.Given(/^some predetermined state$/, function(callback) {
    // Verify or set up an app state
    
    // Move to next step
    callback();
  });

  scenario.When(/^the user takes an action$/, function(callback) {
    // Trigger some user action
    
    // Move to next step
    callback();
  });

  scenario.Then(/^the app does something$/, function(callback) {
    // Verify the expected outcome
    
    // Move to next step
    callback();
  });

  // After scenario hooks
  scenario.After(function (callback) {
    callback();
  });
});

app.template

The app.template file should contain an HTML partial used to set up the application under test and kick off the Cucumber run. It would typically contain some HTML markup for the app, perhaps a script tag with some JS to start up the application, and a call to startCucumberRun(), which is a global function that is added by the karma-cucumberjs adapter. The adapter will not start running tests until the function is called. Below is the example app.template that is used to test the karma-cucumberjs adapter.

<div id='myApp'>
  <div class='box' style='background-color: green;'>A box in my app</div>
</div>

<script type='text/javascript'>
  $('.box').click(function () {
    $('.box').css('background-color', 'red');
  });

  // This MUST be called once the application is ready to undergo testing.
  startCucumberRun();
</script>

##grunt-karma The adapter is compatible with grunt-karma, take a look at the Gruntfile.js for karma-cucumberjs for an example. It is very simple to use, simply configure Karma as needed using the grunt config. The karma-cucumberjs Gruntfile is a working example of using Karma for both Jasmine and Cucumber.

#Bugs Please report any bugs and feature requests using the GitHub issue tracker.

#Contributing First off thank you for your interest in this project. I would be more than happy to have people help the project along by contributing fixes and features. I do however ask that each pull request is kept to a single feature as much as possible to ease the merging process. Also, please provide unit tests for your changes so that I can better understand the intended changes and so that I may integrate PRs as quickly and efficiently as possible. Thank you much again and hope this project helps you as much as it helps me!

License

Copyright (c) 2013 Omar Gonzalez (s9tpepper) & contributors. Licensed under the MIT license.