cant get junit running with Karma - junit

I have installed the npm package karma-junit-reporter at version 2.0.1.
my karma.conf.js file is :
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '#angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-junit-reporter'),
require('karma-coverage-istanbul-reporter'),
require('#angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
captureConsole: true
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/ClientApp'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml', 'junit'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true,
// the default configuration
junitReporter: {
outputDir: 'test', // results will be saved as $outputDir/$browserName.xml
outputFile: 'junit.xml', // if included, results will be saved as $outputDir/$browserName/$outputFile
//suite: '', // suite will become the package name attribute in xml testsuite element
//useBrowserName: false, // add browser name to report and classes names
//nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
//classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
//properties: {}, // key value pair of properties to add to the <properties> section of the report
//xmlVersion: null // use '1' if reporting to be per SonarQube 6.2 XML format
}
});
};
When I run:
ng test --reporters junit
I receive the following error:
can not load reporter "junit", it is not registered! Perhaps you are missing some plugin?
[karma]: No captured browser, open http://localhost:9876/

Ok. I found the answer by chance. Really weird, but this worked. I needed to explicitly mention the config file :
ng test --karma-config=karma.conf.js --reporters junit
it now works even though I was running the ng test command from the same directory as my karma.conf.js file

Related

#rollup/plugin-json with typescript not working

