https://pact.io logo
#pact-js
Title
# pact-js
a

Artur Neumann

04/04/2022, 5:45 AM
with v10.0.0-beta.59 it seems not to be possible to have in one interaction multiple provider states with the same name. That was possible in .36. Is that a bug or a feature? My use-case is to create multiple files. So I call multiple times `
Copy code
provider.given('file exists', { username, password, fileName: resource })
but in the JSON I only have one providerstate with that name
Copy code
"providerStates": [
        {
          "name": "the user is recreated",
          "params":...
        },
        {
          "name": "file exists",
          "params": {
            "fileName": "testFolder/文件.txt",
            "password": "test123",
            "username": "test123"
          }
        },
        {
          "name": "resource is shared",
          "params": ...
        }
      ]
Making the names of provider states individual makes them appear in the JSON, but that would mean I would also have to have an individual state definition in the provider tests (stateHandlers)
m

Matt (pactflow.io / pact-js / pact-go)

04/04/2022, 5:47 AM
hmmm it seems like that would have been a bug in the core that has been resolved (I don’t know why/where just yet). The name of the state I think needs to be unique
@uglyog is my assumption correct? If not, I’ll see if I can track down where that assumption is built in code (whether JS or somewhere else)
u

uglyog

04/04/2022, 5:49 AM
It may have been an accidental feature, I don't recall doing that by design
m

Matt (pactflow.io / pact-js / pact-go)

04/04/2022, 5:49 AM
Should it be possible to have multiple provider states with the same description (but different params?)
u

uglyog

04/04/2022, 5:50 AM
But then it has been a while, and maybe I just don't recall what I was doing back then
m

Matt (pactflow.io / pact-js / pact-go)

04/04/2022, 5:50 AM
I assume not
a

Artur Neumann

04/04/2022, 5:51 AM
if the same description is not allowed, then my tests cannot have just arbitrary filenames, but the names have to be part of the description, or some kind of counter is needed
u

uglyog

04/04/2022, 5:51 AM
The provider states are not keyed, so you could have multiple in the Pact file with the same description. I don't know what the effect will be. But I assume it will just loop though the list and call the handler based on the name
a

Artur Neumann

04/04/2022, 5:52 AM
that would be my expectation
u

uglyog

04/04/2022, 5:52 AM
Just checked Pact-JVM, uniqueness is description + parameters
m

Matt (pactflow.io / pact-js / pact-go)

04/04/2022, 5:53 AM
Cool. I'll see if I can track down where the issue is
It might be there is a keyed state somewhere so it's overridden
Your use case makes sense actually
a

Artur Neumann

04/04/2022, 5:55 AM
the stateHandler on the provider side is happy with the same names, just loops. So the issue is on the side of writing to the JSON
👍 1
any news on this? Should I create an issue to track it?
m

Matt (pactflow.io / pact-js / pact-go)

04/06/2022, 11:05 AM
yes please!
3 Views