Skip to content

Commit 2be075f

Browse files
authored
Merge branch 'master' into add_datadir
2 parents 391e401 + 277f019 commit 2be075f

File tree

11 files changed

+220
-49
lines changed

11 files changed

+220
-49
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ node_modules
22
*.log
33
package-lock.json
44
dist
5-
build
5+
build
6+
coverage
7+
.vscode

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Most importantly, Karmatic provides a (headless) browser test harness in a singl
1515
## Installation
1616

1717
```sh
18-
npm i -D karmatic
18+
npm i -D webpack karmatic
1919
```
2020

2121
... then add a `test` script to your `package.json`:
@@ -28,7 +28,7 @@ npm i -D karmatic
2828
}
2929
```
3030

31-
... now you can run your tests using `npm t`.
31+
... now you can run your tests using `npm t`. Here's a [minimal example repo](https://gist.github.com/developit/acd8a075350eeb6574439e92888c50cf).
3232

3333

3434
### Test File Patterns
@@ -51,6 +51,34 @@ Example:
5151
karmatic --chromeDataDir .chrome
5252
```
5353

54+
## Usage
55+
56+
```text
57+
Usage
58+
$ karmatic <command> [options]
59+
60+
Available Commands
61+
run Run tests once and exit
62+
watch Run tests on any change
63+
debug Open a headful Puppeteer instance for debugging your tests
64+
65+
For more info, run any command with the `--help` flag
66+
$ karmatic run --help
67+
$ karmatic watch --help
68+
69+
Options
70+
-v, --version Displays current version
71+
--files Minimatch pattern for test files
72+
--headless Run using Chrome Headless (default true)
73+
--coverage Report code coverage of tests (default true)
74+
-h, --help Displays this message
75+
```
76+
77+
To disable any option that defaults to `true`, pass `false` to the option: `--headless false` or `--coverage false`.
78+
79+
NOTE: The `debug` option overrides the default value of the `--headless` and `--coverage` option to be `false`. This option will also open up the local Puppeteer installation of Chrome, not your globally installed one. If you'd like to debug your tests using your your own instance of Chrome (or any other browser), copy the URL from the puppeteer window into your favorite browser.
80+
81+
5482
## FAQ
5583

