Karma ClojureScript Test Adapter
karma-cljs-test is an adapter for the Karma test runner, enabling it to execute tests written with the ClojureScript `cljs.test` testing framework. First published 11 years ago, its latest and only version is 0.1.0, indicating it is no longer actively maintained. The package integrates into Karma's configuration by specifying 'cljs-test' as a framework. Its utility is highly specialized for projects using ClojureScript with Karma, a combination that has largely been superseded by other testing approaches within the ClojureScript ecosystem, such as `doo` or direct integration with modern test runners via `shadow-cljs` output. The core dependency, Karma, has also been deprecated, further limiting this adapter's relevance and support. There is no ongoing release cadence.
Common errors
-
Cannot find module 'karma-cljs-test'
cause The package was not installed or is not correctly discoverable by Karma.fixEnsure `karma-cljs-test` is listed in your `package.json`'s `devDependencies` and installed via `npm install` or `yarn install`. Also, verify that Karma's `plugins` configuration (if explicitly defined) includes `karma-cljs-test`. -
Error: Can not load 'cljs-test' framework!
cause Karma cannot find or load the `karma-cljs-test` plugin, usually because it's not installed or not correctly specified in the `frameworks` array.fixCheck your `karma.conf.js` to ensure `frameworks: ['cljs-test']` is present. Confirm `karma-cljs-test` is installed in `node_modules`. If you have a custom `plugins` array in your Karma config, ensure it includes `'karma-cljs-test'`. -
SyntaxError: Unexpected token 'export' (or similar errors related to ES modules in CJS context)
cause Running `karma-cljs-test` (and the older Karma versions it relies on) in a modern Node.js environment or with ClojureScript outputting ES modules can cause conflicts, as the toolchain was built for CommonJS and older JavaScript runtimes.fixEnsure your Node.js version is compatible with the old Karma 0.12.x series. Configure your ClojureScript compiler to output CommonJS or legacy JavaScript that is compatible with the old browser environments Karma 0.12.x supports. Modern ClojureScript with ES modules will likely require a different test runner setup. -
TypeError: Cannot read properties of undefined (reading 'run_with_karma')
cause The ClojureScript test runner function specified in `client.args` either doesn't exist, is misspelled, or hasn't been properly compiled and loaded into the browser context by Karma.fixVerify that your ClojureScript project is compiling successfully and producing the JavaScript file containing `app.test_runner.run_with_karma` (or your equivalent test runner). Check the `files` array in `karma.conf.js` to ensure all necessary compiled ClojureScript files are included and loaded in the correct order.
Warnings
- breaking The `karma-cljs-test` package is 11 years old (v0.1.0) and has not received updates since July 2015. It is highly unlikely to be compatible with modern Node.js versions, recent Karma releases, or current ClojureScript compilation toolchains (e.g., `shadow-cljs`) without significant issues or manual patching.
- deprecated The Karma test runner itself, the fundamental dependency for `karma-cljs-test`, has been officially deprecated. While critical security fixes may be provided for a limited time, active development and new features have ceased, impacting the long-term viability and support for any Karma-based testing solution.
- gotcha The `files` configuration in `karma.conf.js` is highly specific to the ClojureScript compilation output and project structure of the era when this package was active. Paths like `root + '/goog/base.js'` and `root + '/cljs_deps.js'` assume a Google Closure Compiler-based build without advanced optimizations, common with `lein-cljsbuild`. Modern ClojureScript build tools like `shadow-cljs` might produce different file structures or integrate testing differently.
- gotcha The adapter requires Karma `~0.12.0`. Attempting to use it with significantly newer versions of Karma (e.g., 1.x, 2.x, or the current 6.x) is very likely to lead to incompatibility errors due to breaking changes in Karma's API over time.
Install
-
npm install karma-cljs-test -
yarn add karma-cljs-test -
pnpm add karma-cljs-test
Imports
- karma.conf.js frameworks array
import { CljsTest } from 'karma-cljs-test'config.set({ frameworks: ['cljs-test'], // ... });
Quickstart
/* karma.conf.js */
module.exports = function(config) {
var root = 'target/public/dev'; // Adjust this path to your ClojureScript compiled output
config.set({
// Base path that will be used to resolve all relative paths for files and exclude.
basePath: '',
// Frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['cljs-test'],
// List of files / patterns to load in the browser
// These files are loaded in order. Ensure your ClojureScript runtime and application code are loaded before tests.
files: [
root + '/goog/base.js',
root + '/cljs_deps.js',
root + '/app.js', // Your main application/test runner entry point
{pattern: root + '/*.js', included: false},
{pattern: root + '/**/*.js', included: false}
],
// List of files to exclude
exclude: [],
// Client configuration for ClojureScript tests
client: {
args: ['app.test_runner.run_with_karma'] // Replace with your actual ClojureScript test runner function
},
// 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,
// Concurrency level
// how many browser should be started simultaneously
concurrency: Infinity
});
};
// To install:
// npm install --save-dev karma@~0.12.0 karma-cljs-test@~0.1.0 karma-chrome-launcher