Skip to content

sinon should be a peer dependency #253

@diego-santacruz

Description

@diego-santacruz

Hi,

We had a strange behavior with aws-sdk-client-mock, in our project everything worked find with version 4.0.1 and when we updated to version 4.0.2 (or later) things stopped working, basically the first test in a file works and subsequent ones fail.

We traced it back to the fact that 4.0.1 depends on sinon 16, while 4.0.2 depends on sinon 18. Our project depends on sinon 18. Note that we use mocha. So when using version 4.0.1 we get two versions of sinon installed, our test files use one and aws-sdk-client-mock uses another one internally. That radically changes how sinon restores things. With two copies of sinon the sinon.restore() in our afterEach() would not restore the client mocker, while with a single copy it would.

To guarantee that there is a single copy of sinon it would be best to make it a peer dependency and instead of depending on a single major version depend on a version range, so that there is no conflict when the dependent project updates to sinon 19 or 20 let's say.

For instance

  "peerDependencies": {
    "sinon": ">= 18.0.1"
  }

or eventually

  "peerDependencies": {
    "sinon": ">= 18.0.1 && < 21"
  }

Our current usage style is like follows, where we do reset on the client mock in afterEach() and mock the client only in before(), instead of beforeEach()

describe('My test', () => {
  let dbMock;

  before(() => {
    dbMock = mockClient(DynamoDBDocumentClient);
  })

  after(() => {
    dbMock.restore();
  })

  beforeEach(() => {
    // test specific setup
  });

  afterEach(() => {
    dbMock.reset();
    sinon.restore();
  })
})
  • Node version: v18.20.6
  • Testing lib and version: mocha 10.8.2, sinon 18.0.1
  • Typescript version: 5.5.4
  • AWS SDK v3 Client mock version: 4.0.1, 4.0.2, 4.1.0
  • AWS JS SDK libs and versions: 3.782.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions