Can't configure karma to use karma-spec-reporter - automated-tests

In my karma.conf.js
plugins : [
'karma-phantomjs-launcher',
'karma-angular-filesort',
'karma-coverage',
'karma-jasmine',
'karma-ng-html2js-preprocessor',
'karma-spec-reporter',
],
coverageReporter: {
type : 'html',
dir : 'coverage/'
},
specReporter: {
maxLogLines: 10,
suppressPassed: false,
suppressFailed: false,
suppressSkipped: false,
suppressErrorSummary: false
},
// reporters: ['progress']
reporters: ['spec']
Yet when I run my tests (gulp test), the output continues to be the same as when karma used the 'progress' reporter.
What am I missing?

Related

Module '"tapable"' has no exported member 'Tapable'

I was working on a WordPress plugin for a custom Gutenberg block.
Since I needed to add additional scripts which I wanted to write in TypeScript, I used "$ tsc --watch" and a "tsconfig.json"-file to compile them.
After installing #wordpress/scripts ("$ npm i --save-dev --save-exact #wordpress/scripts"), tsc indicated 89 errors at this path: node_modules#types\webpack\index.d.ts.
I have opened this file and found that the source of all the errors was the first line of this import statement:
import {
Tapable,
HookMap,
SyncBailHook,
SyncHook,
SyncLoopHook,
SyncWaterfallHook,
AsyncParallelBailHook,
AsyncParallelHook,
AsyncSeriesBailHook,
AsyncSeriesHook,
AsyncSeriesWaterfallHook,
} from 'tapable';
Tsc was still working for my files, but having 89 errors thrown each time I compile is concerning nonetheless.
This is the code of my tsconfig.json:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": false,
"declaration": false,
"resolveJsonModule": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2017"
],
"moduleResolution": "node",
"module": "esnext",
"target": "es2017",
"outDir": "script/build",
"noUnusedLocals": true,
"noUnusedParameters": true,
"jsx": "react",
"jsxFactory": "h"
},
"include": [
"script/src"
],
"exclude": [
"node_modules"
]
}
I found that the problem was the path of the import statement.
Webpack was importing Tapable from node_modules/tapable when it would have needed to import it from node_modules/#types/tapable.
Changing the last line of the import statement fixed all errors:
} from '../tapable';

No "clean" targets found

Please help, I use Grunt and try to do grunt clean command, but I have
No "clean" targets found.
message as a result. How can I fix that?
copy: {
build: {
files: [{
expand: true,
src: [
"fonts/**/*.{woff, woff2}",
"img/**",
"js/**",
"*.html"
],
dest: "build"
}]
}
},
сlean: {
build: ["build"]
}
});
grunt.registerTask("serve", ["browserSync", "watch"]);
grunt.registerTask('default', ['copy']);
grunt.registerTask("build", [
"clean",
"copy",
"sass",
"postcss",
"csso",
"imagemin"
]);
};
The problem is that the character c in clean - in the grunt configuration literal - is not what it appears to be. It's U+0441 - a Cyrillic letter.
If you retype it and ensure that it is an ANSI c - or copy and paste the word clean from the registerTask call - your grunt configuration should behave as you are expecting it to.

Is there an option for jscs and jshint in .jscsrc/.jshintrc to turn off linting for a directory?

I would like to disable linting for all files in a directory
For example
/
some.js <-LINT
noLint
file1.js <- NO LINT
file2.js <- NO LINT
subDir
file3.js <- NO LINT
I don't think that is possible. For jscs, I can imagine you can create a jscsrc that effectively disables all default rules. For example:
{
"validateLineBreaks": false,
"disallowMultipleVarDecl": false,
"validateIndentation": null
}
For jshint, you can try something similar:
{
"browser": true,
"jquery": true,
"mocha": true,
"node": true,
"curly": false,
"eqeqeq": false,
"maxdepth": 99,
"maxerr": 1000,
"undef": false,
"unused": false,
"esversion": 6,
"expr": true
}
So instead of disabling, you create settings that are as loose as possible.

jshint reporting variables undefined despite globals property defined in configuration

I have a feature-layer application and am writing a jshint gulp task for it.
This is the grunt task:
jshint : {
options : {
reporter : require("jshint-stylish"),
force : true
},
all : ["Gruntfile.js", "develop/modules/**/*.js", "develop/components/**/*.js"]
},
My .jshintrc file:
{
"curly" : true,
"eqeqeq": true,
"forin" : true,
"globals" : {
"angular" : false, <-- is not defined
"module" : false,
"console" : false <-- Is not defined
},
"latedef" : true,
"maxerr" : 150,
"undef": true,
"unused": true,
"strict": true
}
but the output when calling the task on the project is:
C:\Users\jason\Desktop\work\QAngular\angular>grunt jshint
Running "jshint:all" (jshint) task
develop/modules/login/login.js
line 1 col 1 Use the function form of "use strict".
line 3 col 1 'angular' is not defined.
line 12 col 13 'console' is not defined.
line 20 col 21 'angular' is not defined.
line 21 col 34 'angular' is not defined.
line 27 col 29 'console' is not defined.
line 31 col 29 'console' is not defined.
According to the documentation, the globals setting in .jshintrc is supposed to handle this. Its not. Are there any possibilities I missed
grunt-contrib-jshint does not use .jshintrc by default, you have to ask for it explicitly by setting jshint.options.jshintrc to true or a filepath (https://www.npmjs.com/package/grunt-contrib-jshint#jshintrc):
jshint : {
options : {
jshintrc: true,
reporter : require("jshint-stylish"),
force : true
},
all : ["Gruntfile.js", "develop/modules/**/*.js", "develop/components/**/*.js"]
},

how to use multiple mochacov reporters in single Gruntfile and get the coverage report

Currently am switching between html-cov and json-cov in my gruntfile and running the command
grunt mochacov:all > coverage.html
(or)
grunt mochacov:all > coverage.json
Here is the json portion of config from my Gruntfile.js :
mochacov : {
options : {
reporter : 'json-cov',
//reporter : 'travis-cov',
require : ['should'],
timeout: 250000,
//quiet : true,
output : 'coverage.json',
},
all: ['test/test-*.js']
},
Is there anyway using which i can get both coverage.html and coverage.json in the output by default by specifying both html-cov and json-cov somehow?
Sadly, looks like by default grunt-mocha-cov doesn't support this, as the reporter only accepts a 'string' (per the docs).
Theoretically this should be possible with a grunt multitask.
I have found out the answer for the same :-
This is what we need to have in our Gruntfile.js
mochacov: {
jsoncoverage: {
options: {
reporter: 'json-cov',
//reporter : 'travis-cov',
require: ['should'],
timeout: 250000,
//quiet : true,
output: 'reports/coverage.json'
},
all: ['test/test-*.js']
},
htmlcoverage: {
options: {
reporter: 'html-cov',
//reporter : 'travis-cov',
require: ['should'],
timeout: 250000,
//quiet : true,
output: 'reports/coverage.html'
},
all: ['test/test-*.js']
}
}
//and then the following line needs to be there :
grunt.registerTask('mochacoverage', ['mochacov:jsoncoverage', 'mochacov:htmlcoverage']);
Then we can run it using grunt mochacoverage and it will do both html and json

Resources