UNPKG

2.45 kBMarkdownView Raw
1# plugin-karma
2
3Use Karma to run unit tests for your Poi project.
4
5## Install
6
7```bash
8yarn add poi @poi/plugin-karma --dev
9```
10
11Notes: You have to install `poi` locally in your project.
12
13## Usage
14
15```js
16// poi.config.js
17module.exports = {
18 plugins: [
19 require('@poi/plugin-karma')({
20 port: 5001, // default
21 files: ['test/unit/*.test.js'] // default
22 })
23 ]
24}
25```
26
27Then run `poi test`, this plugin will only be activated in test mode.
28
29Or run `poi test --watch` to run Karma in watch mode.
30
31Or run `poi test --coverage` to get code coverage as well.
32
33### Use with Assertion Library
34
35By default this plugin does not add any assertion library, to use one like [chai.js](http://www.chaijs.com/) you can simply install it and use it in your test files, here's an [example](./example/App.test.js).
36
37## Options
38
39### port
40
41Type: `number`<br>
42Default: `5001`
43
44### files
45
46Type: `Array` `string`<br>
47Default: `['test/unit/**/*.test.js']`
48
49### frameworks
50
51Type: `Array` `string`<br>
52Default: `['mocha']`
53
54### reporters
55
56Type: `Array` `string`<br>
57Default: `['mocha']`
58
59If you enable code coverage the `coverage` reporter will automatically be added as well.
60
61### browsers
62
63Type: `Array` `string`<br>
64Default: `['Chrome']`
65
66You can use `headless` option to switch it to `ChromeHeadless` which is only available when you have Chrome>=59 installed.
67
68You can also directly set `browsers` option to override it.
69
70### headless
71
72Type: `boolean`<br>
73Default: `false`
74
75Switch `browsers` to `ChromeHeadless`.
76
77### watch
78
79Type: `boolean`<br>
80Default: `false`
81
82Run karma in watch mode.
83
84### coverage
85
86Type: `boolean`<br>
87Default: `false`
88
89Generate code coverage.
90
91### karma
92
93Type: `object` `karmaConfig => newkarmaConfig`
94
95### chainWebpack
96
97Type: `function`<br>
98Default: `undefined`
99
100Extending webpack config using webpack-chain:
101
102```js
103require('poi-plugin-karma')({
104 chainWebpack(config) {
105 config.some.action()
106 }
107})
108```
109
110### TypeScript support
111
112It works with [poi-plugin-typescript](https://github.com/egoist/poi/tree/master/packages/poi-plugin-typescript).
113
114You need to install `karma-typescript` and `typescript` locally in your project first, and configure `poi-plugin-typescript`:
115
116```js
117// poi.config.js
118module.exports = {
119 plugins: [
120 // The order matters!
121 require('poi-plugin-typescript')(),
122 require('poi-plugin-karma')()
123 ]
124}
125```
126
127## License
128
129[MIT](https://oss.ninja/mit/egoist) &copy; [EGOIST](https://github.com/egoist)