1.14.0 • Published 5 years ago

@wildpeaks/karma-config-web v1.14.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Karma Config: Web

Github Release

Generates a Karma configuration for testing using Puppeteer.


Quickstart

The files option specifies the test files to run:

// karma.conf.js:
const getKarmaConfig = require('@wildpeaks/karma-config-web');

module.exports = function(config) {
	const karmaConfig = getKarmaConfig({
		files: 'src/**/*.spec.js'
	});
	config.set(karmaConfig);
};

You can also use several patterns:

// karma.conf.js:
const getKarmaConfig = require('@wildpeaks/karma-config-web');

module.exports = function(config) {
	const karmaConfig = getKarmaConfig({
		files: [
			'test/*.test.js',
			'src/**/*.spec.js'
		]
	});
	config.set(karmaConfig);
};

Use a Webpack 4 configuration to handle more filetypes:

// karma.conf.js:
const getKarmaConfig = require('@wildpeaks/karma-config-web');

module.exports = function(config) {
	const karmaConfig = getKarmaConfig({
		files: 'src/**/*.spec.js',
		webpack: {
			module: {
				rules: [
					//...
				]
			}
			// ...
		}
	});
	config.set(karmaConfig);
};

The Webpack Config Generator makes it easy to support Typescript, CSS, and images:

// karma.conf.js
const getKarmaConfig = require('@wildpeaks/karma-config-web');
const getWebpackConfig = require('@wildpeaks/webpack-config-web');

module.exports = function(config) {
	const webpackConfig = getWebpackConfig({
		mode: 'development',
		skipPostprocess: true
	});
	const karmaConfig = getKarmaConfig({
		files: 'src/**/*.spec.ts',
		webpack: webpackConfig
	});
	config.set(karmaConfig);
};

Additional browsers

The package only comes with Puppeteer (headless Chrome) because it's cross-platform and headless (so you don't see the browser opening and closing when Karma runs the tests).

However, Karma supports other browsers, such as:

You can also use paid services like BrowserStack and Sauce Labs to run tests in a lot of desktop and mobile browsers.

Add additional launchers in the dependencies of your package.json, example:

{
	"devDependencies": {
		"karma-edge-launcher": "...",
		"karma-firefox-launcher": "...",
		"karma-ie-launcher": "..."
	}
}

Then use property browsers in karma.conf.js:

const getKarmaConfig = require('@wildpeaks/karma-config-web');

module.exports = function(config) {
	const karmaConfig = getKarmaConfig({
		files: 'src/**/*.spec.ts'
	});
	karmaConfig.browsers = ['ChromeHeadless', 'Firefox', 'IE', 'Edge'];
	config.set(karmaConfig);
};

1.14.0

5 years ago

1.13.0

5 years ago

1.12.1

5 years ago

1.12.0

5 years ago

1.11.0

5 years ago

1.10.0

5 years ago

1.9.0

6 years ago

1.8.4

6 years ago

1.8.3

6 years ago

1.8.2

6 years ago

1.8.0

6 years ago

1.7.0

6 years ago

1.6.0

7 years ago

1.5.0

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

1.0.0-alpha3

7 years ago

1.0.0-alpha2

7 years ago

1.0.0-alpha1

7 years ago