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: Cannot read property 'forEach' of undefined #433

Closed
2 of 5 tasks
ghsouza89 opened this issue Mar 8, 2023 · 8 comments
Closed
2 of 5 tasks

TypeError: Cannot read property 'forEach' of undefined #433

ghsouza89 opened this issue Mar 8, 2023 · 8 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@ghsouza89
Copy link

Thank you for reporting a bug! We appreciate it very much. Issues are a big input into the priorities for Pact development

All italic text in this template is safe to remove before submitting

Thanks again!

Software versions

Please provide at least OS and version of pact-js

  • OS: _e.g. Windows 11 Home Single Language
  • Pact Node version: 13.13.4
  • Node Version: v14.18.0
  • Other Versions: Any other versions you think might be relevant (optional)

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
  • 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

Provider Verification passed sucessfully

Actual behaviour

TypeError: Cannot read property 'forEach' of undefined

Steps to reproduce

Run the provider file

`import { Verifier } from '@pact-foundation/pact';
import path from 'path';

describe('Pact Verification', () => {
jest.setTimeout(50000);
it('validates the expectations of dynamicApi Service', () => {
const opts = {
log: path.resolve(process.cwd(), 'logs', 'pact.log'),
LogLevel: 'debug',
providerBaseUrl: 'providerBaseUrl',
pactBrokerUrl: 'pactBrokerUrl',
pactBrokerToken: 'pactBrokerToken',
pactUrls: [
'pactUrls',
],
publishVerificationResult: true,
providerVersion: '2.0.0',
provider: 'provider',
tags: ['release'],
};
return new Verifier(opts).verifyProvider().then((output) => {
console.log('Pact Verification Complete!');
console.log(output);
});
});
});
`

Here is the output

`FAIL contract-testing apps/contract-testing/provider/dynamicApi.spec.ts
Pact Verification
× validates the expectations of dynamicApi Service (15 ms)

● Pact Verification › validates the expectations of dynamicApi Service

TypeError: Cannot read property 'forEach' of undefined

  at ../../node_modules/@pact-foundation/pact-core/src/verifier/validateOptions.ts:266:15
      at Array.forEach (<anonymous>)
  at ../../node_modules/@pact-foundation/pact-core/src/verifier/validateOptions.ts:265:18
      at Array.forEach (<anonymous>)
  at validateOptions (../../node_modules/@pact-foundation/pact-core/src/verifier/validateOptions.ts:260:5)
  at new Verifier (../../node_modules/@pact-foundation/pact-core/src/verifier/index.ts:16:35)
  at Object.<anonymous>.exports.default (../../node_modules/@pact-foundation/pact-core/src/verifier/index.ts:30:56)
  at Pact.verifyPacts (../../node_modules/@pact-foundation/pact-core/src/pact.ts:158:27)
  at ../../node_modules/@pact-foundation/src/dsl/verifier/verifier.ts:137:29

Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 2.036 s, estimated 3 s
Ran all test suites matching /apps\contract-testing\provider\/i.`

image

For extra bonus points and internet karma, provide a repository, gist or reproducible code snippet so that we can test the problem.

We recommend forking the project and modifying a relevant example in the examples folder

Relevant log files

Please ensure you set logging to DEBUG and attach any relevant log files here (or link to a gist).

@ghsouza89 ghsouza89 added the bug Indicates an unexpected problem or unintended behavior label Mar 8, 2023
@ghsouza89
Copy link
Author

PR related: #432

@mefellows
Copy link
Member

Can you please re-test with the latest @ghsouza89? This should be fixed now. Thanks again for raising it.

@ghsouza89
Copy link
Author

@mefellows here is the result after update the @pact-foundation/pact-core to 13.13.5

Before run I did the follow steps:

  1. rm -rf node_modules
  2. rm -f package-lock.json
  3. npm cache clean --force
  4. npm install

image

@TimothyJones
Copy link
Contributor

@pact-foundation/pact-core is a dependency. You need to update @pact-foundation/pact

@TimothyJones
Copy link
Contributor

You can do npm ls @pact-foundation/pact-core to see what you have

@ghsouza89
Copy link
Author

npm ls @pact-foundation/pact-core

here is the output:

$ npm ls @pact-foundation/pact-core themarkerr@1.4.0 C:\markerr-app +-- @pact-foundation/pact@11.0.0 | -- @pact-foundation/pact-core@13.13.4
-- @pact-foundation/pact-core@13.13.5

image

@TimothyJones
Copy link
Contributor

This illustrates the problem. You need to bump the version of @pact-foundation/pact to the latest (and remove the other pact-core dependency, you don't need to depend on it directly). The latest is 11.0.2, although I believe this was fixed in 11.0.1.

Apologies for not being clear about this the first time.

@ghsouza89
Copy link
Author

This illustrates the problem. You need to bump the version of @pact-foundation/pact to the latest (and remove the other pact-core dependency, you don't need to depend on it directly). The latest is 11.0.2, although I believe this was fixed in 11.0.1.

Apologies for not being clear about this the first time.

worked @TimothyJones , thanks a lot for your support, let doc all those steps!

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
Projects
None yet
Development

No branches or pull requests

3 participants