I'm trying to create a grunt task to run cucumber.js tests. The tests are organized in feature "areas" within my project eg:
project_root
--test
--spec-e2e
--home_Page
--features
--step_definitions
From my project's node_modules dir I can run cucumber.js manually and all is well:
$ node cucumber.js ../../../test/spec-e2e/home_Page/features/
Output:
1 scenario (1 passed)
3 steps (3 passed)
I cannot seem to get the grunt-cucumber task configured properly to recreate the same result.
In my Gruntfile.js I have the following configuration:
// Cucumber test runner
cucumberjs: {
src: 'test/spec-e2e/home_Page/features',
options: {
steps: 'test/spec-e2e/home_Page/features/step_definitions',
format: 'pretty'
}
}
...
//Register task
grunt.registerTask('cucumber', ['cucumberjs']);
Running $ grunt cucumber allows just outputs:
$ Running "cucumberjs:src" (cucumberjs) task
$ Done, without errors.
So I'm not receiving any errors or cucumber summary output. If I purposely edit one of my step_definitions to fail the result is always the same. Can someone tell me how to configure this correctly?
Thanks!
Try this one:
Please go through the below doc :
Grunt cucumber js docs
This code works for me :
grunt.initConfig({
cucumberjs: {
all: {
src: 'features',
options: {
backtrace: true,
useShortStackTraces: false,
format: "json:<path where want to write json report>",
steps: 'features',
tags: grunt.option('feature')
}
}
});
grunt.registerTask('default', ['cucumberjs:all']);
Related
I am trying to configure Protractor on Jenkins for CTI.... I have already setup Protractor along with Jasmine and trying to get it integrated with Jenkins.
I have gone through several links & blogs on internet but none seem to be helpful in providing detailed information on how to get the Protractor configured with Jenkins.
Any help or pointing towards the right blog or video will be really appreciated. Thanks
#Vishal
Please find the below snippet you can add as grunt task.
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
exec: {
protractorRunAppsTest: {
cmd: 'C:\\Program Files\\nodejs\\node.exe C:\\Users\\Administrator\\AppData\\Roaming\\npm\\node_modules\\protractor\\built\\cli.js C:\\Jenkins\\workspace\\test\\conf.js'
}
},
server: {
port:3000,
base: ['app']
},
});
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-protractor-runner');
grunt.loadNpmTasks('grunt-run');
grunt.loadNpmTasks('grunt-exec');
grunt.registerTask('server', 'Start node server', function() {
grunt.log.writeln('Started server on port 3000');
require('./app.js');
});
grunt.registerTask('runAppsTest', ['exec:protractorRunAppsTest']);
};
Save the above code as Gruntfile.js
Make sure this is in the workspace folder for jenkins.
In Jenkins job add the 'Build' Section (i am assuming Jenkins is windows server)
add "Execute Windows Batch Command" and add the below content to the text field there.
cd %WORKSPACE%
grunt server runAppsData || exit 0
I hope this would work for you. Please try and let me know.
Consider rating my answer.
#Vishal try to use grunt for doing the same. So that you can easily integrate the Jenkins job with grunt task details.
Just configure and register task with grunt.
Then use the grunt task to run in jenkins.
If you want i can provide more details.
Background:
I'm working on a chrome extension. I used the yeoman generator. It worked like a charm. After I deployed the extension, I needed to debug a few issues.
Problem:
The code is uglified. I can't set break points. I can hardly read it. It is also optimized. This makes it hard to read as well. I would like to tell Grunt to skip uglifying the code.
Attempted Solutions:
I tried to comment out the uglify task in the Grunt file. If I do this, not only is uglify not executed, but most of the scripts fail to copy into the "dist" directory.
I can deploy the application from the "app" directory. If I do this, my human written code is loaded rather than the "dist" values. While this works, I wish to learn more about the inner workings of Grunt. It seems likely that there is some mechanism by which uglifying may be disabled while preserving copying.
It's the usemin task that supplies targets to the uglify task. When you comment out the uglify task usemin can't complete its flow (by default concat and uglify) and the scripts never get copied.
So you must configure the flow in useminPrepare options. Like this:
[...]
useminPrepare: {
options: {
stripBanners: true,
dest: '<%= config.dist %>',
flow: {
steps: {
js: ['concat'], css: ['concat', 'cssmin']
},
post: {}
}
},
[...]
This way you can remove the uglify task from the build sequence (you must, as it will complaint that have no targets and fail).
Documentation here: https://github.com/yeoman/grunt-usemin#flow
I'm using grunt-mocha-test to run node server side tests.
My Gruntfile.js looks like this
module.exports = function(grunt) {
// Add the grunt-mocha-test tasks.
grunt.loadNpmTasks('grunt-mocha-test');
grunt.initConfig({
// Configure a mochaTest task
mochaTest: {
test: {
options: {
reporter: 'dot'
},
src: [ 'test/setup.js', 'test/*.test.js' ]
}
},
});
grunt.registerTask('default', 'mochaTest');
};
What I want to do is this, I want to be able to run different test groups with different commands as follows
grunt will run all tests
grunt test1 runs a subset of tests in the test folder, and
grunt test2 runs another subset of tests
I don't know if this is possible, and I haven't been able to find anything about this in the documentation for grunt-mocha-test
I could sure use some help here.
Thanks
At the moment you have one group called test. Just add another object inside mochaTest and call grunt mochaTest:test2.
I'm using CucumberJS to run tests on my NodeJS web app.
At the moment, I can run all of my grunt tasks by executing grunt, or only the CucumberJS tasks, using grunt cucumberjs.
But now I want to only execute particular features.
For example, say I have the following feature files:
Signin.feature
Favourite.feature
I want to only run the Favourite feature tests, using a command such as:
grunt cucumberjs Favourite
Is this possible?
BTW, here's my gruntfile.js:
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
...
cucumberjs: {
src: 'features',
options: {
steps: 'features/step_definitions',
format: 'pretty'
}
}
});
...
grunt.loadNpmTasks('grunt-cucumber');
grunt.registerTask('default', [... 'cucumberjs']);
};
I finally figured out a solution that seems to work well enough, based on tags.
So for each of my feature files, I've added a tag.
For example, for Favourite.feature:
#favourite
Feature: Favourite
As a user of the system
I would like to favourite items
Then I've used a GruntJS option to specify the tags I want to run via a command-line argument.
I do this through a grunt.option() call in my gruntfile:
cucumberjs: {
src: 'features',
options: {
steps: 'features/step_definitions',
format: 'pretty',
tags: grunt.option('cucumbertags')
}
}
So now I can run GruntJS from the command-line like this:
grunt cucumberjs --cucumbertags=#favourite
And it will only run the feature with the #favourite tag. Yay!
here is my task that allows you to filter by feature.name:
https://github.com/webforge-labs/cuked-zombie/blob/master/tasks/cucumber.js
(download it into a "tasks" folder and you can load it with: grunt.loadTasks('tasks'))
configure it like this (Gruntfile.js):
grunt.loadNpmTasks('grunt-cucumber');
grunt.initConfig({
cucumberjs: {
// config for all features when called with: `grunt cucumber`
all: {
src: 'features',
options: {
steps: "tests/js/cucumber/bootstrap.js",
format: "pretty"
}
},
// config for single features when called with `grunt --filter some-feature`
features: {
src: 'features',
options: {
steps: "tests/js/cucumber/bootstrap.js",
format: "pretty"
}
}
}
});
use it with:
grunt cucumber --filter post
which will run the post.feature (somewhere in your feature directory)
With the new cucumber-js Version it is possible to run it by feature-line:
https://github.com/cucumber/cucumber-js/pull/168
I haven't tested it with grunt but cucumber has an option for executing a scenario without modifying the gherkin file. Just call cucumber-js --name "Scenario Name", therefore I assume that sending the same argument to grant it will do its job.
How do I setup Karma to run my backend unit tests (written with Mocha)? If I add my backend test script to the files = [], it fails stating that require is undefined.
You don't. Karma is only for testing browser-based code. If you have a project with mocha tests on the backend and karma/mocha on the front end, try editing your package.json under scripts to set test to: mocha -R spec && karma run karma.con
Then, if npm test returns true, you'll know it's safe to commit or deploy.
It seems like it cannot be done (thanks #dankohn). Here is my solution using Grunt:
Karma: update your karma.conf.js file
set autoWatch = false;
set singleRun = true;
set browsers = ['PhantomJS']; (to have inline results)
Grunt:
npm install grunt-contrib-watch grunt-simple-mocha grunt-karma
configure the two grunt tasks (see grunt file below)
Gruntfile.js:
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-karma');
grunt.initConfig({
simplemocha: {
backend: {
src: 'test/server-tests.js'
}
},
karma: {
unit: {
configFile: 'karma.conf.js'
}
}
});
// Default task.
grunt.registerTask('default', ['simplemocha', 'karma']);
};
Grunt (optional): configure grunt-watch to run after changing spec files or files to be tested.
run all using grunt command.