Reputation: 2256
I am running javascript tests with functionality compiled by webpack in Karma. It seems that sources are compiled but not processed by karma, no test run. testing.webpack.js
module.exports = {
devtool: 'inline-source-map',
resolve: {
extensions: ['.js']
},
module: {
rules: [
{
test: /\.js$/,
exclude: [/node_modules/],
use: [{
loader: 'babel-loader',
}]
}
]
}
};
There is my karma.conf.js
const webpackConfig = require('./testing.webpack.js');
module.exports = function (config) {
config.set({
basePath: './',
coverageReporter: {
dir: 'tmp/coverage/',
reporters: [
{ type: 'html', subdir: 'report-html' },
{ type: 'lcov', subdir: 'report-lcov' }
],
instrumenterOptions: {
istanbul: { noCompact: true }
}
},
files: [
'spec/**/*.spec.js'
],
frameworks: ['should', 'jasmine', 'mocha'],
reporters: ['mocha', 'coverage'],
preprocessors: {
'spec/**/*.spec.js': ['webpack', 'sourcemap']
},
plugins: [
'karma-webpack',
'karma-jasmine',
'karma-mocha',
'karma-should',
'karma-coverage',
'karma-chrome-launcher',
'karma-phantomjs-launcher',
'karma-mocha-reporter',
'karma-sourcemap-loader'
],
webpack: webpackConfig,
webpackMiddleware: {
stats: 'errors-only'
}
});
return config;
};
I receive the following output:
npx karma start karma.conf.js --single-run --browsers Chrome --debug
14 12 2020 15:54:55.608:DEBUG [config]: Loading config /home/victor/github/victor-shelepen/instance-locator/karma.conf.js
14 12 2020 15:54:55.612:DEBUG [config]: autoWatch set to false, because of singleRun
14 12 2020 15:54:55.613:DEBUG [karma-server]: Final config Config {
LOG_DISABLE: 'OFF',
LOG_ERROR: 'ERROR',
LOG_WARN: 'WARN',
LOG_INFO: 'INFO',
LOG_DEBUG: 'DEBUG',
frameworks: [ 'should', 'jasmine', 'mocha' ],
protocol: 'http:',
port: 9876,
listenAddress: '0.0.0.0',
hostname: 'localhost',
httpsServerConfig: {},
basePath: '/home/victor/github/victor-shelepen/instance-locator',
files: [
Pattern {
pattern: '/home/victor/github/victor-shelepen/instance-locator/spec/**/*.spec.js',
served: true,
included: true,
watched: false,
nocache: false,
weight: [ 1, 1, 1, 0, 0, 0 ],
type: undefined,
isBinary: undefined
}
],
browserConsoleLogOptions: { level: 'debug', format: '%b %T: %m', terminal: true },
customContextFile: null,
customDebugFile: null,
customClientContextFile: null,
exclude: [
'/home/victor/github/victor-shelepen/instance-locator/karma.conf.js'
],
logLevel: 'DEBUG',
colors: true,
autoWatch: false,
autoWatchBatchDelay: 250,
restartOnFileChange: false,
usePolling: true,
reporters: [ 'mocha', 'coverage' ],
singleRun: true,
browsers: [ 'Chrome' ],
captureTimeout: 60000,
pingTimeout: 5000,
proxies: {},
proxyValidateSSL: true,
preprocessors: [Object: null prototype] {
'/home/victor/github/victor-shelepen/instance-locator/spec/**/*.spec.js': [ 'webpack', 'sourcemap' ]
},
preprocessor_priority: {},
urlRoot: '/',
upstreamProxy: undefined,
reportSlowerThan: 0,
loggers: [
{
type: 'console',
layout: { type: 'pattern', pattern: '%[%d{DATE}:%p [%c]: %]%m' }
}
],
transports: [ 'polling', 'websocket' ],
forceJSONP: false,
plugins: [
'karma-webpack',
'karma-jasmine',
'karma-mocha',
'karma-should',
'karma-coverage',
'karma-chrome-launcher',
'karma-phantomjs-launcher',
'karma-mocha-reporter',
'karma-sourcemap-loader'
],
client: {
args: [],
useIframe: true,
runInParent: false,
captureConsole: true,
clearContext: true
},
defaultClient: {
args: [],
useIframe: true,
runInParent: false,
captureConsole: true,
clearContext: true
},
browserDisconnectTimeout: 2000,
browserDisconnectTolerance: 0,
browserNoActivityTimeout: 30000,
processKillTimeout: 2000,
concurrency: Infinity,
failOnEmptyTestSuite: true,
retryLimit: 2,
detached: false,
crossOriginAttribute: true,
browserSocketTimeout: 20000,
cmd: 'start',
debug: true,
configFile: '/home/victor/github/victor-shelepen/instance-locator/karma.conf.js',
coverageReporter: {
dir: 'tmp/coverage/',
reporters: [
{ type: 'html', subdir: 'report-html' },
{ type: 'lcov', subdir: 'report-lcov' }
],
instrumenterOptions: { istanbul: { noCompact: true } }
},
webpack: {
devtool: 'inline-source-map',
resolve: { extensions: [ '.js' ] },
module: {
rules: [
{
test: /\.js$/,
exclude: [ /node_modules/ ],
use: [ { loader: 'babel-loader' } ]
}
]
}
},
webpackMiddleware: { stats: 'errors-only' }
}
14 12 2020 15:54:55.614:DEBUG [plugin]: Loading plugin karma-webpack.
14 12 2020 15:54:55.664:DEBUG [plugin]: Loading plugin karma-jasmine.
14 12 2020 15:54:55.665:DEBUG [plugin]: Loading plugin karma-mocha.
14 12 2020 15:54:55.666:DEBUG [plugin]: Loading plugin karma-should.
14 12 2020 15:54:55.667:DEBUG [plugin]: Loading plugin karma-coverage.
14 12 2020 15:54:55.914:DEBUG [plugin]: Loading plugin karma-chrome-launcher.
14 12 2020 15:54:55.920:DEBUG [plugin]: Loading plugin karma-phantomjs-launcher.
14 12 2020 15:54:55.938:DEBUG [plugin]: Loading plugin karma-mocha-reporter.
14 12 2020 15:54:55.941:DEBUG [plugin]: Loading plugin karma-sourcemap-loader.
14 12 2020 15:54:55.956:DEBUG [web-server]: Instantiating middleware
14 12 2020 15:54:55.957:DEBUG [reporter]: Trying to load reporter: mocha
14 12 2020 15:54:55.958:DEBUG [reporter]: Trying to load color-version of reporter: mocha (mocha_color)
14 12 2020 15:54:55.959:DEBUG [reporter]: Couldn't load color-version.
14 12 2020 15:54:55.959:DEBUG [reporter]: Trying to load reporter: coverage
14 12 2020 15:54:55.959:DEBUG [reporter]: Trying to load color-version of reporter: coverage (coverage_color)
14 12 2020 15:54:55.959:DEBUG [reporter]: Couldn't load color-version.
START:
Webpack bundling...
asset runtime.js 11.4 KiB [compared for emit] (name: runtime)
asset commons.js 989 bytes [compared for emit] (name: commons) (id hint: commons)
asset another.spec.4218216441.js 175 bytes [compared for emit] (name: another.spec.4218216441)
Entrypoint another.spec.4218216441 12.5 KiB = runtime.js 11.4 KiB commons.js 989 bytes another.spec.4218216441.js 175 bytes
webpack 5.10.1 compiled successfully in 204 ms
14 12 2020 15:54:56.659:INFO [karma-server]: Karma v5.2.3 server started at http://localhost:9876/
14 12 2020 15:54:56.659:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
14 12 2020 15:54:56.662:INFO [launcher]: Starting browser Chrome
14 12 2020 15:54:56.662:DEBUG [launcher]: null -> BEING_CAPTURED
14 12 2020 15:54:56.663:DEBUG [temp-dir]: Creating temp dir at /tmp/karma-27533261
14 12 2020 15:54:56.663:DEBUG [launcher]: google-chrome --user-data-dir=/tmp/karma-27533261 --enable-automation --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-renderer-backgrounding --disable-device-discovery-notifications http://localhost:9876/?id=27533261
14 12 2020 15:54:57.068:DEBUG [web-server]: serving: /home/victor/github/victor-shelepen/instance-locator/node_modules/karma/static/client.html
14 12 2020 15:54:57.150:DEBUG [web-server]: serving: /home/victor/github/victor-shelepen/instance-locator/node_modules/karma/static/karma.js
14 12 2020 15:54:57.229:DEBUG [karma-server]: A browser has connected on socket RYAt3YKj13i66X8RAAAA
14 12 2020 15:54:57.278:DEBUG [Chrome 87.0.4280.88 (Linux x86_64)]: undefined -> CONNECTED
14 12 2020 15:54:57.279:INFO [Chrome 87.0.4280.88 (Linux x86_64)]: Connected on socket RYAt3YKj13i66X8RAAAA with id 27533261
14 12 2020 15:54:57.280:DEBUG [launcher]: BEING_CAPTURED -> CAPTURED
14 12 2020 15:54:57.280:DEBUG [launcher]: Chrome (id 27533261) captured in 0.621 secs
14 12 2020 15:54:57.280:DEBUG [Chrome 87.0.4280.88 (Linux x86_64)]: CONNECTED -> CONFIGURING
14 12 2020 15:54:57.289:DEBUG [web-server]: serving: /home/victor/github/victor-shelepen/instance-locator/node_modules/karma/static/favicon.ico
14 12 2020 15:54:57.292:DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=RYAt3YKj13i66X8RAAAA
14 12 2020 15:54:57.323:DEBUG [middleware:karma]: custom files null null null
14 12 2020 15:54:57.323:DEBUG [middleware:karma]: Serving static request /context.html
14 12 2020 15:54:57.325:DEBUG [web-server]: serving: /home/victor/github/victor-shelepen/instance-locator/node_modules/karma/static/context.html
14 12 2020 15:54:57.346:DEBUG [middleware:source-files]: Requesting /base/node_modules/mocha/mocha.js?143074c949211f445d6c1a8a431990c9849bf6ae
14 12 2020 15:54:57.347:DEBUG [middleware:source-files]: Fetching /home/victor/github/victor-shelepen/instance-locator/node_modules/mocha/mocha.js
14 12 2020 15:54:57.347:DEBUG [web-server]: serving (cached): /home/victor/github/victor-shelepen/instance-locator/node_modules/mocha/mocha.js
14 12 2020 15:54:57.352:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-mocha/lib/adapter.js?a0f4bbc139407501892ac58d70c2791e7adec343
14 12 2020 15:54:57.352:DEBUG [middleware:source-files]: Fetching /home/victor/github/victor-shelepen/instance-locator/node_modules/karma-mocha/lib/adapter.js
14 12 2020 15:54:57.352:DEBUG [web-server]: serving (cached): /home/victor/github/victor-shelepen/instance-locator/node_modules/karma-mocha/lib/adapter.js
14 12 2020 15:54:57.353:DEBUG [middleware:source-files]: Requesting /base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?8f66117bbfbdf7b03a8f43bc667e3a4421ce15de
14 12 2020 15:54:57.353:DEBUG [middleware:source-files]: Fetching /home/victor/github/victor-shelepen/instance-locator/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
14 12 2020 15:54:57.354:DEBUG [web-server]: serving (cached): /home/victor/github/victor-shelepen/instance-locator/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
14 12 2020 15:54:57.354:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/boot.js?760d54bbca4f739f1f8b252c1636d76201cc4e88
14 12 2020 15:54:57.355:DEBUG [middleware:source-files]: Fetching /home/victor/github/victor-shelepen/instance-locator/node_modules/karma-jasmine/lib/boot.js
14 12 2020 15:54:57.355:DEBUG [web-server]: serving (cached): /home/victor/github/victor-shelepen/instance-locator/node_modules/karma-jasmine/lib/boot.js
14 12 2020 15:54:57.356:DEBUG [web-server]: serving: /home/victor/github/victor-shelepen/instance-locator/node_modules/karma/static/context.js
14 12 2020 15:54:57.370:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/adapter.js?c22f41e6dc6770beb0be7c86dfade9637bce9290
14 12 2020 15:54:57.370:DEBUG [middleware:source-files]: Fetching /home/victor/github/victor-shelepen/instance-locator/node_modules/karma-jasmine/lib/adapter.js
14 12 2020 15:54:57.370:DEBUG [web-server]: serving (cached): /home/victor/github/victor-shelepen/instance-locator/node_modules/karma-jasmine/lib/adapter.js
14 12 2020 15:54:57.372:DEBUG [middleware:source-files]: Requesting /base/node_modules/should/should.js?1aa5493eba423eb3fbfa86274d47aff5d2defc34
14 12 2020 15:54:57.372:DEBUG [middleware:source-files]: Fetching /home/victor/github/victor-shelepen/instance-locator/node_modules/should/should.js
14 12 2020 15:54:57.373:DEBUG [web-server]: serving (cached): /home/victor/github/victor-shelepen/instance-locator/node_modules/should/should.js
14 12 2020 15:54:57.374:DEBUG [middleware:source-files]: Requesting /absoluteanother.spec.4218216441.js?144f72c8ebc6aafdd231efe77b325a86fb00deba
14 12 2020 15:54:57.374:DEBUG [middleware:source-files]: Fetching another.spec.4218216441.js
14 12 2020 15:54:57.374:DEBUG [web-server]: serving (cached): another.spec.4218216441.js
14 12 2020 15:54:57.444:DEBUG [Chrome 87.0.4280.88 (Linux x86_64)]: CONFIGURING -> EXECUTING
14 12 2020 15:54:57.446:DEBUG [Chrome 87.0.4280.88 (Linux x86_64)]: EXECUTING -> CONNECTED
14 12 2020 15:54:57.447:DEBUG [launcher]: CAPTURED -> BEING_KILLED
14 12 2020 15:54:57.447:DEBUG [launcher]: BEING_KILLED -> BEING_FORCE_KILLED
Finished in 0.002 secs / 0 secs @ 15:54:57 GMT+0200 (Eastern European Standard Time)
SUMMARY:
✔ 0 tests completed
14 12 2020 15:54:57.456:DEBUG [karma-server]: Run complete, exiting.
14 12 2020 15:54:57.457:DEBUG [launcher]: Disconnecting all browsers
14 12 2020 15:54:57.457:DEBUG [launcher]: BEING_FORCE_KILLED -> BEING_FORCE_KILLED
14 12 2020 15:54:57.457:DEBUG [proxy]: Destroying proxy agents
14 12 2020 15:54:57.486:DEBUG [coverage]: Writing coverage to /home/victor/github/victor-shelepen/instance-locator/tmp/coverage/report-html
14 12 2020 15:54:57.492:DEBUG [coverage]: Writing coverage to /home/victor/github/victor-shelepen/instance-locator/tmp/coverage/report-lcov
14 12 2020 15:54:57.500:DEBUG [launcher]: Process Chrome exited with code 0 and signal null
14 12 2020 15:54:57.500:DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-27533261
14 12 2020 15:54:57.536:DEBUG [launcher]: Finished all browsers
14 12 2020 15:54:57.537:DEBUG [launcher]: BEING_FORCE_KILLED -> FINISHED
14 12 2020 15:54:57.537:DEBUG [launcher]: FINISHED -> FINISHED
I see that it has been compiled. another.spec.4218216441.js another.spec.js
describe('Testing', () => {
it('G', () => {
should(1).be(1);
});
});
But no test run. I will be pleased with a tip. Thank you.
Upvotes: 1
Views: 1805
Reputation: 843
Previously when using the alpha version of karma-webpack 5, if you did not include 'webpack' as a framework in your karma configuration everything would build, but no tests would be run just like this. 5.0.0 stable has been released that addresses this issue and fixes that on the fly. If you update to that it should work fine.
Upvotes: 2