Here is a snippet from my gruntjs file in a vs2013 web project. What I am seeing is adding the last line in the initconfig to load the settings stops showing the tasks in the VS2013 Task Runner Explorer. As soon as comment out that line the Task Runner Explorer enumerates my tasks. There are no errors in the output window for the Task Runner ExplorerI .
I can run my gruntfile.js fine using the grunt cli.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
target: grunt.config.get('target'),
settings: grunt.file.readJSON('config/' + grunt.option('target') + '.json'), //problematic line
karma: {
unit: {
configFile: 'karma.conf.js'
}
},
I had a problem with grunt.file.readJSON and I solved it by giving my option a self invoked function which checked to see if the file even exists. Something like:
settings: function () {
if (grunt.file.exists('config/' + grunt.option('target') + '.json')) {
return grunt.file.readJSON('config/' + grunt.option('target') + '.json')
}
return '';
}()
Related
I'm using Cypress for frontend testing and I defined a task in cypress.config file.
setupNodeEvents(on) {
on('task', {
downloads: downloadspath => {
return fs.readdirSync(downloadspath);
},
deleteFiles: directory => {
const files = fs.readdirSync(directory);
if (files.length === 0) {
return 0;
}
for (const file of files) {
fs.unlinkSync(path.join(directory, file));
}
return 0;
},
});
},
And when I use it in my tests, it gives an error like this:
There's no explanation so, I don't know how to fix this error.
cy.task does a simple work, it just deletes all files in the cypress/downloads folder.
Generally, if the task throws an error it shows up in the Cypress log. You may get more info if you open devtools and click on the Cypress log entry.
Specifically, fs.unlinkSync(path.join(directory, file)) is probably failing because there is a sub-directory in the directory, see Node.js fs.unlinkSync() Method
The fs.unlinkSync() method is used to synchronously remove a file or symbolic link from the filesystem. This function does not work on directories, therefore it is recommended to use fs.rmdir() to remove a directory.
Since you are deleting cypress/downloads in the test, be aware Cypress does that for you
Cypress Configuration - Downloads
trashAssetsBeforeRuns (default: true)
Whether Cypress will trash assets within the downloadsFolder, screenshotsFolder, and videosFolder before tests run with cypress run.
I want Cypress to execute custom scripts before and after running the specs suite.
The before:run and after:run APIs look perfect for that.
But the same snippet that works perfectly in before:run doesn’t seem to work in after:run:
module.exports = {
e2e: {
setupNodeEvents(on, config) {
on("before:run", details => {
console.log("Before run:")
exec("npm run cal", {}, handleExecOutput)
})
on("after:run", results => {
console.log("After run:")
exec("npm run cal", {}, handleExecOutput)
})
},
},
};
The cal script is defined in package.json as simply calling the native cal command, as a minimal test.
This is logging "Before run" and the calendar (not exactly together) before running the specs, and only "After run" after running the specs. However, if I change npm run cal to simply cal, the command is executed in both cases.
I’ve tried it with and without promises, with yarn and npm, always the same result. What am I missing?
I have a Nightwatch.js test suite running. When it completes, I've configured the output directory using the output_folder setting. It produces JUnit XML files in that directory correctly. I have an existing automation tool which scans the directory for JUnit test XML files and reports on them. Unfortunately it only matches files in the directory with a naming scheme: TEST-.xml. Let's assume that I can't change the matching rules on my automation tool. I'm looking for a way to add "TEST-" as a prefix to my tests. Ideally I can do this by configuring Nightwatch. Does Nightwatch support this configuration? I can't find any such options.
I ended up changing my test scripts in package.json so that they did a rename after the test was run. Here is what they were before:
{
// ...
"scripts": {
"integ-tests": "<some nightwatch command>"
}
// ...
}
Here is what they were after:
{
// ...
"scripts": {
"rename-integ-tests": "node -e \"require('fs').readdir('<my test directory>', (err, files) => { files.forEach(file => { if(file.endsWith('.xml') && ! file.startsWith('TEST-')) { fs.rename('<my test directory>' + file, '<my test directory>/TEST-' + file, function(err) { if (err) console.log(err); console.log('Renamed Smoke Test: ' + file + ' to TEST-' + file) }) } }); });\"",
"private-integ-tests": "<some nightwatch command>",
"integ-tests": "npm run private-integ-tests && npm run rename-integ-tests"
}
// ...
}
Here is my problem : in an AngularJS project, I use Babel 6 (ES2015 + stage3 + decorators), SystemJS and Karma + Jasmine.
All is OK, except for code coverage : I can't find a good way to get a coverage report on ES6 code instead of transpiled ES5.
I have some restrictions :
no Github npm dependencies
no deprecated projects (like isparta)
should run on Windows (yeah, I know, but I have to) and GNU/Linux
This question is especially oriented to a local html coverage report, but I also need a format that could be used in SonarQube.
There seems to be a huge lake of support on this question (especially with Decorators and SystemJS), so, along with some issues on Github, maybe the stackoverflow community could share a way to do this.
If you need some extras, you can see this project on Github (Sedona-Solutions/sdn-angularjs-seed), and look at the related issues (Sedona-Solutions/sdn-angularjs-seed#5) with references to all related issues and projects I could found.
About remap-istanbul
Here is my transpilation and mapping gulp task :
gulp.task('es6', function () {
return gulp.src(paths.source, { base: 'app' })
.pipe(plumber())
.pipe(changed(paths.output, { extension: '.js' }))
.pipe(sourcemaps.init())
.pipe(babel(compilerOptions))
.pipe(ngAnnotate({
sourceMap: true,
gulpWarnings: false
}))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(paths.output))
});
Karma-coverage
coverageReporter: {
reporters: [
{
type: 'json',
dir: 'target/coverage/',
subdir: '.',
file: 'coverage-final.json'
}
]
}
and the test:remap gulp task :
gulp.task('test:remap', ['test'], function (done) {
return gulp.src(paths.coverage + '/coverage-final.json')
.pipe(remapIstanbul({
reports: {
'json': paths.coverage + '/coverage.json',
'html': paths.coverage + '/html-remaped/'
},
fail: true,
useAbsolutePaths: true
}));
});
due to the first remap-istanbul issue, I get the following error :
C:\...\sdn-angularjs-seed\node_modules\remap-istanbul\node_modules\istanbul\lib\report\html.js:288
text = structuredText[startLine].text;
^
TypeError: Cannot read property 'text' of undefined
at C:\...\sdn-angularjs-seed\node_modules\remap-istanbul\node_modules\istanbul\lib\report\html.js:288:53
You can see the corresponding code on github.
It could be an error on some mapping generation, or paths ... If you think so, tell me.
karma-coverage + remap-istanbul should work fine
I have installed the chrome jet brains extension
I have tests like this:
describe('Service tests', function () {
beforeEach(module('app'));
it('should have a Service', inject(function($injector) {
var exist = $injector.has('dataService');
etc
but no luck getting breakpoints to hit any where in the tests. I can get the debugger to break when writing debugger, but an unable to step through.
Do you have karma-coverage set up in your karma config? It uses instrumented code, so debugging is not possible. Related tickets: http://github.com/karma-runner/karma/issues/630, http://youtrack.jetbrains.com/issue/WEB-8443
If you are building with Webpack you might need to specify the devtools option in your webpack config property in karma.conf.js like this:
module.exports = (config) => {
config.set({
webpack: {
...,
devtool: 'inline-source-map'
}
})
};
This solution works for me with Webpack v3.
If by any chance you are using Angular and you have removed all the coverage related stuff from your karma.config file and are still unable to hit the breakpoints, look into the angular.json. It might be having the codeCoverage bit set to true.
"test": {
...
"options": {
...
"codeCoverage": false,
...
}
...
}