Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/valotas/karma-parcel
Karma with Parcel bundler
https://github.com/valotas/karma-parcel
karma parcel
Last synced: 3 months ago
JSON representation
Karma with Parcel bundler
- Host: GitHub
- URL: https://github.com/valotas/karma-parcel
- Owner: valotas
- License: mit
- Created: 2018-10-29T19:56:39.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-27T17:33:45.000Z (almost 2 years ago)
- Last Synced: 2024-04-26T21:47:48.217Z (7 months ago)
- Topics: karma, parcel
- Language: TypeScript
- Size: 1.07 MB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-parcel - karma-parcel - Let parcel bundle your tests that karma should run (Integration with other languages, frameworks / Other)
README
# Karma Parcel
Use [parcel v2][parcel] to preprocess [karma][] tests
**Notice:** `v0.7` or newer of this plugin supports `parcel@2` and `karma@6`. If for whatever
reason you need to make use of `parcel-bundler@1` (or `parcel@1`), please use [`[email protected]`](https://www.npmjs.com/package/karma-parcel/v/0.6.1)## Install
To get all the needed packages:
```bash
npm i karma parcel karma-parcel -D
```## Configure:
Add `parcel` to the frameworks to be used and to the files that should be preprocessed with it:
```js
module.exports = function (config) {
config.set({
frameworks: ["mocha", "parcel"],// add patterns with all your tests even if they should not
// be handled by parcel
files: [
"tests/**/*.js",
{
// parcel tests should not be watched. Parcel will do the
// watching instead
pattern: "parcel/**/*.js",
watched: false,
included: false,
},
],// let karma know which of the test files should be bundled
// with parcel
preprocessors: {
"parcel/*": ["parcel"],
},
});
};
```### `parcelConfig`
some more parcel specific configuration can be passed to the underlying parcel
instance via the `parcelConfig` attribute of your karma configuration:```js
module.exports = function (config) {
config.set({
// lot of karma configuration
parcelConfig: {
cacheDir: "/path/to/cache", // default: "./.cache"
detailedReport: true, // default: false,
logLevel: "verbose",
},
});
};
```### `karmaParcelWorkspace`
make use of this in order to define a workspace other than current directory:
```js
module.exports = function (config) {
config.set({
// ... lot of karma configuration
// use /tmp/foo/bar as the workspace
karmaParcelWorkspace: path.join(os.tmpdir(), "foo", "bar"),
parcelConfig: { /* the parcel config*/ },
});
};
```## Under the hood
Parcel will create one bundle with all the files that are preprocessed with
the `parcel` preprocessor. The preprocessor will emit an empty file instead of
the actual content. The plugin will register a bundle file to karma's
fileList with `serve: false` in order not to be handled by karma's middleware.
To serve the bundled file, parcel's own middleware is registered and used# Related
This plugin is heavily inspired by [`karma-browserify`][karma-browserify] and
[`karma-webpack`][karma-webpack].[parcel]: https://parceljs.org/
[karma]: https://karma-runner.github.io
[karma-browserify]: https://github.com/nikku/karma-browserify
[karma-webpack]: https://github.com/webpack-contrib/karma-webpack