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
}
});
Related
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
Already seen many topics here but none of the pointed solutions worked.
When optimizing my project, R.js is failing to handle this json! plugin dependency on one of my modules.
Error message:
Tracing dependencies for: app/productApp
TypeError: errback is not a function
In module tree:
app/productApp
blah
json
My r.js build config file:
define([
'productApp',
'json!blah'
], function(...){...}
and here is my r.js config file:
({
name: 'app/productApp',
out: '../app.js',
optimize: 'uglify2',
findNestedDependencies: true,
inlineJSON: false,
inlineText: false,
exclude: [ 'json!blah' ]
)}
I've already tried all possible ways, such as an exclude on the r.js config file, or and adding '!bust' at the end of the dependency list, but no luck.
Require.js / R.js version: 2.2.0
One detail: I'm running r.js through node package.json script, triggered by maven.
Thoughts?
Found the solution. It turns out that the paths to the json and text libraries were missing from require config file. (it can't be just made 'empty:' within r.js build config file).
This then would fix the issue:
...
paths: {
'text': 'lib/text',
'json': 'lib/json',
...
},
exclude: {
'json!blah'
}
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();
});
I get the following error when running gulp test:
Error: Please run node with the --harmony flag!
Here is my gulp task:
var jest = require('gulp-jest');
gulp.task('test', function() {
return gulp.src('src/**/__tests__').pipe(jest({
rootDir: 'src',
scriptPreprocessor: '../node_modules/6to5-jest',
unmockedModulePathPatterns: [ 'react' ]
}));
});
To reproduce: https://github.com/SEEK-Jobs/react-playground
Note that npm test works properly (test is failing as expected), but gulp test fails with the error above. Both npm test and gulp test have the same config object:
{
rootDir: 'src',
scriptPreprocessor: '../node_modules/6to5-jest',
unmockedModulePathPatterns: [ 'react' ]
}
What am I doing wrong?
As far as I can tell the error is thrown from jest-cli.
The reason you don't get it with npm test is that you probably configured npm to run the jest bin script directly, which uses harmonize to programmatically set the --harmony flag.
You can fix by installing harmonize and putting require('harmonize')() in your gulpfile.
It was a bug in gulp-eslint, and it is fixed now in version 0.3.0.
I am following this guide to generate junit output from my js tests:
https://github.com/sbrandwoo/grunt-qunit-junit
I have installed grunt-qunit-junit into my local test project:
npm install grunt-contrib-qunit --save-dev
And this is my Gruntfile.js:
module.exports = function(grunt) {
"use:strict";
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
qunit_junit: {
options: {
},
all: ["all_tests.html"]
},
})
grunt.loadNpmTasks('grunt-qunit-junit');
};
where all_tests.html is located in the same dir and lists all my *test.js files. But when I run:
user#ubuntu:~/Test$ grunt qunit_junit
Running "qunit_junit" task
>> XML reports will be written to _build/test-reports
Done, without errors.
Why are the tests not executed (the folder _build/test-reports is not created)?
The README states that you should execute both the qunit_junit and qunit tasks: http://github.com/sbrandwoo/grunt-qunit-junit#usage-examples
For example: grunt.registerTask('test', ['qunit_junit', 'qunit']);