我想在Angular中创建消费者Pact测试。
我已将pact依赖项放入package.json:
"@pact-foundation/karma-pact": "2.1.9",
"@pact-foundation/pact-node": "6.21.3",
"@pact-foundation/pact-web": "7.2.0",
然后我更新了karma.conf.js:
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular', 'pact'],
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'),
require('@pact-foundation/karma-pact')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'prod'
},
// load pact web module
files: [
'../node_modules/@pact-foundation/pact-web/pact-web.js'
],
pact: [{
cors: true,
port: 1235,
consumer: "ui",
provider: "testservice",
dir: "pacts",
spec: 2
}],
proxies: {
'/test-service/': 'http://127.0.0.1:1235/test-service/'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: true,
browsers: ['ChromeHeadless'],
singleRun: true
});
};
现在,当我开始ng测试时,Karma尝试启动Pact服务器并引发错误:
07 02 2019 16:14:23.694:DEBUG [plugin]: Loading inlined plugin (defining framework:pact).
10% building modules 2/2 modules 0 active[2019-02-07T15:14:23.890Z] INFO: pact-node@6.21.3/16304 on VAA6DAB0246:
Creating Pact Server with options:
cors = true,
port = 1235,
consumer = ui,
provider = testservice,
dir = D:\Users\aster\WebstormProjects\test\pacts,
spec = 2,
pactFileWriteMode = overwrite,
ssl = false,
host = localhost
[2019-02-07T15:14:23.905Z] INFO: pact-node@6.21.3/16304 on VAA6DAB0246: Created 'standalone\win32-1.63.0\bin\pact-mock-service.bat service --cors 'true' --port '1235' --consumer 'ui' --provider 'testservice' --pact_dir 'D:\Users\aster\WebstormProjects\test\pacts' --pact_specification_version '2' --pact-file-write-mode 'overwrite' --host 'localhost'' process with PID: 35496
[2019-02-07T15:14:31.221Z] ERROR: pact-node@6.21.3/16304 on VAA6DAB0246:
Pact Binary Error: Das System kann den angegebenen Pfad nicht finden.
[2019-02-07T15:14:31.482Z] WARN: pact-node@6.21.3/16304 on VAA6DAB0246: Pact exited with code 1.
[2019-02-07T15:14:31.482Z] INFO: pact-node@6.21.3/16304 on VAA6DAB0246: Removing Pact with PID: 35496
FEHLER: Der Prozess "35496" wurde nicht gefunden. 07 02 2019 16:14:53.913:ERROR [pact]: Error while trying to run karma-pact: Error: Couldn't start Pact with PID: 35496
有人知道如何解决此错误吗?也许有想法如何找出缺失的路径?
答案 0 :(得分:0)
我已找到此错误的原因-我们的企业防火墙阻止了二进制文件的下载。我已经手动下载了二进制文件,现在协议可以正常运行了。
答案 1 :(得分:0)
我也遇到了这个问题(使用Mac OS),并且在主机文件中添加了主机名作为别名即可解决此问题。
您可以通过在终端中运行hostname
来查找主机名。它类似于mymacbook.local
。
然后在/etc/hosts
文件中添加/编辑这些条目,使它们看起来像这样:
127.0.0.1 localhost mymacbook.local
::1 localhost mymacbook.local