我想在Angular中创建consumer Pact测试。
我已经在package.json中添加了pact依赖:
"@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有人知道如何修复这个错误吗?或者可能知道如何找出缺失的路径?
发布于 2019-02-12 22:49:37
我找到了这个错误的原因--我们的企业防火墙阻止了二进制文件的下载。我已经手动下载了二进制文件,现在pact可以正常工作了。
发布于 2019-09-11 18:50:56
我也有这个问题(使用Mac ),在hosts文件中添加我的主机名作为别名解决了这个问题。
您可以通过在terminal.It中运行类似mymacbook.local的hostname来找到您的主机名。
然后在/etc/hosts文件中添加/编辑这些条目,使其如下所示:
127.0.0.1 localhost mymacbook.local
::1 localhost mymacbook.local发布于 2021-09-16 09:45:49
我也遇到了同样的问题。如Ilja的回答所述,必须下载该二进制文件。此外,还必须在package.json中配置"pact_binary_location“。这在https://www.npmjs.com/package/@pact-foundation/pact-node上有很好的描述
https://stackoverflow.com/questions/54576818
复制相似问题