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

V3 DSL Feedback #215

Open
Maxim-Filimonov opened this issue Aug 12, 2022 · 6 comments
Open

V3 DSL Feedback #215

Maxim-Filimonov opened this issue Aug 12, 2022 · 6 comments

Comments

@Maxim-Filimonov
Copy link

Maxim-Filimonov commented Aug 12, 2022

Feature description

V3 API.

Use case

I made the same code using jest-pact v3

pactWith(pactConfig, (interaction) => {
  interaction('authentication api', ({ execute, provider }) => {
    const username = mockUsername;
    provider.addInteraction(validUsername({ username }));

    return execute(
      'can check for existence of username',
      async (mockServer) => {
        const response = await validateUsername({
          username,
          api: new Api(mockServer.url),
        });

        expect(response).toBeDefined();
      },
    );
  });
});

and plain pact v3:

describe('authentication', () => {
  it('can check for existence of username', () => {
    const username = mockUsername;
    provider.addInteraction(validUsername({ username }));
    
    return provider.executeTest(async (mockServer) => {
    const response =  await validateUsername({
        username,
        api: new Api(mockServer.url),
     expect(response).toBeDefined();
    });
  });
});

It seems to me that plain pact v3 syntax is way closer to jest and easier to understand. I have a clear separation between different interactions and only need to wrap my api calls with special executeTest method.
While with jest-pact I'm getting confused as I would need to add a NEW interaction for every single interaction that I do even, so my interaction already has a name defined.

I would suggest removing extra layer of interaction and provide ({ execute, provider}) directly in callback of pactWith. I presume pactWith just maps to describe, we should be able to use standard it blocks to separate tests instead of wrapping them in special syntax.

By interaction already has a name I mean my interaction already has:

uponReceiving: 'a POST request to validate the username',
@YOU54F
Copy link
Member

YOU54F commented Dec 5, 2022

Thanks for this @Maxim-Filimonov - I'll take the time to digest soon, but in the meantime happy to hear everyone else's viewpoints on how the new interface is working for them.

Especially considering some of the changes from the Ruby core -> Rust core and the lifecycle changes.

I agree that the experience with using Jest and Pact JS is pretty nice as it is.

t seems to me that plain pact v3 syntax is way closer to jest and easier to understand. I have a clear separation between different interactions and only need to wrap my api calls with special executeTest method.

@TimothyJones
Copy link
Contributor

It seems to me that plain pact v3 syntax is way closer to jest and easier to understand.

I agree. I think at the time jest-pact's V3 support was written, the "plain" v3 syntax didn't exist, and it looks like it was jest-pact's V3 support was migrated from beta without reviewing it.

@TimothyJones
Copy link
Contributor

By the way, the intention for the interaction block being separate is that you should be able to do this:

pactWith(pactConfig, (interaction) => {
  interaction('authentication api', ({ execute, provider }) => {
    beforeEach(() => {
       return provider.addInteraction(validUsername({ username }));
    })
    
   execute(
       /* some positive case */
    );
   execute(
       /* some negative case */
    );
  });
});

That could be clearer in the docs - although I'm not actually sure this is that nice. I didn't like the name execute at the time.

While with jest-pact I'm getting confused as I would need to add a NEW interaction for every single interaction that I do even, so my interaction already has a name defined.

Doesn't this happen with your example too? Repeated tests would need the same interaction defined.

By interaction already has a name I mean my interaction already has:

Yeah. Ideally Jest-Pact should pass this on so you don't have to.

@johhnsmmith198
Copy link

Hi @Maxim-Filimonov
You had to define a provider outside your describe section in your plain pact v3 example.
Did you define the provider in a separated file and have all your test files importing the same provider object?
Or is it defined in a beforeAll on each test file?

Why does jest-pact v3 is deconstructing: { execute, provider } instead of letting us use provider.executeTest ?
Thanks

@TimothyJones
Copy link
Contributor

Because provider.executeTest didn't exist at the time that the V3 part of jest-pact was written. It looks like the beta of jest-pact was promoted to the main release at the time of the pact-js v10 release without changes.

@Maxim-Filimonov
Copy link
Author

Maxim-Filimonov commented Feb 13, 2023

Hi @Maxim-Filimonov You had to define a provider outside your describe section in your plain pact v3 example. Did you define the provider in a separated file and have all your test files importing the same provider object? Or is it defined in a beforeAll on each test file?

We just do this before describe block:

# pactConfig is just a static object from separate file
const provider = new PactV3(pactConfig);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants