How to add html reporting to a cucumber/chimp e2e test - gulp

I am using the example provided on the chimp website for gulp-chimp
gulp.task('chimp-options', () => {
return chimp({
features: './features',
browser: 'phantomjs',
singleRun: true,
debug: false,
output: {
screenshotsPath: './screenshots',
jsonOutput: './cucumber.json',
},
htmlReport: {
enable: true,
jsonFile: './e2e_output/cucumber.json',
output: './e2e_output/report/cucumber.html',
reportSuiteAsScenarios: true,
launchReport: true,
}
});
});
the problem i have and that it's killing me is that when I run gulp chimp-options i get :
Unable to parse cucumberjs output into json: './e2e_output/cucumber.json' SyntaxError: ./e2e_output/cucumber.json: Unexpected end of JSON input
What am I doing wrong ?

I believe chimp is just a wrapper on multiple frameworks/libraries out there and I'm pretty sure they just use cucumber-html-reporter to generate its HTML reports.
If you still can't get it working automatically via chimp, just generate the options file as usual and npm install cucumber-html-reporter and then use it to generate the same report.
Create a separate file called generate_html_report.js and paste in the code under Usage. Then add this to your npm script to run after your test suite has finished. I'd avoid putting it in your afterHooks as I've had issues in the past where the JSON file hadn't been completely generated before it tries to run the script expecting the JSON file to be there.

Related

Index.js file continuously gives "JSON text did not start with array" despite being formatted as an array

I have a parse-server hosted by heroku, which has an index.js file utilized for its configuration. I want to use Mailgun to up functionality for the user to request a password reset, and I have set up the config file, following this answer, as follows:
var api = new ParseServer({
appName: 'App Name',
publicServerURL: 'https://<name>.herokuapp.com/parse',
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it $
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't$
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query s$
},
push: JSON.parse(process.env.SERVER_PUSH || "{}"),
verifyUserEmails: true, //causing errors
emailAdapter: { //causing errors
module: 'parse-server-simple-mailgun-adapter',
options: {
fromAddress: 'parse#example.com',
domain: '<domain>',
apiKey: '<key>',
}
}
});
This code does not work, though, because of the verifyUserEmails and emailAdapter. Removing both of them removes the "JSON text did not start with array" error. Adding either one of them back in results in the error being thrown. I have no idea why, though, since I do not see any obvious reason as to how they aren't being set up in an array correctly?
Do I need to set up the cooresponding config vars in heroku in addition to having them in the config file? I considered this, but appName and publicServerURL are not set up in this way and don't give this error.
emailAdapter.options.apiKey doesn't need a comma at the end since its the last element of it's JSON.
I wouldn't be surprised that you're also leaving in the comma at the end of verifyUserEmails when you include it improperly as well.
options: {
fromAddress: 'parse#example.com',
domain: '<domain>',
apiKey: '<key>',
}
This is not valid JSON, because there is a comma at the end of the apiKey line. The last item in a JSON object does not have a comma.
For anyone that is repeatedly running into this issue, I have figured out exactly what was going wrong. Despite the error informing me that my JSON was incorrectly formatted, it turns out it was actually that the module was misnamed. According to this post, the updated module has been renamed to '#parse/simple-mailgun-adapter'. Inserting this into the index.js, after ensuring I had ran the npm install --save #parse/simple-mailgun-adapter in my local repo, fixed the issue.

RequireJS: Uglification Not Working

I must be making a mistake somewhere, but it's not being written to stdout during optimization. I'm trying to optimize a file via requirejs, but the output isn't being minified. According to the documentation, UglifyJS should minify the code.
At any rate, the following code is trivial, but it isolates the problem.
src/index.js:
require(['config'], function () {
require(['myMod'], function (myMod) {
console.log(myMod.x());
})
})
src/myMod.js:
define(function () {
let myMod = {
x: 5
};
return myMod;
})
src/config.js:
define(function () {
require.config({
baseUrl: 'src'
});
})
And here's the gulp task that is performing the optimization:
gulp.task('optimize', function (cb) {
let config = {
appDir: 'src',
dir: 'dist/src',
generateSourceMaps: true,
preserveLicenseComments: false,
removeCombined: true,
baseUrl: './',
modules: [{
name: 'index',
include: ['myMod']
}]
}
let success = function (buildResponse) { console.log(buildResponse); cb() },
error = function (err) { console.log(err); cb(err) }
rjs.optimize(config, success, error)
})
After running the task, dist/src/index.js has all of the other modules included in it. However, it's not minified, and none of the variables have been renamed. Instead, it's as if the files were just concatenated, nothing more. Could someone tell me (1) why is it not being minified? (2) is UglifyJS throwing an error? If so, is there a way to see it when the gulp task is being run?
EDIT Here's a link to RequireJS docs where it talks about using the optimizer in node, which is done in the gulp task mentioned above. It's at the bottom under "Using the optimizer as a node module".
http://requirejs.org/docs/node.html
RequireJS' optimizer bundles UglifyJS2. UglifyJS2 does not handle ES6 or higher. If I take the options you use in your gulpfile, and plunk them into a separate file that I name options.js, and issue this command:
$ ./node_modules/.bin/r.js -o options.js
Then I get this output:
Tracing dependencies for: index
Uglify file: /tmp/t33/dist/src/index.js
Error: Cannot uglify file: /tmp/t33/dist/src/index.js. Skipping it. Error is:
SyntaxError: Unexpected token: name (myMod)
If the source uses ES2015 or later syntax, please pass "optimize: 'none'" to r.js and use an ES2015+ compatible minifier after running r.js. The included UglifyJS only understands ES5 or earlier syntax.
index.js
----------------
config.js
index.js
myMod.js
As you can see, UglifyJS does fail to minify your file, and RequireJS just skips the minification step for that file. Since this is not an outright error, the file is still output, just not minified.
If you change let to var in myMod.js, then the issue disappears.
Unfortunately, since this is not an execution failure (r.js still runs, it just does not minify the file), the error is not signaled to the errback handler you pass to rjs.optimize. I don't see a way to catch such error in a Gulpfile. The safe thing to do is to set optimize: "none" and perform the minification as an additional build step after running rjs.optimize.
I had also run into the same issue where require.js's optimizer (r.js) was combining different modules, but, it was not minify-ing the merged file. Although my run time environment is different from yours (using Java's Nashorn engine), this error was visible on my console :
If the source uses ES2015 or later syntax, please pass "optimize: 'none'" to r.js and use an ES2015+ compatible minifier after running r.js. The included UglifyJS only understands ES5 or earlier syntax.
Also, this error does not stop the optimizer from combining the files, it's just that the optimizer will not be able to mini-fy the merged file.

How to generate Json file after execution finish

I'm working with cucumber and protractor and to generate reports i'm using
cucumber-html-reporter I already add the configuration to generate the report
var options = {
theme: 'bootstrap',
jsonFile: 'reporter/cucumber_report.json',
output: 'reporter/cucumber_report.html',
reportSuiteAsScenarios: true,
launchReport: true,
};
defineSupportCode(function({ After }) {
After((scenario)=> {
reporter.generate(options);
});
});
but i'm not generate the json file with this code, I search in google and the code to generate the json file should be add into the cucumberOpts in the conf.js but i'm not sure what's the code should be into cucumberOpts to generate the json file and the convert into report.
I hope you can help me guys.
Maybe this can help you, it's for Typescript but the code is almost the same. You can export the file in an After-hook. The link is for CucumberJS 1, if you look into the master branch you can also find the CucumberJS 2 solution
The advantage of this in comparison to generating the JSON file with the format option is that you can modify the JSON before saving
Hope it helps
For people that still have this problem, in my case the problem was that I was using cucumber v1 instead cucumber v2. For this case I should use registerHandler instead After this is the complete example:
defineSupportCode(function({registerHandler}) {
registerHandler('AfterFeatures', function (features) {
reporter.generate(options);
});
});
Hope this help u guys.

Generating JSON object of the tests ran using Protractor?

I'm relatively new to end to end testing with Protractor, Mocha and Yadda (for integration with Mocha so I can use Gherkin and step definitions).
I've seen a plugin called Mochawesome which generates an HTML report which can be viewed offline, along with this JSON object of the test results, all of which contained in a 'reports' folder.
I presume it's Mochawesome which generates these JSON objects as the HTML page seems to have corresponding tags etc. Is there any way to generate a JSON object of the tests ran without the HTML reporter? The idea was to create my own sort of 'dashboard' containing information about the tests based on the JSON information.
Yes you can create a JSON report of your specs/tests with protractor.You just have to put resultJsonOutputFile: './Report.json' in your config file.
your config file should somewhat look like this:
exports.config = {
directConnect: true,
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://juliemr.github.io/protractor-demo/',
framework: 'jasmine2',
specs: ['*spec.js '],
allScriptsTimeout: 180000,
getPageTimeout: 180000,
jasmineNodeOpts: {
defaultTimeoutInterval: 180000
},
resultJsonOutputFile: './Report.json', // It would create report.json file in your current folder
onPrepare: function () {
browser.driver.manage().window().maximize();
browser.ignoreSynchronization = true;
}
};
You can consume this json report and use it in your way!
I'm not sure about generating JSON object directly in protractor. But what i know is that, we can generate results in XML and then convert xml to json by writing some customized code.
Code for generating XML reports are as follows:
framework: "jasmine2",
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters'),
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
savePath: '../result/',
filePrefix: ‘report’,
consolidateAll: true
});
);
},

Grunt - read json object from file

I want to use grunt-hash plugin for renaming my js files.
This plugin create a new file containing map of renamed files:
hash: {
options: {
mapping: 'examples/assets.json', //mapping file so your server can serve the right files
Now I need to fix links to this files by replacing all usages (rename 'index.js' to 'index-{hash}.js') so I want to use grunt-text-replace plugin.
According to documentation I need to cofigure replacements:
replace: {
example: {
replacements: [{
from: 'Red', // string replacement
to: 'Blue'
}]
}
}
How could I read json mapping file to get {hash} values for each file and provide them to replace task?
grunt.file.readJSON('your-file.json')
is probably what you are looking for.
I've set up a little test. I have a simple JSON file 'mapping.json', which contains the following JSON object:
{
"mapping": [
{"file": "foo.txt"},
{"file": "bar.txt"}
]
}
In my Gruntfile.js I've written the following simple test task, which reads the first object in the 'mapping'-array:
grunt.registerTask('doStuff', 'do some stuff.', function() {
mapping = grunt.file.readJSON('mapping.json');
grunt.log.write(mapping.mapping[0]["file"]).ok();
});
When invoking the Grunt task, the console output will be as follows:
$ grunt doStuff
Running "doStuff" task
foo.txtOK
Done, without errors.
I hope this helps! :)