我的单元测试使用'ng test'在我的外壳中工作,但不适用于Travis: No captured browser in Travis
我正在使用karma,karma.conf.js:
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
files: [
{ pattern: 'src/app/*.ts', served: true, watched: true, included: false},
{ pattern: 'src/app/**/**/*.spec.ts', served: true, watched: true, included: false}
],
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
//browsers: ['Chrome'],
browsers: ['ChromeNoSandbox'],
customLaunchers: {
ChromeNoSandbox: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
singleRun: false,
browserNoActivityTimeout: 25000
});
};
然后,这是我的.travil.yml:
language: node_js
sudo: required
node_js:
- node
# addons:
# chrome: stable
# firefox: latest
apt:
sources:
- google-chrome
packages:
- python
- golang
- google-chrome-stable
- google-chrome-beta
before_install:
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
- sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
- sudo apt-get update
- sudo apt-get install google-chrome-stable
- export CHROME_BIN=usr/bin/google-chrome
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
before_script:
- "sudo chown root /opt/google/chrome/chrome-sandbox"
- "sudo chmod 4755 /opt/google/chrome/chrome-sandbox"
# No need these two lines if you use latest version of node
# - npm install
# - npm update
- yarn
# - export CHROME_BIN=usr/bin/google-chrome
# - export DISPLAY=:99.0
# - sh -e /etc/init.d/xvfb start
# - sudo apt-get update
# - sudo apt-get install -y libappindicator1 fonts-liberation
# - wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
# - sudo dpkg -i google-chrome*.deb
# install:
# - npm install -g @angular/cli
script:
# - npm test
- yarn e2e
- yarn lint
- yarn test
我看到了很多解决方案,但对我没有用。
我不知道是否存在链接,但因果报应启动在我的项目中也无法正常工作,出现以下错误:'@ angular-devkit / build-angular / plugins / karma'因果报应旨在可以在Angular CLI中使用,并且无法在Angular CLI中正常工作
答案 0 :(得分:0)
我解决了这个问题。 我只是通过export CHROME_BIN = chromium-browser更改了.travils.yml中的export CHROME_BIN = usr / bin / google-chrome,并为ng测试添加了--watch = false选项。