I have a valid appsettings.json file (according to jsonlint.com), I've set the tsconfig resolveJsonModule option to true. I'm importing #rollup/plugin-json and I've tried calling it at every position in the plugins chain. But I always get:
(!) Plugin json: Could not parse JSON file
appsettings.json
[!] Error: Unexpected token (Note that you need #rollup/plugin-json to import JSON files)
appsettings.json (2:10)
So the plugin is firing (I think), but it can't parse the file, which seems to be valid. Rollup config looks like this:
import typescript from '#rollup/plugin-typescript';
import resolve from '#rollup/plugin-node-resolve';
import commonjs from "#rollup/plugin-commonjs";
import dev from 'rollup-plugin-dev';
import copy from 'rollup-plugin-copy';
import replace from '#rollup/plugin-replace';
// Loaders for non-ts/js file types
import postcss from 'rollup-plugin-postcss';
import image from '#rollup/plugin-image';
import json from '#rollup/plugin-json';
console.log(`Node env is ${process.env.NODE_ENV}`);
// console.debug(process);
let isDevEnv = process.env.NODE_ENV === 'development';
let useMsw = process.env.USE_MSW;
const extensions = ['.cjs', '.js', '.jsx', '.json', '.ts', '.tsx', '.css', '.png'];
// const intro = useMsw
// ? 'global = window; window.NODE_ENV = process.env.NODE_ENV; window.USE_MSW = true'
// : 'global = window; window.NODE_ENV = process.env.NODE_ENV; window.USE_MSW = false';
const intro = `global = window; window.NODE_ENV = process.env.NODE_ENV; ${useMsw ? 'window.USE_MSW = true;' : ''}`;
export default {
input: [
'src/index.tsx'
],
output: {
intro: intro,
file: './dist/bundle.js',
format: 'es',
sourcemap: isDevEnv,
inlineDynamicImports: true,
},
plugins: [
postcss({}),
resolve({
extensions: extensions,
browser: true
}),
commonjs(),
typescript(),
replace({
'process.env.NODE_ENV': JSON.stringify('development')
}),
image(),
copy({
targets: [
{src: './src/index.html', dest: './dist/'},
{src: './src/mockServiceWorker.js', dest: './dist/'}
],
verbose: true
}),
isDevEnv && dev('dist', {
host: 'localhost'
}),
json(),
]
};
tsconfig looks like this:
{
"compilerOptions": {
"declaration": false,
"module": "ESNext",
"noImplicitAny": true,
"target": "ES2015",
"jsx": "react",
"allowSyntheticDefaultImports": true,
"allowJs": true,
"moduleResolution": "Node",
"esModuleInterop": true,
"resolveJsonModule": true
},
"include": [
"src/**/*.tsx",
"src/**/*.ts",
"declaration.d.ts",
"src/components/TabularVIew/GridContainer/hooks"
],
"exclude": ["node_modules"]
}
and the actual json file looks like this:
{
"HUB_URL": "theHubUrl",
"AUTH_ENDPOINT": "https://localhost:44330/API/Dispatch/Authentication/v1.0/authenticate",
"POSITION_ENDPOINT": "https://localhost:44330/API/Dispatch/Data/v1.0/position",
"SUMMARY_ENDPOINT": "https://localhost:44330/API/Dispatch/Data/v1.0/summaries",
"GLOBAL_TLM": 1,
"PERIOD_LENGTH_MINUTES": 30,
"EFA_BLOCKS": [
[23,0,1,2],
[3,4,5,6],
[7,8,9,10],
[11,12,13,14],
[15,16,17,18],
[19,20,21,22]
]
}
and the rollup output is this:
(!) Plugin json: Could not parse JSON file
appsettings.json
[!] Error: Unexpected token (Note that you need #rollup/plugin-json to import JSON files)
appsettings.json (2:10)
Pretty frustrating because on one line it says 'plugin json can't parse', then the next log line tells me I need plugin json???. Invalid file, file not found, plugin not installed, these I could understand. Possibly a clash between tsc and the plugin. Out of ideas..
Suggestions welcome.
Thanks.
The reason for that can be the json file encoding is utf8withbom. Try to encode the file as utf8.
Not really an answer, but the behaviour appears to be linked to some aggressive caching. Either by npm or typescript. I opened up the project in vscode, hosed node_modules, ran npm install, usual drill.. created a new JSON file, installed the rollup json plugin, and it built. Sum total of learning: 0;

Gulp Jscs - TypeError: Cannot convert undefined or null to object

I wanted to use gulp-jscs in my project, so I've installed it according the documentation:
npm install --save-dev gulp-jscs
But when I try to run the gulp file, I'm getting this error:
TypeError: Cannot convert undefined or null to object
at Function.keys (native)
at copyConfiguration (C:\Users\[User]\Desktop\[Project]\
node_modules\jscs\lib\config\configuration.js:920:12)
Also, there are other errors related to this:
at NodeConfiguration.Configuration.
_processConfig([location-path]\node_modules\jscs\lib\config\configuration.js:459:5)
at NodeConfiguration.Configuration.load
([location-path]\node_modules\jscs\lib\config\configuration.js:211:10)
at null.StringChecker.configure
([location-path]\node_modules\jscs\lib\string-checker.js:62:29)
at null.Checker.configure ([location-path]\node_modules\jscs\lib\checker.js:27:39)
at Object.module.exports ([location-path]\node_modules\gulp-jscs\index.js:35:10)
at Gulp.<anonymous> ([location-path]\Gulpfile.js:60:17)
at module.exports ([location-path]\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask ([location-path]\node_modules\orchestrator\index.js:273:3)
Process terminated with code 1.
You need to have a .jscsrc file in the root of you project present. In there you can provide options for JSCS as well as the code style rules that should be followed.
Below is the .jscsrc that's used by node-jscs project itself. You can use this to base your own configuration on.
{
"preset": "google",
"fileExtensions": [".js", "jscs"],
"requireSemicolons": true,
"requireParenthesesAroundIIFE": true,
"maximumLineLength": 120,
"validateLineBreaks": "LF",
"validateIndentation": 4,
"disallowTrailingComma": true,
"disallowUnusedParams": true,
"disallowSpacesInsideObjectBrackets": null,
"disallowImplicitTypeConversion": ["string"],
"safeContextKeyword": "_this",
"jsDoc": {
"checkAnnotations": "closurecompiler",
"checkParamNames": true,
"requireParamTypes": true,
"checkRedundantParams": true,
"checkReturnTypes": true,
"checkRedundantReturns": true,
"requireReturnTypes": true,
"checkTypes": "capitalizedNativeCase",
"checkRedundantAccess": true,
"requireNewlineAfterDescription": true
},
"excludeFiles": [
"test/data/**",
"patterns/*"
]
}
Note that jscs won't actually check for anything unless you have a "preset" in your .jscsrc or have explicitly specified the rules that should be followed.

Protractor-cucumber report: result.json is empty

After i follow this question Cucumber HTML report with Protractor to add this line to config file resultJsonOutputFile: 'report.json', i can generate report.json file but this file is empty after i run my test.
---------------conf.js--------------
exports.config = {
allScriptTimeout: 60000, //To set up a timeout for each test executed on Protractor
baseUrl: 'http://localhost/wp/index.php',
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
//seleniumServerJar: 'selenium-server-standalone-2.48.2.jar',
framework: 'cucumber',
specs: [
'Feature/login.feature'
],
capabilities: {
browserName: 'firefox',
},
onPrepare : function () {
//driver.manage().window().setSize( width, height );
global.driver = browser.driver;
browser.ignoreSynchronization = true;
},
resultJsonOutputFile: 'report.json',
cucumberOpts: {
require: 'Feature/Steps/*_steps.js',
format: 'pretty',
defaultTimeoutInterval: 30000
}
};
Am i doing wrong or missing with my config? Could you help me give a guide to generate report for protractor-cucumber? Thank so much.
Changing the following code should solve the issue. (Refresh the folder in IDE to view the report.json)
// resultJsonOutputFile: 'report.json',
cucumberOpts: {
require: 'Feature/Steps/*_steps.js',
format: 'pretty',
format:'json:../report.json'
}

gulp and karma, file karma.conf.js does not exist

I have a basic AngularJS app and want to have all my terminal command run with gulp tasks eg $ gulp dev for the development server and $ gulp unitTest for testing etc.
I have installed Gulp as per the Docs using $ npm install --save-dev gulp with my gulpfile.js in the root of the project file. I have also done the same for karma's install and config file.
It is worth stating now that I want all the npm installs tagged with --save for easily move the project around the office and servers.
When it comes to adding the task to Gulp I have to us a relative (to the karma module) path for the configFile option to find the config but then It does not find the tests.
the following gulpfile.js produces the error ERROR [config]: File karma.conf.js does not exist!
var gulp = require('gulp'),
// ....
karma = require('karma').Server;
gulp.task('test', function(done) {
var karmaServerOptions = {
configFile: 'karma.conf.js', // works if relative path from ./node_modules/karma/lib/config.js
singleRun: true
};
karma.start(
karmaServerOptions,
function(exitStatus) {
done(exitStatus ? 'There are failing tests' : undefined);
}
);
});
karma.conf.js:
// Karma configuration
// Generated on Thu Aug 06 2015 13:38:12 GMT+0100 (BST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: './',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
// '**/*js',
'node_modules/angular/angular.js',
'app/**/*.js',
// 'unitTests/**/*Spec.js',
// 'unitTests/**/*spec.js'
'unitTests/**/*.js'
],
// list of files to exclude
exclude: [],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
})
}
note: The files array is a bit of a mess as it still has some, but not all, of my experiments in it.
See gulp task can't find karma.conf.js for an explantation about __dirname.
Or use:
var Server = require('karma').Server
gulp.task('test', function (done) {
new Server({
configFile: require('path').resolve('karma.conf.js'),
singleRun: true
}, done).start();
});

browserify, karma, jasmine and gulp not running tests even after setting config

I followed the instructions here https://www.npmjs.com/package/karma-browserify and even after setting the karma.conf.js with the following it does not run any tests in PhantomJS or Chrome. It says Executed 0 of 0 ERROR even though I have one dummy spec file in test folder which passes.
karma.set({
basePath: 'to/some/somepath'
frameworks: ['browserify', 'jasmine' ],
files: ['relative/to/somepath/test/**/*.js'],
preprocessors: {
'relative/to/somepath/test/**/*.js': ['browserify']
},
browserify: {
debug: true
}
});