У меня есть набор юнит-тестов Mocha + Chai. Они успешно работают на странице HTML, а также в Карме (с использованием Headless Chrome). Классы определены в различных файлах, и соответствующие файлы включаются в тесты с использованием require
, затем используется пакет Parcel. Все это работает, и тесты проходят.
Теперь я хотел бы добавить покрытие, используя karma-coverage
. Я использую конфигурацию ниже, но, как видно из журнала внизу, охват составляет 0% для каждого файла, несмотря на прохождение тестов.
Я просмотрел множество руководств и отчетов об ошибках, но ни одного такого используйте комбинацию karma-coverage
и karma-parcel
. Интересно, есть ли где-нибудь проблема с инструментами и объединением кода. Кажется, что karma-parcel
не поддерживает обслуживание исходных карт . Вызовет ли это проблему?
Я также пробовал инструментировать код, используя babel-plugin-istanbul
вместо препроцессора karma-coverage
, но это тоже не сработало.
Является ли комбинация karma-coverage
и посылка возможна?
Конфигурация:
module.exports = (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: ["mocha", "parcel"],
// list of files / patterns to load in the browser
files: [
{
pattern: "fhrs_osm/static/src/*.js",
watched: false,
included: false,
},
{
pattern: "fhrs_osm/static/src/tests/*.test.js",
// parcel will do the watching for these files
watched: false,
included: false,
},
],
// list of files / patterns to exclude
exclude: [
"fhrs_osm/static/src/index.js",
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"fhrs_osm/static/src/*.js": ["coverage"],
"fhrs_osm/static/src/tests/*.test.js": ["parcel"],
},
// test results reporter to use
// possible values: "dots", "progress"
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ["progress", "coverage"],
coverageReporter: {
type: "text",
// dir: "coverage_js",
includeAllSources: true,
},
// 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_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: ["ChromeHeadless"],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
// singleRun: false,
singleRun: true,
Журнал с включенной отладкой:
npx karma start
02 08 2020 20:34:21.546:DEBUG [config]: Loading config /Users/grs/Desktop/fhrs-osm-2/karma.conf.js
02 08 2020 20:34:21.556:DEBUG [config]: autoWatch set to false, because of singleRun
02 08 2020 20:34:21.557:DEBUG [karma-server]: Final config Config {
LOG_DISABLE: 'OFF',
LOG_ERROR: 'ERROR',
LOG_WARN: 'WARN',
LOG_INFO: 'INFO',
LOG_DEBUG: 'DEBUG',
frameworks: [ 'mocha', 'parcel' ],
protocol: 'http:',
port: 9876,
listenAddress: '0.0.0.0',
hostname: 'localhost',
httpsServerConfig: {},
basePath: '/Users/grs/Desktop/fhrs-osm-2',
files: [
Pattern {
pattern: '/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/*.js',
served: true,
included: false,
watched: false,
nocache: false,
weight: [ 1, 0, 1, 0, 0, 0 ],
type: undefined,
isBinary: undefined
},
Pattern {
pattern: '/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/tests/*.test.js',
served: true,
included: false,
watched: false,
nocache: false,
weight: [ 1, 0, 1, 0, 0, 0 ],
type: undefined,
isBinary: undefined
}
],
browserConsoleLogOptions: { level: 'debug', format: '%b %T: %m', terminal: true },
customContextFile: null,
customDebugFile: null,
customClientContextFile: null,
exclude: [
'/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/index.js',
'/Users/grs/Desktop/fhrs-osm-2/karma.conf.js'
],
logLevel: 'DEBUG',
colors: true,
autoWatch: false,
autoWatchBatchDelay: 250,
restartOnFileChange: false,
usePolling: false,
reporters: [ 'progress', 'coverage' ],
singleRun: true,
browsers: [ 'ChromeHeadless' ],
captureTimeout: 60000,
pingTimeout: 5000,
proxies: {},
proxyValidateSSL: true,
preprocessors: [Object: null prototype] {
'/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/*.js': [ 'coverage' ],
'/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/tests/*.test.js': [ 'parcel' ]
},
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-*' ],
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',
configFile: '/Users/grs/Desktop/fhrs-osm-2/karma.conf.js',
coverageReporter: { type: 'text', includeAllSources: true }
}
02 08 2020 20:34:21.558:DEBUG [plugin]: Loading karma-* from /Users/grs/Desktop/fhrs-osm-2/node_modules
02 08 2020 20:34:21.560:DEBUG [plugin]: Loading plugin /Users/grs/Desktop/fhrs-osm-2/node_modules/karma-chrome-launcher.
02 08 2020 20:34:21.567:DEBUG [plugin]: Loading plugin /Users/grs/Desktop/fhrs-osm-2/node_modules/karma-coverage.
02 08 2020 20:34:22.024:DEBUG [plugin]: Loading plugin /Users/grs/Desktop/fhrs-osm-2/node_modules/karma-mocha.
02 08 2020 20:34:22.028:DEBUG [plugin]: Loading plugin /Users/grs/Desktop/fhrs-osm-2/node_modules/karma-parcel.
02 08 2020 20:34:23.867:DEBUG [preprocessor.coverage]: coverage included in reporters [ 'progress', 'coverage' ]
02 08 2020 20:34:23.878:DEBUG [parcel]: Created workspace: /Users/grs/Desktop/fhrs-osm-2/.karma-parcel
02 08 2020 20:34:23.878:DEBUG [framework:parcel]: Adding /Users/grs/Desktop/fhrs-osm-2/.karma-parcel/index.js to the fileList
02 08 2020 20:34:23.878:DEBUG [framework:parcel]: Adding middleware:parcel
02 08 2020 20:34:23.879:DEBUG [web-server]: Instantiating middleware
02 08 2020 20:34:23.897:DEBUG [reporter]: Trying to load reporter: coverage
02 08 2020 20:34:23.898:DEBUG [reporter]: Trying to load color-version of reporter: coverage (coverage_color)
02 08 2020 20:34:23.898:DEBUG [reporter]: Couldn't load color-version.
02 08 2020 20:34:23.941:DEBUG [filelist]: Excluded file "/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/index.js"
02 08 2020 20:34:23.948:DEBUG [preprocessor.coverage]: Processing "/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/data_source.js".
02 08 2020 20:34:24.036:DEBUG [preprocessor.coverage]: Adding source map to instrumented file for "/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/data_source.js".
02 08 2020 20:34:24.037:DEBUG [preprocessor.coverage]: Processing "/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/data_sources.js".
02 08 2020 20:34:24.065:DEBUG [preprocessor.coverage]: Adding source map to instrumented file for "/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/data_sources.js".
02 08 2020 20:34:24.066:DEBUG [preprocessor.coverage]: Processing "/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/marker_styling.js".
02 08 2020 20:34:24.132:DEBUG [preprocessor.coverage]: Adding source map to instrumented file for "/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/marker_styling.js".
02 08 2020 20:34:24.132:DEBUG [preprocessor.coverage]: Processing "/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/slippy_map.js".
02 08 2020 20:34:24.214:DEBUG [preprocessor.coverage]: Adding source map to instrumented file for "/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/slippy_map.js".
02 08 2020 20:34:24.215:DEBUG [preprocessor.coverage]: Processing "/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/inspector.js".
02 08 2020 20:34:24.294:DEBUG [preprocessor.coverage]: Adding source map to instrumented file for "/Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/inspector.js".
02 08 2020 20:34:24.295:DEBUG [parcel]: Adding /Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/tests/marker_styling.test.js to /Users/grs/Desktop/fhrs-osm-2/.karma-parcel/entry.js
02 08 2020 20:34:24.296:DEBUG [parcel]: Adding /Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/tests/simple_mocha.test.js to /Users/grs/Desktop/fhrs-osm-2/.karma-parcel/entry.js
02 08 2020 20:34:24.298:DEBUG [parcel]: Adding /Users/grs/Desktop/fhrs-osm-2/fhrs_osm/static/src/tests/slippy_map.test.js to /Users/grs/Desktop/fhrs-osm-2/.karma-parcel/entry.js
02 08 2020 20:34:24.311:INFO [karma-server]: Karma v5.1.1 server started at http://localhost:9876/
02 08 2020 20:34:24.312:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
02 08 2020 20:34:24.321:INFO [launcher]: Starting browser ChromeHeadless
02 08 2020 20:34:24.322:DEBUG [launcher]: null -> BEING_CAPTURED
02 08 2020 20:34:24.324:DEBUG [temp-dir]: Creating temp dir at /var/folders/f7/75_xxcbx4l1f2nwkk2grfvtw0000gn/T/karma-36818045
02 08 2020 20:34:24.325:DEBUG [launcher]: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/var/folders/f7/75_xxcbx4l1f2nwkk2grfvtw0000gn/T/karma-36818045 --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=36818045 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222
02 08 2020 20:34:25.284:DEBUG [web-server]: serving: /Users/grs/Desktop/fhrs-osm-2/node_modules/karma/static/client.html
02 08 2020 20:34:25.563:DEBUG [web-server]: serving: /Users/grs/Desktop/fhrs-osm-2/node_modules/karma/static/karma.js
02 08 2020 20:34:25.806:DEBUG [karma-server]: A browser has connected on socket UpB-Dup7iM8X2Nb-AAAA
02 08 2020 20:34:25.830:DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=UpB-Dup7iM8X2Nb-AAAA
02 08 2020 20:34:25.866:DEBUG [Chrome Headless 84.0.4147.105 (Mac OS 10.14.6)]: undefined -> CONNECTED
02 08 2020 20:34:25.866:INFO [Chrome Headless 84.0.4147.105 (Mac OS 10.14.6)]: Connected on socket UpB-Dup7iM8X2Nb-AAAA with id 36818045
02 08 2020 20:34:25.867:DEBUG [launcher]: BEING_CAPTURED -> CAPTURED
02 08 2020 20:34:25.867:DEBUG [launcher]: ChromeHeadless (id 36818045) captured in 1.555 secs
02 08 2020 20:34:25.868:DEBUG [Chrome Headless 84.0.4147.105 (Mac OS 10.14.6)]: CONNECTED -> CONFIGURING
02 08 2020 20:34:25.890:DEBUG [middleware:karma]: custom files null null null
02 08 2020 20:34:25.891:DEBUG [middleware:karma]: Serving static request /context.html
02 08 2020 20:34:25.895:DEBUG [web-server]: serving: /Users/grs/Desktop/fhrs-osm-2/node_modules/karma/static/context.html
02 08 2020 20:34:25.911:DEBUG [middleware:source-files]: Requesting /base/node_modules/mocha/mocha.js?bce34c80a59125d4bef907f68298c5edcb5bd9fc
02 08 2020 20:34:25.911:DEBUG [middleware:source-files]: Fetching /Users/grs/Desktop/fhrs-osm-2/node_modules/mocha/mocha.js
02 08 2020 20:34:25.912:DEBUG [web-server]: serving (cached): /Users/grs/Desktop/fhrs-osm-2/node_modules/mocha/mocha.js
02 08 2020 20:34:25.917:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-mocha/lib/adapter.js?a0f4bbc139407501892ac58d70c2791e7adec343
02 08 2020 20:34:25.917:DEBUG [middleware:source-files]: Fetching /Users/grs/Desktop/fhrs-osm-2/node_modules/karma-mocha/lib/adapter.js
02 08 2020 20:34:25.919:DEBUG [web-server]: serving (cached): /Users/grs/Desktop/fhrs-osm-2/node_modules/karma-mocha/lib/adapter.js
02 08 2020 20:34:25.923:DEBUG [middleware:source-files]: Requesting /base/.karma-parcel/index.js?da39a3ee5e6b4b0d3255bfef95601890afd80709
02 08 2020 20:34:25.923:DEBUG [middleware:source-files]: Fetching /Users/grs/Desktop/fhrs-osm-2/.karma-parcel/index.js
02 08 2020 20:34:25.923:DEBUG [parcel]: Serving /base/.karma-parcel/index.js?da39a3ee5e6b4b0d3255bfef95601890afd80709 as /karma-parcel/index.js?da39a3ee5e6b4b0d3255bfef95601890afd80709
02 08 2020 20:34:25.924:DEBUG [parcel]: Creating bundler for EntryFile(/Users/grs/Desktop/fhrs-osm-2/.karma-parcel/entry.js, imports: 3)
02 08 2020 20:34:25.942:DEBUG [web-server]: serving: /Users/grs/Desktop/fhrs-osm-2/node_modules/karma/static/context.js
02 08 2020 20:34:30.147:DEBUG [Chrome Headless 84.0.4147.105 (Mac OS 10.14.6)]: CONFIGURING -> EXECUTING
Chrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 0 of 25 SUCCESS (0 secsChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 1 of 25 SUCCESS (0 secsChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 2 of 25 SUCCESS (0 secsChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 3 of 25 SUCCESS (0 secsChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 4 of 25 SUCCESS (0 secsChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 5 of 25 SUCCESS (0 secsChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 6 of 25 SUCCESS (0 secsChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 7 of 25 SUCCESS (0 secsChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 8 of 25 SUCCESS (0 secsChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 9 of 25 SUCCESS (0 secsChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 10 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 11 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 12 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 13 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 14 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 15 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 16 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 17 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 18 of 25 SUCCESS (0 secs / 0.018 secs)
02 08 2020 20:34:30.323:DEBUG [parcel]: Wrote bundled test: /Users/grs/Desktop/fhrs-osm-2/.karma-parcel/index.js
02 08 2020 20:34:30.361:INFO [filelist]: Changed file "/Users/grs/Desktop/fhrs-oChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 19 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 20 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 21 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 22 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 23 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 24 of 25 SUCCESS (0 secChrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 25 of 25 SUCCESS (0 secs / 0.025 secs)
02 08 2020 20:34:30.373:DEBUG [Chrome Headless 84.0.4147.105 (Mac OS 10.14.6)]: Chrome Headless 84.0.4147.105 (Mac OS 10.14.6): Executed 25 of 25 SUCCESS (0.227 secs / 0.025 secs)
02 08 2020 20:34:30.374:DEBUG [launcher]: CAPTURED -> BEING_KILLED
02 08 2020 20:34:30.375:DEBUG [launcher]: BEING_KILLED -> BEING_FORCE_KILLED
TOTAL: 25 SUCCESS
02 08 2020 20:34:30.379:DEBUG [karma-server]: Run complete, exiting.
02 08 2020 20:34:30.383:DEBUG [launcher]: Disconnecting all browsers
02 08 2020 20:34:30.383:DEBUG [launcher]: BEING_FORCE_KILLED -> BEING_FORCE_KILLED
02 08 2020 20:34:30.383:DEBUG [proxy]: Destroying proxy agents
-------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
data_source.js | 0 | 0 | 0 | 0 | 1-51
data_sources.js | 0 | 0 | 0 | 0 | 3-22
inspector.js | 0 | 0 | 0 | 0 | 1-117
marker_styling.js | 0 | 0 | 0 | 0 | 1-64
slippy_map.js | 0 | 0 | 0 | 0 | 1-62
-------------------|---------|----------|---------|---------|-------------------
02 08 2020 20:34:30.434:DEBUG [launcher]: Process ChromeHeadless exited with code null and signal SIGTERM
02 08 2020 20:34:30.434:DEBUG [temp-dir]: Cleaning temp dir /var/folders/f7/75_xxcbx4l1f2nwkk2grfvtw0000gn/T/karma-36818045
02 08 2020 20:34:30.470:DEBUG [launcher]: Finished all browsers
02 08 2020 20:34:30.470:DEBUG [launcher]: BEING_FORCE_KILLED -> FINISHED
02 08 2020 20:34:30.470:DEBUG [launcher]: FINISHED -> FINISHED