
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
karma-mocha
Advanced tools
Adapter for the Mocha testing framework.
Install karma-mocha
and mocha
into to your project via npm
:
$ npm install karma-mocha mocha --save-dev
karma-mocha
should work with any version of mocha
.
Since karma-mocha
is an adapter for Karma, you likely have it installed already, but in case you don't:
$ npm install karma --save-dev
If you're having trouble, Karma provides detailed instructions on installation.
Following code shows the default configuration...
// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['mocha'],
files: [
'*.js'
]
});
};
If you want to pass configuration options directly to mocha you can do this in the following way
// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['mocha'],
files: [
'*.js'
],
client: {
mocha: {
// change Karma's debug.html to the mocha web reporter
reporter: 'html',
// require specific files after Mocha is initialized
require: [require.resolve('bdd-lazy-var/bdd_lazy_var_global')],
// custom ui, defined in required file above
ui: 'bdd-lazy-var/global',
}
}
});
};
If you want run only some tests matching a given pattern you can do this in the following way
karma start &
karma run -- --grep=<pattern>
or
module.exports = function(config) {
config.set({
...
client: {
mocha: {
grep: '<pattern>', // passed directly to mocha
...
}
...
}
});
};
If you want to expose test properties specific to mocha
, you can use the expose
option:
module.exports = function(config) {
config.set({
...
client: {
mocha: {
expose: ['body'] // This will be exposed in a reporter as `result.mocha.body`
...
}
...
}
});
};
If you already have a configuration for Mocha in an opts file, you can use the opts
option:
module.exports = function(config) {
config.set({
...
client: {
mocha: {
opts: 'test/mocha.opts' // You can set opts to equal true then plugin will load opts from default location 'test/mocha.opts'
...
}
...
}
});
};
On the end of each test karma-mocha
passes to karma
result object with fields:
description
Test title.suite
List of titles of test suites.success
True if test is succeed, false otherwise.skipped
True if test is skipped.time
Test duration.log
List of errors.startTime
Milliseconds since epoch that the test startedendTime
Milliseconds since epoch that the test endedassertionErrors
List of additional error info:
name
Error name.message
Error message.actual
Actual data in assertion, serialized to string.expected
Expected data in assertion, serialized to string.showDiff
True if it is configured by assertion to show diff.mocha
An optional object listed if you use the expose
optionThis object will be passed to test reporter.
NB. the start and end times are added by the adapter whereas the duration is calculated by Mocha - as such they probably will not match arithmetically. Ie. endTime - startTime !== duration
. These fields have been added so that timestamped reports can be matched up with other timestamped reports from the target device (eg. memory profiling data collected outside the browser)
For more information on Karma see the homepage.
2.0.1 (2020-04-29)
<a name="1.3.0"></a>
The karma-jasmine package is a plugin that allows you to use the Jasmine testing framework with the Karma test runner. Like karma-mocha, it enables you to run tests in various browsers. Jasmine is known for its behavior-driven development (BDD) style and comes with a rich set of matchers and utilities.
The karma-qunit package is a plugin that integrates the QUnit testing framework with the Karma test runner. QUnit is a powerful, easy-to-use JavaScript unit testing framework. It is used by the jQuery project and is known for its simplicity and ease of use.
The karma-chai package allows you to use the Chai assertion library with the Karma test runner. Chai can be used with different testing frameworks like Mocha, Jasmine, and QUnit. It provides a variety of assertion styles, including BDD and TDD, making it a versatile choice for testing.
FAQs
A Karma plugin. Adapter for Mocha testing framework.
The npm package karma-mocha receives a total of 355,996 weekly downloads. As such, karma-mocha popularity was classified as popular.
We found that karma-mocha demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.