最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Pact gRPC consumer test in node.js - Stack Overflow

programmeradmin0浏览0评论

I am evaluating Pact and i fail to get a running grpc consumer test in node.js. I installed the protobuf plugin with the Pact CLI tool.

My mocha test looks like this:

'use strict';
const { PactV4, SpecificationVersion } = require('@pact-foundation/pact');
const path = require('node:path');

describe.only('PactTest', function () {
    let provider;

    before(async function () {
        provider = new PactV4({
            dir: path.resolve(process.cwd(), 'pacts'),
            consumer: 'some.consumer',
            provider: 'some.provider',
            port: '50073',
            spec: SpecificationVersion.SPECIFICATION_VERSION_V4
        });
    });

    it('shall create contract file', async function () {
        await provider
            .addSynchronousInteraction('Call scheduler service')
            .usingPlugin({
                plugin: 'protobuf',
                version: '0.5.4'
            })
            .withPluginContents(
                JSON.stringify({
                    'pact:proto': '/Users/path/to/some/proto/scheduler.proto',
                    'pact:proto-service': 'ElsaSchedulerService/GetTaskExecutionById',
                    'pact:message-type': 'GetTaskExecutionByIdResponse',
                    'pact:content-type': 'application/protobuf',
                    success: true,
                    taskFullName: 'egon'
                }),
                'application/grpc'
            )
            .startTransport('grpc', '127.0.0.1')
            .executeTest(async mockServer => {
                //mockServer.port === 55312

                // do some stuff which triggers the grpc call
            });
    });
});

It even starts a mockServer but it has a random port (55312) and i need the mock server to listen to port 50073. Why does Pact ignore the port i specified in line 13?

Thanks in advance, Thomas

发布评论

评论列表(0)

  1. 暂无评论