我无法让pact测试运行与卡玛与我的角度应用程序设置。这是package.json的相关部分。
"@angular/core": "~13.3.6",
"@pact-foundation/karma-pact": "^3.1.0",
"@pact-foundation/pact": "^9.17.3",
"@pact-foundation/pact-node": "^10.17.4"
"jasmine-core": "~3.8",
"karma": "^6.3.19",
"karma-chrome-launcher": "^3.1.1",
"karma-coverage": "~2.0.3",
"karma-jasmine": "^5.0.0",
"karma-jasmine-html-reporter": "~1.7.0"karma.config.json
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'),
require('@angular-devkit/build-angular/plugins/karma'),
require('@pact-foundation/karma-pact')
],
files: [
'polyfills.js',
'node_modules/@pact-foundation/pact-web/pact-web.js'
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, './coverage/spa'),
subdir: '.',
reporters: [
{type: 'html'},
{type: 'text-summary'}
]
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true,
pact: [
{
cors: true,
spec: 3,
port: 1234,
consumer: 'consumer',
provider: 'provider',
logLevel: 'DEBUG',
dir: 'pacts'
}
],
});
};我使用了@angular-builders/custom-webpack,这是额外的webpackconfig,用于添加填充:
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
module.exports = {
plugins: [
new NodePolyfillPlugin()
],
externals: {
"fs": require('fs'),
"child_process": require('child_process'),
"net": require('net')
}
};我收到了这个错误:
Uncaught TypeError: Cannot read properties of undefined (reading 'readFile')如果我像这样配置它:
module.exports = {
resolve: {
fallback: {
"fs": false,
}
},
plugins: [
new NodePolyfillPlugin()
],
externals: {
"child_process": require('child_process'),
"net": require('net')
}
};我知道这个错误:
An error was thrown in afterAll
Uncaught TypeError: Cannot destructure property 'isAbsolute' of '__webpack_require__(...).win32' as it is null.
TypeError: Cannot destructure property 'isAbsolute' of '__webpack_require__(...).win32' as it is null.
at Object.79857 (http://localhost:9876/_karma_webpack_/webpack:/node_modules/tar/lib/strip--path.js:3:9)在webpack配置中将目标设置为节点没有帮助,只是得到没有定义module的错误。
知道怎么解决这个问题吗?
发布于 2022-06-16 04:42:14
我们可能需要一个存储库来重现这个问题。话虽如此,Webpack似乎正在尝试打包@pact-foundation/pact包,这是行不通的(我可以看到提到了tar和win32,它们都只在服务器端使用)--这可能是一条线索。
我还想说的是,业力支持(事实上,pact网络)不太可能得到支持,我建议你在业力之外(例如Jest,Mocha等)测试这一点。使用标准的@pact-foundation/pact包。
https://stackoverflow.com/questions/72632340
复制相似问题