karma-chrome-launcher
karma-chrome-launcher是什么
什么是karma-chrome-launcher,A Karma plugin. Launcher for Chrome and Chrome Canary.
karma-chrome-launcher使用教程帮助文档
karma-chrome-launcher
Launcher for Google Chrome, Google Chrome Canary and Google Chromium.
Installation
The easiest way is to keep karma-chrome-launcher
as a devDependency in your package.json
, by running
$ npm i -D karma-chrome-launcher
Configuration
// karma.conf.js
module.exports = function(config) {
config.set({
browsers: ['Chrome', 'Chrome_without_security'], // You may use 'ChromeCanary', 'Chromium' or any other supported browser
// you can define custom flags
customLaunchers: {
Chrome_without_security: {
base: 'Chrome',
flags: ['--disable-web-security']
}
}
})
}
The --user-data-dir
is set to a temporary directory but can be overridden on a custom launcher as shown below. One reason to do this is to have a permanent Chrome user data directory inside the project directory to be able to install plugins there (e.g. JetBrains IDE Support plugin).
customLaunchers: {
Chrome_with_debugging: {
base: 'Chrome',
chromeDataDir: path.resolve(__dirname, '.chrome')
}
}
You can pass list of browsers as a CLI argument too:
$ karma start --browsers Chrome,Chrome_without_security
Headless Chromium with Puppeteer
The Chrome DevTools team created Puppeteer - it will automatically install Chromium for all platforms and contains everything you need to run it from within your CI.
Available Browsers
Note: Headless mode requires a browser version >= 59
- Chrome (CHROME_BIN)
- ChromeHeadless (CHROME_BIN)
- Chromium (CHROMIUM_BIN)
- ChromiumHeadless (CHROMIUM_BIN)
- ChromeCanary (CHROME_CANARY_BIN)
- ChromeCanaryHeadless (CHROME_CANARY_BIN)
- Dartium (DARTIUM_BIN)
Usage
$ npm i -D puppeteer karma-chrome-launcher
// karma.conf.js
process.env.CHROME_BIN = require('puppeteer').executablePath()
module.exports = function(config) {
config.set({
browsers: ['ChromeHeadless']
})
}
For more information on Karma see the homepage.
本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。
转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]