{"id":15490527,"url":"https://github.com/blaugold/webpack-mocha-plugin","last_synced_at":"2025-04-22T19:10:43.728Z","repository":{"id":65379316,"uuid":"73524655","full_name":"blaugold/webpack-mocha-plugin","owner":"blaugold","description":"Webpack plugin integration with mocha testing framework + coverage with istanbul.","archived":false,"fork":false,"pushed_at":"2018-03-19T21:37:34.000Z","size":50,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-19T09:18:32.801Z","etag":null,"topics":["coverage","istanbul","mocha","webpack-plugin"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blaugold.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-12T01:39:30.000Z","updated_at":"2017-05-14T11:39:10.000Z","dependencies_parsed_at":"2023-01-20T08:45:46.664Z","dependency_job_id":null,"html_url":"https://github.com/blaugold/webpack-mocha-plugin","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blaugold%2Fwebpack-mocha-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blaugold%2Fwebpack-mocha-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blaugold%2Fwebpack-mocha-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blaugold%2Fwebpack-mocha-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blaugold","download_url":"https://codeload.github.com/blaugold/webpack-mocha-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250306638,"owners_count":21408926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coverage","istanbul","mocha","webpack-plugin"],"created_at":"2024-10-02T07:21:54.731Z","updated_at":"2025-04-22T19:10:43.707Z","avatar_url":"https://github.com/blaugold.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## webpack-mocha-plugin\nWebpack plugin integration with mocha testing framework + coverage with istanbul.\n\n[![CircleCI](https://circleci.com/gh/blaugold/webpack-mocha-plugin/tree/master.svg?style=svg\u0026circle-token=6120e3250facc9807944a407480a3705b171216e)](https://circleci.com/gh/blaugold/webpack-mocha-plugin/tree/master)\n\n## Installation\n```bash\n    npm i -D webpack-mocha-plugin mocha istanbul remap-istanbul\n```\n\n### Webpack Config\nThis webpack configuration will run your tests and write a html and json coverage report to\n`coverage`, after webpack compiles the project. If webpack is in watch mode tests are run after\neach compilation.\nYou can configure entry and output how ever you like. The plugin will add all generated files\nending in `.js` to the mocha test.\n```javascript\n    const WebpackMochaPlugin = require('webpack-mocha-plugin');\n    const nodeExternals = require('webpack-node-externals');\n    \n    module.exports = {\n        target: 'node',\n    \n        entry: {\n            test: __dirname + '/test.bundle.ts'\n        },\n    \n        output: {\n            path: '.tmp/test',\n            filename: '[name].bundle.js'\n        },\n    \n        resolve: {\n            extensions: ['.ts', '.js']\n        },\n    \n        externals: [nodeExternals()],\n    \n        devtool: 'inline-source-map',\n    \n        module: {\n            rules: [\n                {\n                    enforce: 'pre',\n                    test: /\\.js$/,\n                    loader: 'source-map'\n                },\n                {\n                    test: /\\.ts$/,\n                    loader: 'awesome-typescript'\n                },\n                {\n                    enforce: 'post',\n                    test: /\\.(js|ts)$/,\n                    // Exlude tests so they don't show up in coverage report.\n                    exclude: /\\.(spec)\\.(ts|js)$/,\n                    loader: 'sourcemap-istanbul-instrumenter',\n                    query: {\n                        'force-sourcemap': true\n                    }\n                }\n            ]\n        },\n    \n        plugins: [\n            new WebpackMochaPlugin({\n                codeCoverage: true\n            })\n        ],\n        // When using code coverage exclude the coverage report from being watched.\n        // Otherwise you might get an infinite loop.\n        watchOptions: {\n            ignored: /coverage/\n        }\n    };\n```\n\n## Options\n```javascript\n    new WebpackMochaPlugin({\n        mocha?: any = {};\n        codeCoverage?: boolean = false;\n        coverageVariable?: string = '__coverage__';\n        coverageReports?: string[] = ['html', 'json'];\n        coverageDir?: string = 'coverage';\n    })\n```\n\nYou can pass all options which the Mocha JS API takes in `mocha`.\n`codeCoverage` enables or disables generation of a report.\n`coverageVariable` is where the instrumenter puts the coverage information.\n`coverageReports` takes all reporters which `istanbul` can generate.\n`coverageDir` is the directory where the coverage report will be stored.\n\n## Test Bundle\n```javascript\n    // This will only inlcude spec files and files required by them in the coverage report.\n    // Tell webpack to bundle all spec files in a context.\n    const ctx = require.context('src', true, /\\.(spec)\\.js/)\n    \n    // Evaluate all modules in context.\n    ctx.keys().map(moduleId =\u003e ctx(moduleId))\n    \n    // This will include all files in the src directory so untest code shows up in the coverage\n    // report.\n    // Tell webpack to bundle all source files in a context.\n    const ctx = require.context('src', true, /\\.js/)\n    \n    // Evaluate all modules in context.\n    ctx.keys().map(moduleId =\u003e ctx(moduleId))\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblaugold%2Fwebpack-mocha-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblaugold%2Fwebpack-mocha-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblaugold%2Fwebpack-mocha-plugin/lists"}