首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使pact测试运行与Karma和角

无法使pact测试运行与Karma和角
EN

Stack Overflow用户
提问于 2022-06-15 13:27:53
回答 1查看 112关注 0票数 0

我无法让pact测试运行与卡玛与我的角度应用程序设置。这是package.json的相关部分。

代码语言:javascript
复制
"@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

代码语言:javascript
复制
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,用于添加填充:

代码语言:javascript
复制
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");

    module.exports = {
        plugins: [
            new NodePolyfillPlugin()
        ],
        externals: {
            "fs": require('fs'),
            "child_process": require('child_process'),
            "net": require('net')
        }
    };

我收到了这个错误:

代码语言:javascript
复制
Uncaught TypeError: Cannot read properties of undefined (reading 'readFile')

如果我像这样配置它:

代码语言:javascript
复制
module.exports = {
    resolve: {
        fallback: {
            "fs": false,
        }
    },
    plugins: [
        new NodePolyfillPlugin()
    ],
    externals: {
        "child_process": require('child_process'),
        "net": require('net')
    }
};

我知道这个错误:

代码语言:javascript
复制
 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的错误。

知道怎么解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2022-06-16 04:42:14

我们可能需要一个存储库来重现这个问题。话虽如此,Webpack似乎正在尝试打包@pact-foundation/pact包,这是行不通的(我可以看到提到了tar和win32,它们都只在服务器端使用)--这可能是一条线索。

我还想说的是,业力支持(事实上,pact网络)不太可能得到支持,我建议你在业力之外(例如Jest,Mocha等)测试这一点。使用标准的@pact-foundation/pact包。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72632340

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档