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