5684
**Q**: [Is there an FAQ?](https://twitter.com/gauntface/status/956259291928776704)**

package.json

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "karmatic",
3-
"version": "1.0.5",
3+
"version": "1.2.0",
44
"description": "Zero-config automatic (headless) browser testing. Powered by Karma, Webpack & Jasmine.",
55
"main": "dist/index.js",
66
"module": "dist/index.m.js",
77
"bin": "dist/cli.js",
88
"scripts": {
99
"prepare": "npm t",
10-
"build": "microbundle --target node --external all -f cjs --no-compress src/*.js",
10+
"build": "microbundle --target node -f cjs --no-compress src/*.js",
1111
"test:build": "node ./dist/cli.js run",
12+
"test:watch": "node ./dist/cli.js watch --headless false",
1213
"test": "eslint src test && npm run -s build && npm run -s test:build",
1314
"release": "npm run -s prepare && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
1415
},
@@ -20,34 +21,45 @@
2021
"chrome",
2122
"test runner"
2223
],
24+
"files": [
25+
"dist"
26+
],
2327
"author": "Jason Miller <[email protected]> (http://jasonformat.com)",
28+
"repository": "developit/karmatic",
2429
"license": "MIT",
2530
"devDependencies": {
2631
"eslint": "^4.16.0",
2732
"eslint-config-developit": "^1.1.1",
28-
"microbundle": "^0.4.2",
29-
"workerize-loader": "^1.0.1"
33+
"microbundle": "^0.11.0",
34+
"webpack": "^4.14.0",
35+
"workerize-loader": "^1.0.4"
3036
},
3137
"dependencies": {
32-
"babel-core": "^6.26.0",
33-
"babel-loader": "^7.1.2",
34-
"babel-plugin-transform-object-rest-spread": "^6.26.0",
35-
"babel-plugin-transform-react-jsx": "^6.24.1",
36-
"babel-polyfill": "^6.26.0",
37-
"babel-preset-env": "^1.6.1",
38-
"babel-preset-stage-0": "^6.24.1",
38+
"@babel/core": "^7.4.3",
39+
"@babel/plugin-proposal-object-rest-spread": "^7.4.3",
40+
"@babel/plugin-transform-react-jsx": "^7.3.0",
41+
"@babel/polyfill": "^7.4.3",
42+
"@babel/preset-env": "^7.4.3",
43+
"@babel/preset-stage-0": "^7.0.0",
44+
"babel-loader": "^8.0.5",
45+
"babel-plugin-istanbul": "^5.1.0",
3946
"chalk": "^2.3.0",
4047
"dlv": "^1.1.1",
41-
"jasmine-core": "^2.9.1",
42-
"karma": "^2.0.0",
48+
"jasmine-core": "^3.3.0",
49+
"karma": "^3.1.1",
4350
"karma-chrome-launcher": "^2.2.0",
44-
"karma-jasmine": "^1.1.1",
51+
"karma-coverage": "^1.1.2",
52+
"karma-firefox-launcher": "^1.1.0",
53+
"karma-jasmine": "^2.0.1",
54+
"karma-sauce-launcher": "^2.0.2",
4555
"karma-sourcemap-loader": "^0.3.7",
4656
"karma-spec-reporter": "0.0.32",
4757
"karma-webpack": "2.0.7",
4858
"puppeteer": "^1.0.0",
4959
"sade": "^1.3.1",
50-
"script-loader": "^0.7.2",
51-
"webpack": "^3.10.0"
60+
"script-loader": "^0.7.2"
61+
},
62+
"peerDependencies": {
63+
"webpack": ">=4"
5264
}
5365
}

src/cli.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ import './lib/patch';
66
import karmatic from '.';
77
import { cleanStack } from './lib/util';
88

9+
// @ts-ignore
910
const { version } = require('../package.json');
1011

11-
let toArray = val => Array.isArray(val) ? val : val == null ? [] : [val];
12+
let toArray = val => typeof val === 'string' ? val.split(/\s*,\s*/) : val == null ? [] : [].concat(val);
1213

1314
let prog = sade('karmatic');
1415

1516
prog
1617
.version(version)
1718
.option('--files', 'Minimatch pattern for test files')
1819
.option('--headless', 'Run using Chrome Headless', true)
20+
.option('--coverage', 'Report code coverage of tests', true)
21+
.option('--downlevel', 'Downlevel syntax to ES5')
1922
.option('--chromeDataDir', 'Save Chrome preferences');
2023

2124
prog
@@ -28,11 +31,21 @@ prog
2831
.describe('Run tests on any change')
2932
.action( (str, opts) => run(str, opts, true) );
3033

34+
prog
35+
.command('debug [...files]')
36+
.describe('Open a headful Puppeteer instance for debugging your tests')
37+
.option('--headless', 'Run using Chrome Headless', false) // Override default to false
38+
.option('--browsers', 'Run in specific browsers', null)
39+
.option('--coverage', 'Report code coverage of tests', false) // Override default to false
40+
.action( (str, opts) => run(str, opts, true) );
41+
3142
prog.parse(process.argv);
3243

3344
function run(str, opts, isWatch) {
3445
opts.watch = !!isWatch;
3546
opts.files = toArray(str || opts.files).concat(opts._);
47+
const b = opts.browsers || opts.browser;
48+
opts.browsers = b ? toArray(b) : null;
3649
karmatic(opts)
3750
.then( output => {
3851
if (output!=null) process.stdout.write(output + '\n');

0 commit comments

Comments
 (0)