Skip to content

Commit

Permalink
Merge branch 'master' into add_datadir
Browse files Browse the repository at this point in the history
  • Loading branch information
developit authored Jun 19, 2020
2 parents e9867df + 31e886c commit da02ba5
Show file tree
Hide file tree
Showing 15 changed files with 373 additions and 245 deletions.
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage
dist
node_modules
package-lock.json
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"arrowParens": "always",
"trailingComma": "es5",
"singleQuote": true,
"endOfLine": "lf",
"useTabs": true
}
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

A simplified zero-configuration wrapper around [Karma], [Webpack], [Jasmine] & [Puppeteer].

Think of it like Jest for cross-browser testing (it uses the same [expect syntax](https://jestjs.io/docs/en/using-matchers)).

## Why do I want this?

Expand All @@ -11,7 +12,6 @@ Karmatic is a zero-configuration wrapper around these tools with intelligent def

Most importantly, Karmatic provides a (headless) browser test harness in a single dependency.


## Installation

```sh
Expand All @@ -30,7 +30,6 @@ npm i -D webpack karmatic

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


### Test File Patterns

By default, Karmatic will find tests in any files ending in `.test.js` or `_test.js`.
Expand Down Expand Up @@ -78,27 +77,23 @@ To disable any option that defaults to `true`, pass `false` to the option: `--he

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.


## FAQ

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

> Yes.

## Projects Using Karmatic

Karmatic is pretty new! Here are some projects that have switched to it you may use as a reference:

- [workerize-loader](https://github.com/developit/workerize-loader/commit/afaa20bbfbdec1d6a5523ec69ba2a2d5d495cfd6)


## License

[MIT](https://oss.ninja/mit/developit) © [developit](https://github.com/developit)


[Karma]: https://karma-runner.github.io
[Webpack]: https://webpack.js.org
[Jasmine]: https://jasmine.github.io
[Puppeteer]: https://github.com/GoogleChrome/puppeteer
[karma]: https://karma-runner.github.io
[webpack]: https://webpack.js.org
[jasmine]: https://jasmine.github.io
[puppeteer]: https://github.com/GoogleChrome/puppeteer
137 changes: 72 additions & 65 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,67 +1,74 @@
{
"name": "karmatic",
"version": "1.4.0",
"description": "Zero-config automatic (headless) browser testing. Powered by Karma, Webpack & Jasmine.",
"main": "dist/index.js",
"module": "dist/index.m.js",
"bin": "dist/cli.js",
"scripts": {
"prepare": "npm t",
"build": "microbundle --target node -f cjs --no-compress src/*.js",
"test:build": "node ./dist/cli.js run",
"test:watch": "node ./dist/cli.js watch --headless false",
"test": "eslint src test && npm run -s build && npm run -s test:build",
"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"
},
"eslintConfig": {
"extends": "eslint-config-developit"
},
"keywords": [
"karma",
"chrome",
"test runner"
],
"files": [
"dist"
],
"author": "Jason Miller <jason@developit.ca> (http://jasonformat.com)",
"repository": "developit/karmatic",
"license": "MIT",
"devDependencies": {
"eslint": "^4.16.0",
"eslint-config-developit": "^1.1.1",
"microbundle": "^0.11.0",
"webpack": "^4.39.3",
"workerize-loader": "^1.1.0"
},
"dependencies": {
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.5.5",
"@babel/preset-stage-0": "^7.0.0",
"babel-loader": "^8.0.6",
"babel-plugin-istanbul": "^5.2.0",
"chalk": "^2.3.0",
"dlv": "^1.1.3",
"istanbul-instrumenter-loader": "^3.0.1",
"jasmine-core": "^3.3.0",
"karma": "^4.3.0",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.0.1",
"karma-firefox-launcher": "^1.2.0",
"karma-jasmine": "^2.0.1",
"karma-sauce-launcher": "^2.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "^4.0.2",
"minimatch": "^3.0.4",
"puppeteer": "^1.19.0",
"sade": "^1.6.1",
"script-loader": "^0.7.2"
},
"peerDependencies": {
"webpack": ">=4"
}
"name": "karmatic",
"version": "1.4.0",
"description": "Zero-config automatic (headless) browser testing. Powered by Karma, Webpack & Jasmine.",
"main": "dist/index.js",
"module": "dist/index.m.js",
"bin": "dist/cli.js",
"scripts": {
"prepare": "npm t",
"build": "microbundle --target node -f cjs --no-compress src/*.js",
"test:build": "node ./dist/cli.js run",
"test:watch": "node ./dist/cli.js watch --headless false",
"prettier": "prettier --write './**/*.{js,json,yml,md}'",
"test": "prettier --check './**/*.{js,json,yml,md}' && eslint src test && npm run -s build && npm run -s test:build",
"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"
},
"eslintConfig": {
"extends": [
"eslint-config-developit",
"prettier"
]
},
"keywords": [
"karma",
"chrome",
"test runner"
],
"files": [
"dist"
],
"author": "Jason Miller <jason@developit.ca> (http://jasonformat.com)",
"repository": "developit/karmatic",
"license": "MIT",
"devDependencies": {
"eslint": "^4.16.0",
"eslint-config-developit": "^1.1.1",
"eslint-config-prettier": "^6.10.0",
"microbundle": "^0.11.0",
"prettier": "^1.19.1",
"webpack": "^4.39.3",
"workerize-loader": "^1.1.0"
},
"dependencies": {
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.5.5",
"@babel/preset-stage-0": "^7.0.0",
"babel-loader": "^8.0.6",
"babel-plugin-istanbul": "^5.2.0",
"chalk": "^2.3.0",
"dlv": "^1.1.3",
"expect": "^24.9.0",
"istanbul-instrumenter-loader": "^3.0.1",
"jasmine-core": "^3.3.0",
"karma": "^4.3.0",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.0.1",
"karma-firefox-launcher": "^1.2.0",
"karma-jasmine": "^2.0.1",
"karma-sauce-launcher": "^2.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "^4.0.2",
"minimatch": "^3.0.4",
"puppeteer": "^1.19.0",
"sade": "^1.6.1",
"script-loader": "^0.7.2"
},
"peerDependencies": {
"webpack": ">=4"
}
}
8 changes: 5 additions & 3 deletions src/appender.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { cleanStack } from './lib/util';

export function configure(config, layouts) {
let layout = layouts.colouredLayout;
return logEvent => {
process.stdout.write(chalk.red(cleanStack(layout(logEvent, config.timezoneOffset)))+'\n');
return (logEvent) => {
process.stdout.write(
chalk.red(cleanStack(layout(logEvent, config.timezoneOffset))) + '\n'
);
};
}
}
24 changes: 16 additions & 8 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import { cleanStack } from './lib/util';
// @ts-ignore
const { version } = require('../package.json');

let toArray = val => typeof val === 'string' ? val.split(/\s*,\s*/) : val == null ? [] : [].concat(val);
let toArray = (val) =>
typeof val === 'string'
? val.split(/\s*,\s*/)
: val == null
? []
: [].concat(val);

let prog = sade('karmatic');

Expand All @@ -29,15 +34,15 @@ prog
prog
.command('watch [...files]')
.describe('Run tests on any change')
.action( (str, opts) => run(str, opts, true) );
.action((str, opts) => run(str, opts, true));

prog
.command('debug [...files]')
.describe('Open a headful Puppeteer instance for debugging your tests')
.option('--headless', 'Run using Chrome Headless', false) // Override default to false
.option('--browsers', 'Run in specific browsers', null)
.option('--coverage', 'Report code coverage of tests', false) // Override default to false
.action( (str, opts) => run(str, opts, true) );
.action((str, opts) => run(str, opts, true));

prog.parse(process.argv);

Expand All @@ -47,13 +52,16 @@ function run(str, opts, isWatch) {
const b = opts.browsers || opts.browser;
opts.browsers = b ? toArray(b) : null;
karmatic(opts)
.then( output => {
if (output!=null) process.stdout.write(output + '\n');
.then((output) => {
if (output != null) process.stdout.write(output + '\n');
if (!opts.watch) process.exit(0);
})
.catch(err => {
if (!(typeof err.code==='number' && err.code>=0 && err.code<10)) {
process.stderr.write(chalk.red(cleanStack(err && (err.stack || err.message) || err)) + '\n');
.catch((err) => {
if (!(typeof err.code === 'number' && err.code >= 0 && err.code < 10)) {
process.stderr.write(
chalk.red(cleanStack((err && (err.stack || err.message)) || err)) +
'\n'
);
}
process.exit(err.code || 1);
});
Expand Down
Loading

0 comments on commit da02ba5

Please sign in to comment.