我尝试在Docker容器上的proyect中运行单元测试,测试在我的本地计算机上运行良好,但是当在docker countainer上运行时,我不知道会发生什么。
当我运行命令npm test
时,这是控制台中的错误:
/app # npm test
> home-tarjetas@0.0.0 test /app
> ng test --code-coverage --no-watch
10% building modules 1/1 modules 0 active05 09 2018 20:05:30.036:INFO
[karma]: Karma v2.0.5 server started at http://0.0.0.0:9876/
05 09 2018 20:05:30.038:INFO [launcher]: Launching browser
ChromeHeadlessNoSandbox with unlimited concurrency
05 09 2018 20:05:32.466:INFO [launcher]: Starting browser ChromeHeadless
Unhandled rejection Error: EPERM: operation not permitted, scandir
'/proc/1/map_files/563394025000-5633940e6000'
at Object.fs.readdirSync (fs.js:861:3)
at GlobSync._readdir (/app/node_modules/glob/sync.js:288:41)
at GlobSync._readdirInGlobStar (/app/node_modules/glob/sync.js:245:17)
at GlobSync._readdir (/app/node_modules/glob/sync.js:276:17)
at GlobSync._processReaddir (/app/node_modules/glob/sync.js:137:22)
at GlobSync._process (/app/node_modules/glob/sync.js:132:10)
at GlobSync._processGlobStar (/app/node_modules/glob/sync.js:380:10)
at GlobSync._process (/app/node_modules/glob/sync.js:130:10)
at GlobSync._processGlobStar (/app/node_modules/glob/sync.js:383:10)
at GlobSync._process (/app/node_modules/glob/sync.js:130:10)
at GlobSync._processGlobStar (/app/node_modules/glob/sync.js:383:10)
at GlobSync._process (/app/node_modules/glob/sync.js:130:10)
at GlobSync._processGlobStar (/app/node_modules/glob/sync.js:383:10)
at GlobSync._process (/app/node_modules/glob/sync.js:130:10)
at new GlobSync (/app/node_modules/glob/sync.js:48:10)
at new Glob (/app/node_modules/glob/glob.js:129:12)
05 09 2018 20:06:32.472:WARN [launcher]: ChromeHeadless have not captured in
60000 ms, killing.
05 09 2018 20:06:34.477:WARN [launcher]: ChromeHeadless was not killed in
2000 ms, sending SIGKILL.
05 09 2018 20:06:36.481:WARN [launcher]: ChromeHeadless was not killed by
SIGKILL in 2000 ms, continuing.
npm ERR! Test failed. See above for more details.
这是我的 DockerFile :
FROM 172.17.200.7:5000/alpine-node-base:v1.0.0
LABEL name="home-m"
LABEL author="fgt"
RUN mkdir /app
WORKDIR /app
COPY . .
RUN rm -rf node_modules
CMD ["top"]
package.json
{
"name": "home-m",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"test": "ng test --code-coverage --no-watch",
"lint": "ng lint",
"e2e": "ng e2e",
"build:packagr": "ng-packagr -p package.json",
"publish": "npm publish ./dist-module"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.2.0",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"core-js": "^2.4.1",
"ngx-swiper-wrapper": "^6.4.0",
"rxjs": "^5.5.12",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "~1.7.4",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^5.2.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^6.0.117",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"ng-packagr": "^4.1.1",
"protractor": "~5.1.2",
"puppeteer": "^1.7.0",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
}
karma.conf.js
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function (config) {
config.set({
basePath: '..',
files:[
'**/*.spec.ts'
],
exclude: [
],
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers:{
ChromeHeadlessNoSandbox:{
base:'ChromeHeadless',
flags:['--no-sandbox','--disable-gpu']
}
},
singleRun: false
});
};