1 | # @aofl/unit-testing-plugin
|
2 |
|
3 | Aofl unit testing plugin uses [WebdriverIO](https://webdriver.io/) to run unit tests in the browser.
|
4 |
|
5 | *Note: for automated browser testing refer to @aofl/wdio*
|
6 |
|
7 |
|
8 | ## Installation
|
9 | ```bash
|
10 | npm i -D @aofl/unit-testing-plugin
|
11 | ```
|
12 |
|
13 | If you plan on generating coverage report `babel-plugin-istanbul` is needed to instrument transpiled code. We recommend using [babel-plugin-istanbul](https://www.npmjs.com/package/babel-plugin-istanbul)
|
14 |
|
15 | ## Usage
|
16 | ```javascript
|
17 | const UnitTesting = require('@aofl/unit-testing-plugin');
|
18 |
|
19 | module.export = {
|
20 | entry: {
|
21 | 'custom-elements-es5-adapter': 'path/to/custom-e...',
|
22 | 'init-polyfill-service': 'path/to/...'
|
23 | }.
|
24 | plugins: [
|
25 | new UnitTesting({
|
26 | root: process.cwd(), // project root
|
27 | output: '__build_tests', // output directory of compiled test files.
|
28 | host: 'localhost',
|
29 | port: 3035,
|
30 | config: path.join(root, '.wct.config.js'),
|
31 | debug: false,
|
32 | nycArgs: [ // cli arguments passed to nyc to generate coverage report
|
33 | 'report',
|
34 | '--reporter=lcov',
|
35 | '--reporter=text-summary',
|
36 | '--report-dir=./logs/coverage'
|
37 | ]
|
38 | })
|
39 | ]
|
40 | }
|
41 | ```
|
42 |
|
43 |
|
44 | ## WebdriverIO Configuration
|
45 | For ease of use @aofl/unit-testing comes preconfigured with common WebdriverIO recipes. You can provide your own file based on https://webdriver.io/docs/configurationfile.html. However, in most cases you should only need to configure the capabilities field.
|
46 |
|
47 |
|
48 | ### Local
|
49 |
|
50 | ```js
|
51 | // .wct.config.js
|
52 | module.exports.config = {
|
53 | capabilities: [
|
54 | {
|
55 | "maxInstances": 5,
|
56 | "browserName": 'chrome',
|
57 | 'goog:chromeOptions': {
|
58 | // to run chrome headless the following flags are required
|
59 | // (see https://developers.google.com/web/updates/2017/04/headless-chrome)
|
60 | args: ['--headless', '--disable-gpu'],
|
61 | }
|
62 | },
|
63 | {
|
64 | "maxInstances": 5,
|
65 | "browserName": 'firefox',
|
66 | 'moz:firefoxOptions': {
|
67 | // flag to activate Firefox headless mode (see https://github.com/mozilla/geckodriver/blob/master/README.md#firefox-capabilities for more details about moz:firefoxOptions)
|
68 | args: ['-headless']
|
69 | },
|
70 | },
|
71 | // {
|
72 | // "maxInstances": 10,
|
73 | // "browserName": 'safari'
|
74 | // }
|
75 | ]
|
76 | };
|
77 | ```
|
78 |
|
79 | ### SauceLabs
|
80 | Set `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY` as environment variables.
|
81 |
|
82 | ```js
|
83 | // .wct-sauce.config.js
|
84 | const sharedSettings = {
|
85 | recordLogs: true,
|
86 | recordVideo: true,
|
87 | recordScreenshots: false,
|
88 | timeout: 300,
|
89 | idleTimeout: 1000,
|
90 | commandTimeout: 600,
|
91 | webdriverRemoteQuietExceptions: false,
|
92 | videoUploadOnPass: false,
|
93 | tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER || null // if using travis refer to https://docs.travis-ci.com/user/sauce-connect/
|
94 | };
|
95 |
|
96 | const config = {
|
97 | preset: 'sauce',
|
98 | specFileRetries: 1,
|
99 | sauceConnect: true,
|
100 | capabilities: [
|
101 | {
|
102 | ...sharedSettings,
|
103 | "browserName": "Safari",
|
104 | "appiumVersion": "1.15.0",
|
105 | "deviceName": "iPhone X Simulator",
|
106 | "platformVersion": "13.0",
|
107 | "platformName": "iOS"
|
108 | },
|
109 | ...
|
110 | ]
|
111 | };
|
112 | ``` |
\ | No newline at end of file |