pact-foundation / pact-js-core

Core binaries for pact-js, a Contract Testing Framework. NOTE: If you are looking to do Pact contract testing in node, you almost certainly want pact-js, not pact-node.
https://docs.pact.io
MIT License
150 stars 79 forks source link

pact-node@10.14.0: Pact Binary Error when trying to run a test #345

Closed erickbelfy closed 3 years ago

erickbelfy commented 3 years ago

I had an issue while trying to setup Pact provider when i try to run my tests here it follows

Software versions

Please provide at least OS and version of pact-js

Please confirm the following:

Expected behaviour

It should create a server that runs the Pact provider and test all the cases

Actual behaviour

it gives me the error below:

[2021-11-04 15:02:50.945 +0000] INFO (97114 on MAC-CA-BELFOER2): pact-node@10.14.0: Creating Pact Server with options:
{"consumer":"customer-signup-gateway-consumer","cors":true,"dir":"/Users/belfoer1/Documents/oss-ui/packages/apps/signup/server/pact/pacts","host":"127.0.0.1","log":"/Users/belfoer1/Documents/oss-ui/packages/apps/signup/server/pact/logs","pactFileWriteMode":"update","port":3000,"provider":"customer-sign-up","spec":2,"ssl":false,"timeout":30000}
[2021-11-04 15:02:51.720 +0000] ERROR (97114 on MAC-CA-BELFOER2): pact-node@10.14.0: Pact Binary Error: /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/ruby/lib/ruby/gems/2.2.0/gems/bundler-1.9.9/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /Users/belfoer1/Library/Android in PATH, mode 040777

[2021-11-04 15:02:52.066 +0000] ERROR (97114 on MAC-CA-BELFOER2): pact-node@10.14.0: Pact Binary Error: /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.9.0/lib/pact/mock_service/run.rb:75:in `initialize': Is a directory @ rb_sysopen - /Users/belfoer1/Documents/oss-ui/packages/apps/signup/server/pact/logs (Errno::EISDIR)
    from /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.9.0/lib/pact/mock_service/run.rb:75:in `open'
    from /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.9.0/lib/pact/mock_service/run.rb:75:in `open_log_file'
    from /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.9.0/lib/pact/mock_service/run.rb:69:in `service_options'
    from /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.9.0/lib/pact/mock_service/run.rb:37:in `mock_service'
    from /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.9.0/lib/pact/mock_service/run.rb:28:in `call'
    from /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.9.0/lib/pact/mock_service/run.rb:13:in `call'
    from /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.9.0/lib/pact/mock_service/cli.rb:32:in `service'
    from /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
    from /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
    from /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor/base.rb:485:in `start'
    from /Users/belfoer1/Documents/oss-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/lib/app/pact-mock-service.rb:15:in `<main>'

[2021-11-04 15:02:52.080 +0000] WARN (97114 on MAC-CA-BELFOER2): pact-node@10.14.0: Pact exited with code 1.
[2021-11-04 15:02:52.080 +0000] INFO (97114 on MAC-CA-BELFOER2): pact-node@10.14.0: Removing Pact process with PID: 97235

Steps to reproduce

given code:

// eslint-disable-next-line import/no-extraneous-dependencies
import { Pact } from '@pact-foundation/pact';
import path from 'path';
import config from '../src/config';

const { PACT_CONSUMER, PACT_PROVIDER, PORT } = config();

global.provider = new Pact({
  cors: true,
  consumer: PACT_CONSUMER,
  provider: PACT_PROVIDER,
  pactfileWriteMode: 'update',
  port: parseInt(PORT, 10),
  log: path.resolve(process.cwd(), 'pact/logs'),
  dir: path.resolve(process.cwd(), 'pact/pacts'),
  logLevel: 'info',
  spec: 2,
});
/* eslint jest/expect-expect: "off" */
import request from 'supertest';
import { Matchers } from '@pact-foundation/pact';
import express from 'express';
import signupRoutes from './signup-routes';

const app = express();

app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(signupRoutes);

const newAccountMock = {
  accountUuid: 'mock-hash',
  realm: 'mock',
  userUuid: 'mock-hash',
};

const account = {
  emailAddress: 'jhonPACT@company.com',
  password: 'myPWD@',
  firstName: 'jhon',
  lastName: 'PACT',
  customerName: 'company',
};

describe('pacts', () => {
  afterEach(() => global.provider.verify());
  describe('adding new customer', () => {
    it('should add a new customer', async () => {
      console.log('IT', global.provider.mockService);
      await global.provider.addInteraction({
        state: 'Add a new customer',
        uponReceiving: 'A request for API ',
        withRequest: {
          method: 'POST',
          path: '/signup',
          body: account,
        },
        willRespondWith: {
          status: 201,
          body: Matchers.eachLike(newAccountMock),
        },
      });
      await request(app)
        .post('/signup')
        .send(account)
        .set('Accept', 'application/json')
        .expect('Content-Type', /json/)
        .expect(201);
      console.log('am i here?????');
    });
  });
});
mefellows commented 3 years ago

Duplicate of: https://github.com/pact-foundation/pact-js/issues/766