Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: ffi.pactffiMessageGivenWithParams is not a function #1200

Closed
4 of 5 tasks
Kampfmoehre opened this issue Mar 22, 2024 · 2 comments
Closed
4 of 5 tasks

TypeError: ffi.pactffiMessageGivenWithParams is not a function #1200

Kampfmoehre opened this issue Mar 22, 2024 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior triage This issue is yet to be triaged by a maintainer

Comments

@Kampfmoehre
Copy link

Software versions

  • OS: Debian (CI), Fedora
  • Consumer Pact library: PactJS 12.3.0
  • Provider Pact library: PactJS 12.3.0
  • Node Version: v21.7.1

Issue Checklist

Please confirm the following:

  • I have upgraded to the latest
  • I have the read the FAQs in the Readme
  • I have triple checked, that there are no unhandled promises in my code and have read the section on intermittent test failures
  • I have set my log level to debug and attached a log file showing the complete request/response cycle
  • For bonus points and virtual high fives, I have created a reproduceable git repository (see below) to illustrate the problem

Expected behaviour

Tests run like before.

Actual behaviour

Tests fail with an error message:

TypeError: ffi.pactffiMessageGivenWithParams is not a function

      150 |
      151 |       await converterPact
    > 152 |         .given({ name: "A file to convert", params: { mediaType: "image" } })
          |          ^
      153 |         .expectsToReceive("A valid convert image request")
      154 |         .withMetadata({
      155 |           // "content-type": "application/json",

      at Object.givenWithParams (node_modules/@pact-foundation/pact-core/src/consumer/index.ts:46:9)
      at MessageConsumerPact.Object.<anonymous>.MessageConsumerPact.given (node_modules/@pact-foundation/src/messageConsumerPact.ts:77:20)
      at Object.<anonymous> (test/some.test.ts:152:10)

Steps to reproduce

We are having trouble running our tests in CI since the update of @pact-foundation/pact to version 12.1.2. Consumer message pact tests fail with the below error. Reverting to 12.1.2 lets the test run successfully again.

Tests run with Jest look like this:

it("something works", async () => {
  const messageRequest = {
    someId: Matchers.string("Nkiwmu-oFoRN3lqzYD7M"),
    originalFileChecksum: {
      algo: "SHA256",
      hash: Matchers.hexadecimal("b3eb64161ac2a85bf364fc3b0e19e063bc9375475237feddee2ae36089c59cb3"),
    },
    someOtherId: Matchers.string("T-PlRCvy2N3JnjAiANGC"),
    fileName: Matchers.string("some-file.bmp"),
    profile: Matchers.string("thumb"),
    targetFormat: Matchers.string("jpg"),
  };

  let result: MessageResponse | undefined = undefined;
  let message: Message | undefined;
  const ackMock = jest.fn();
  const nackMock = jest.fn();

  await converterPact
    .given({ name: "A file to convert", params: { mediaType: "image" } })
    .expectsToReceive("A valid convert image request")
    .withMetadata({
      type: "convert:image",
    })
    .withContent(converterRequest)
    .verify(async (m: PactMessage) => {
      message = new Message(m.contents, m.metadata);
      message.ack = ackMock;
      message.nack = nackMock;

      const channel = amqpService.getChannelFromPool("Exchange/Queue/convert");
      result = await (channel.consumer as Pipeline<Message, MessageResponse>).execute(message);

      return result;
    });

  expect(message).not.toBeUndefined();
  expect(nackMock).not.toHaveBeenCalled();
  expect(ackMock).toHaveBeenCalled();
  expect(result).not.toBeUndefined();
});

Relevant log files

No special logs are emitted from Pact, however running the same test with Pact version 12.1.2 (where the test works) emits the following logs:

[08:39:20.192] INFO (24436): 0.4.16: pact native library successfully found, and the correct version
2024-03-22T07:39:20.198657Z  WARN ThreadId(01) pact_ffi::mock_server::handles: Failed to parse metadata value 'convert:image' as JSON - expected value at line 1 column 1. Will treat it as string
2024-03-22T07:39:20.198776Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $
2024-03-22T07:39:20.198787Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Configuring a normal object
2024-03-22T07:39:20.198909Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $.convertedFileId
2024-03-22T07:39:20.198913Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: detected pact:matcher:type, will configure a matcher
2024-03-22T07:39:20.198932Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $.originalFileChecksum
2024-03-22T07:39:20.198934Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Configuring a normal object
2024-03-22T07:39:20.198938Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $.originalFileChecksum.hash
2024-03-22T07:39:20.198941Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: detected pact:matcher:type, will configure a matcher
2024-03-22T07:39:20.198947Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $.originalFileId
2024-03-22T07:39:20.198949Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: detected pact:matcher:type, will configure a matcher
2024-03-22T07:39:20.198953Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $.originalFileName
2024-03-22T07:39:20.198955Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: detected pact:matcher:type, will configure a matcher
2024-03-22T07:39:20.198959Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $.profile
2024-03-22T07:39:20.198961Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: detected pact:matcher:type, will configure a matcher
2024-03-22T07:39:20.198965Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $.targetFormat
2024-03-22T07:39:20.198967Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: detected pact:matcher:type, will configure a matcher
[08:39:20.199] INFO (24436): pact@12.1.2: Verifying message
[08:39:20.199] DEBUG (24436): pact@12.1.2: reified message raw: raw
[08:39:20.199] DEBUG (24436): pact@12.1.2: rehydrated message body into correct type: [object Object]
2024-03-22T07:39:20.201618Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: pact_ffi::mock_server::handles::pactffi_pact_handle_write_file FFI function invoked
2024-03-22T07:39:20.201664Z DEBUG ThreadId(01) pact_models::pact: Merging pact with file "/home/user/project/pacts/somePact.json"
2024-03-22T07:39:20.201750Z  WARN ThreadId(01) pact_models::pact: Note: Existing pact is an older specification version (V3), and will be upgraded
@Kampfmoehre Kampfmoehre added bug Indicates an unexpected problem or unintended behavior triage This issue is yet to be triaged by a maintainer labels Mar 22, 2024
@mefellows
Copy link
Member

Thanks for spotting, this is indeed a bug. It looks like pactffiMessageGivenWithParams was not exported by the C interface in @pact-foundation/pact-core.

I'll push out a release shortly that pins the versions so that an upgrade will automatically pull in the correct version.

@mefellows
Copy link
Member

Fixed in 12.3.1 via 34d8a4b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior triage This issue is yet to be triaged by a maintainer
Projects
None yet
Development

No branches or pull requests

2 participants