Skip to content

Commit 6d82b58

Browse files
authored
remove ts-sinon dependency, upgrade sinon (#804)
`ts-sinon` is no longer maintained, and doesn't seem to be very useful for us. Upgrade `sinon` and `@types/sinon` to latest.
1 parent 080359c commit 6d82b58

File tree

10 files changed

+289
-305
lines changed

10 files changed

+289
-305
lines changed

package-lock.json

Lines changed: 187 additions & 213 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tbd54566975/dwn-sdk-js",
3-
"version": "0.4.6",
3+
"version": "0.4.7",
44
"description": "A reference implementation of https://identity.foundation/decentralized-web-node/spec/",
55
"repository": {
66
"type": "git",
@@ -101,7 +101,7 @@
101101
"@types/randombytes": "2.0.0",
102102
"@types/readable-stream": "4.0.10",
103103
"@types/secp256k1": "4.0.3",
104-
"@types/sinon": "10.0.11",
104+
"@types/sinon": "^17.0.3",
105105
"@types/uuid": "^9.0.1",
106106
"@types/varint": "6.0.0",
107107
"@typescript-eslint/eslint-plugin": "^7.9.0",
@@ -133,8 +133,7 @@
133133
"playwright": "^1.44.0",
134134
"rimraf": "^3.0.2",
135135
"search-index": "3.4.0",
136-
"sinon": "13.0.1",
137-
"ts-sinon": "^2.0.2",
136+
"sinon": "18.0.1",
138137
"typescript": "^5.1.6",
139138
"util": "0.12.4"
140139
},

tests/core/protocol-authorization.spec.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import type { MessageStore } from '../../src/index.js';
2-
31
import { DwnErrorCode } from '../../src/core/dwn-error.js';
42
import { expect } from 'chai';
3+
import { MessageStoreLevel } from '../../src/index.js';
54
import { ProtocolAuthorization } from '../../src/core/protocol-authorization.js';
6-
import { stubInterface } from 'ts-sinon';
75
import { TestDataGenerator } from '../utils/test-data-generator.js';
86

7+
import sinon from 'sinon';
8+
99
describe('ProtocolAuthorization', () => {
10+
beforeEach(() => {
11+
sinon.restore();
12+
});
13+
1014
describe('authorizeWrite()', () => {
1115
it('should throw if message references non-existent parent', async () => {
1216
const alice = await TestDataGenerator.generateDidKeyPersona();
@@ -17,7 +21,7 @@ describe('ProtocolAuthorization', () => {
1721
});
1822

1923
// stub the message store
20-
const messageStoreStub = stubInterface<MessageStore>();
24+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
2125
messageStoreStub.query.resolves({ messages: [] }); // simulate parent not in message store
2226

2327
await expect(ProtocolAuthorization.authorizeWrite(alice.did, recordsWrite, messageStoreStub)).to.be.rejectedWith(
@@ -38,7 +42,7 @@ describe('ProtocolAuthorization', () => {
3842
}
3943
} as any;
4044

41-
const messageStoreStub = stubInterface<MessageStore>();
45+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
4246
expect(ProtocolAuthorization['getActionsSeekingARuleMatch'](alice.did, deliberatelyCraftedInvalidMessage, messageStoreStub)).to.be.empty;
4347
});
4448
});

tests/dwn.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import type { DataStore, EventLog, MessageStore, ResumableTaskStore } from '../s
66
import chaiAsPromised from 'chai-as-promised';
77
import sinon from 'sinon';
88
import chai, { expect } from 'chai';
9+
import { DataStoreLevel, EventEmitterStream, EventLogLevel, MessageStoreLevel, ResumableTaskStoreLevel } from '../src/index.js';
910

1011
import { Dwn } from '../src/dwn.js';
1112
import { Message } from '../src/core/message.js';
12-
import { stubInterface } from 'ts-sinon';
1313
import { TestDataGenerator } from './utils/test-data-generator.js';
1414
import { TestEventStream } from './test-event-stream.js';
1515
import { TestStores } from './test-stores.js';
@@ -50,6 +50,7 @@ export function testDwnClass(): void {
5050
});
5151

5252
after(async () => {
53+
sinon.restore();
5354
await dwn.close();
5455
});
5556

@@ -133,11 +134,11 @@ export function testDwnClass(): void {
133134
}
134135
};
135136

136-
const messageStoreStub = stubInterface<MessageStore>();
137-
const dataStoreStub = stubInterface<DataStore>();
138-
const resumableTaskStoreStub = stubInterface<ResumableTaskStore>();
139-
const eventLogStub = stubInterface<EventLog>();
140-
const eventStreamStub = stubInterface<EventStream>();
137+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
138+
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
139+
const resumableTaskStoreStub = sinon.createStubInstance(ResumableTaskStoreLevel);
140+
const eventLogStub = sinon.createStubInstance(EventLogLevel);
141+
const eventStreamStub = sinon.createStubInstance(EventEmitterStream);
141142

142143
const dwnWithConfig = await Dwn.create({
143144
tenantGate : blockAllTenantGate,
@@ -166,12 +167,11 @@ export function testDwnClass(): void {
166167
return { isActiveTenant: false, detail: customMessage };
167168
}
168169
};
169-
170-
const messageStoreStub = stubInterface<MessageStore>();
171-
const dataStoreStub = stubInterface<DataStore>();
172-
const resumableTaskStoreStub = stubInterface<ResumableTaskStore>();
173-
const eventLogStub = stubInterface<EventLog>();
174-
const eventStreamStub = stubInterface<EventStream>();
170+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
171+
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
172+
const resumableTaskStoreStub = sinon.createStubInstance(ResumableTaskStoreLevel);
173+
const eventLogStub = sinon.createStubInstance(EventLogLevel);
174+
const eventStreamStub = sinon.createStubInstance(EventEmitterStream);
175175

176176
const dwnWithConfig = await Dwn.create({
177177
tenantGate : blockAllTenantGate,

tests/handlers/records-delete.spec.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DidResolver } from '@web5/dids';
22
import type { EventStream } from '../../src/types/subscriptions.js';
3-
import type { ResumableTaskManager } from '../../src/core/resumable-task-manager.js';
3+
import { ResumableTaskManager } from '../../src/core/resumable-task-manager.js';
44
import type {
55
DataStore,
66
EventLog,
@@ -25,13 +25,12 @@ import { DwnMethodName } from '../../src/enums/dwn-interface-method.js';
2525
import { Message } from '../../src/core/message.js';
2626
import { normalizeSchemaUrl } from '../../src/utils/url.js';
2727
import { RecordsDeleteHandler } from '../../src/handlers/records-delete.js';
28-
import { stubInterface } from 'ts-sinon';
2928
import { TestDataGenerator } from '../utils/test-data-generator.js';
3029
import { TestEventStream } from '../test-event-stream.js';
3130
import { TestStores } from '../test-stores.js';
3231
import { TestStubGenerator } from '../utils/test-stub-generator.js';
3332
import { Time } from '../../src/utils/time.js';
34-
import { DataStream, Dwn, Encoder, Jws, RecordsDelete, RecordsRead, RecordsWrite } from '../../src/index.js';
33+
import { DataStream, Dwn, Encoder, Jws, MessageStoreLevel, RecordsDelete, RecordsRead, RecordsWrite } from '../../src/index.js';
3534
import { DidKey, UniversalResolver } from '@web5/dids';
3635

3736
chai.use(chaiAsPromised);
@@ -46,6 +45,14 @@ export function testRecordsDeleteHandler(): void {
4645
let eventStream: EventStream;
4746
let dwn: Dwn;
4847

48+
beforeEach(() => {
49+
sinon.restore();
50+
});
51+
52+
after(() => {
53+
sinon.restore();
54+
});
55+
4956
describe('functional tests', () => {
5057

5158
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
@@ -64,8 +71,6 @@ export function testRecordsDeleteHandler(): void {
6471
});
6572

6673
beforeEach(async () => {
67-
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
68-
6974
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
7075
await messageStore.clear();
7176
await dataStore.clear();
@@ -764,10 +769,12 @@ export function testRecordsDeleteHandler(): void {
764769
// intentionally not supplying the public key so a different public key is generated to simulate invalid signature
765770
const mismatchingPersona = await TestDataGenerator.generatePersona({ did: author.did, keyId: author.keyId });
766771
const didResolver = TestStubGenerator.createDidResolverStub(mismatchingPersona);
767-
const messageStore = stubInterface<MessageStore>();
768-
const resumableTaskManager = stubInterface<ResumableTaskManager>();
769772

770-
const recordsDeleteHandler = new RecordsDeleteHandler(didResolver, messageStore, resumableTaskManager);
773+
// setting up a stub method resolver & message store
774+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
775+
const resumableTaskManagerStub = sinon.createStubInstance(ResumableTaskManager);
776+
777+
const recordsDeleteHandler = new RecordsDeleteHandler(didResolver, messageStoreStub, resumableTaskManagerStub);
771778
const reply = await recordsDeleteHandler.handle({ tenant, message });
772779
expect(reply.status.code).to.equal(401);
773780
});
@@ -777,10 +784,10 @@ export function testRecordsDeleteHandler(): void {
777784
const tenant = author.did;
778785

779786
// setting up a stub method resolver & message store
780-
const messageStore = stubInterface<MessageStore>();
781-
const resumableTaskManager = stubInterface<ResumableTaskManager>();
787+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
788+
const resumableTaskManagerStub = sinon.createStubInstance(ResumableTaskManager);
782789

783-
const recordsDeleteHandler = new RecordsDeleteHandler(didResolver, messageStore, resumableTaskManager);
790+
const recordsDeleteHandler = new RecordsDeleteHandler(didResolver, messageStoreStub, resumableTaskManagerStub);
784791

785792
// stub the `parse()` function to throw an error
786793
sinon.stub(RecordsDelete, 'parse').throws('anyError');

tests/handlers/records-query.spec.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,22 @@ import { Message } from '../../src/core/message.js';
2323
import { RecordsQuery } from '../../src/interfaces/records-query.js';
2424
import { RecordsQueryHandler } from '../../src/handlers/records-query.js';
2525
import { RecordsWriteHandler } from '../../src/handlers/records-write.js';
26-
import { stubInterface } from 'ts-sinon';
2726
import { TestDataGenerator } from '../utils/test-data-generator.js';
2827
import { TestEventStream } from '../test-event-stream.js';
2928
import { TestStores } from '../test-stores.js';
3029
import { TestStubGenerator } from '../utils/test-stub-generator.js';
30+
import { DataStoreLevel, Dwn, MessageStoreLevel, RecordsWrite, Time } from '../../src/index.js';
3131
import { DidKey, UniversalResolver } from '@web5/dids';
32-
import { Dwn, RecordsWrite, Time } from '../../src/index.js';
3332

3433
chai.use(chaiAsPromised);
3534

3635
export function testRecordsQueryHandler(): void {
3736
describe('RecordsQueryHandler.handle()', () => {
37+
38+
beforeEach(() => {
39+
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
40+
});
41+
3842
describe('functional tests', () => {
3943
let didResolver: DidResolver;
4044
let messageStore: MessageStore;
@@ -60,8 +64,6 @@ export function testRecordsQueryHandler(): void {
6064
});
6165

6266
beforeEach(async () => {
63-
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
64-
6567
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
6668
await messageStore.clear();
6769
await dataStore.clear();
@@ -3005,10 +3007,10 @@ export function testRecordsQueryHandler(): void {
30053007
// intentionally not supplying the public key so a different public key is generated to simulate invalid signature
30063008
const mismatchingPersona = await TestDataGenerator.generatePersona({ did: author!.did, keyId: author!.keyId });
30073009
const didResolver = TestStubGenerator.createDidResolverStub(mismatchingPersona);
3008-
const messageStore = stubInterface<MessageStore>();
3009-
const dataStore = stubInterface<DataStore>();
3010+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
3011+
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
30103012

3011-
const recordsQueryHandler = new RecordsQueryHandler(didResolver, messageStore, dataStore);
3013+
const recordsQueryHandler = new RecordsQueryHandler(didResolver, messageStoreStub, dataStoreStub);
30123014
const reply = await recordsQueryHandler.handle({ tenant, message });
30133015

30143016
expect(reply.status.code).to.equal(401);
@@ -3020,9 +3022,9 @@ export function testRecordsQueryHandler(): void {
30203022

30213023
// setting up a stub method resolver & message store
30223024
const didResolver = TestStubGenerator.createDidResolverStub(author!);
3023-
const messageStore = stubInterface<MessageStore>();
3024-
const dataStore = stubInterface<DataStore>();
3025-
const recordsQueryHandler = new RecordsQueryHandler(didResolver, messageStore, dataStore);
3025+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
3026+
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
3027+
const recordsQueryHandler = new RecordsQueryHandler(didResolver, messageStoreStub, dataStoreStub);
30263028

30273029
// stub the `parse()` function to throw an error
30283030
sinon.stub(RecordsQuery, 'parse').throws('anyError');

tests/handlers/records-read.spec.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { EncryptionInput } from '../../src/interfaces/records-write.js';
44
import type { EventStream } from '../../src/types/subscriptions.js';
55
import type { DataStore, EventLog, MessageStore, ProtocolDefinition, ProtocolsConfigureMessage, ResumableTaskStore } from '../../src/index.js';
66

7-
import { DwnConstant, PermissionsProtocol, Time } from '../../src/index.js';
7+
import { DataStoreLevel, DwnConstant, MessageStoreLevel, PermissionsProtocol, Time } from '../../src/index.js';
88
import { DwnInterfaceName, DwnMethodName } from '../../src/index.js';
99

1010
import chaiAsPromised from 'chai-as-promised';
@@ -26,7 +26,6 @@ import { Encryption } from '../../src/utils/encryption.js';
2626
import { HdKey } from '../../src/utils/hd-key.js';
2727
import { KeyDerivationScheme } from '../../src/utils/hd-key.js';
2828
import { RecordsReadHandler } from '../../src/handlers/records-read.js';
29-
import { stubInterface } from 'ts-sinon';
3029
import { TestDataGenerator } from '../utils/test-data-generator.js';
3130
import { TestEventStream } from '../test-event-stream.js';
3231
import { TestStores } from '../test-stores.js';
@@ -48,6 +47,10 @@ export function testRecordsReadHandler(): void {
4847
let eventStream: EventStream;
4948
let dwn: Dwn;
5049

50+
beforeEach(() => {
51+
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
52+
});
53+
5154
describe('functional tests', () => {
5255

5356
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
@@ -66,8 +69,6 @@ export function testRecordsReadHandler(): void {
6669
});
6770

6871
beforeEach(async () => {
69-
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
70-
7172
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
7273
await messageStore.clear();
7374
await dataStore.clear();
@@ -1893,10 +1894,10 @@ export function testRecordsReadHandler(): void {
18931894
// intentionally not supplying the public key so a different public key is generated to simulate invalid signature
18941895
const mismatchingPersona = await TestDataGenerator.generatePersona({ did: alice.did, keyId: alice.keyId });
18951896
const didResolver = TestStubGenerator.createDidResolverStub(mismatchingPersona);
1896-
const messageStore = stubInterface<MessageStore>();
1897-
const dataStore = stubInterface<DataStore>();
1897+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
1898+
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
18981899

1899-
const recordsReadHandler = new RecordsReadHandler(didResolver, messageStore, dataStore);
1900+
const recordsReadHandler = new RecordsReadHandler(didResolver, messageStoreStub, dataStoreStub);
19001901
const reply = await recordsReadHandler.handle({ tenant: alice.did, message: recordsRead.message });
19011902
expect(reply.status.code).to.equal(401);
19021903
});
@@ -1911,10 +1912,10 @@ export function testRecordsReadHandler(): void {
19111912
});
19121913

19131914
// setting up a stub method resolver & message store
1914-
const messageStore = stubInterface<MessageStore>();
1915-
const dataStore = stubInterface<DataStore>();
1915+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
1916+
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
19161917

1917-
const recordsReadHandler = new RecordsReadHandler(didResolver, messageStore, dataStore);
1918+
const recordsReadHandler = new RecordsReadHandler(didResolver, messageStoreStub, dataStoreStub);
19181919

19191920
// stub the `parse()` function to throw an error
19201921
sinon.stub(RecordsRead, 'parse').throws('anyError');

tests/handlers/records-subscribe.spec.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ import { Message } from '../../src/core/message.js';
1515
import { Poller } from '../utils/poller.js';
1616
import { RecordsSubscribe } from '../../src/interfaces/records-subscribe.js';
1717
import { RecordsSubscribeHandler } from '../../src/handlers/records-subscribe.js';
18-
import { stubInterface } from 'ts-sinon';
1918
import { TestDataGenerator } from '../utils/test-data-generator.js';
2019
import { TestEventStream } from '../test-event-stream.js';
2120
import { TestStores } from '../test-stores.js';
2221
import { TestStubGenerator } from '../utils/test-stub-generator.js';
2322
import { DidKey, UniversalResolver } from '@web5/dids';
24-
import { Dwn, DwnErrorCode, DwnMethodName, Time } from '../../src/index.js';
23+
import { Dwn, DwnErrorCode, DwnMethodName, EventEmitterStream, MessageStoreLevel, Time } from '../../src/index.js';
2524

2625
chai.use(chaiAsPromised);
2726

@@ -232,10 +231,10 @@ export function testRecordsSubscribeHandler(): void {
232231
// intentionally not supplying the public key so a different public key is generated to simulate invalid signature
233232
const mismatchingPersona = await TestDataGenerator.generatePersona({ did: author!.did, keyId: author!.keyId });
234233
const didResolver = TestStubGenerator.createDidResolverStub(mismatchingPersona);
235-
const messageStore = stubInterface<MessageStore>();
236-
const eventStream = stubInterface<EventStream>();
234+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
235+
const eventStreamStub = sinon.createStubInstance(EventEmitterStream);
237236

238-
const recordsSubscribeHandler = new RecordsSubscribeHandler(didResolver, messageStore, eventStream);
237+
const recordsSubscribeHandler = new RecordsSubscribeHandler(didResolver, messageStoreStub, eventStreamStub);
239238
const reply = await recordsSubscribeHandler.handle({ tenant, message, subscriptionHandler: () => {} });
240239

241240
expect(reply.status.code).to.equal(401);
@@ -247,9 +246,9 @@ export function testRecordsSubscribeHandler(): void {
247246

248247
// setting up a stub method resolver & message store
249248
const didResolver = TestStubGenerator.createDidResolverStub(author!);
250-
const messageStore = stubInterface<MessageStore>();
251-
const eventStream = stubInterface<EventStream>();
252-
const recordsSubscribeHandler = new RecordsSubscribeHandler(didResolver, messageStore, eventStream);
249+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
250+
const eventStreamStub = sinon.createStubInstance(EventEmitterStream);
251+
const recordsSubscribeHandler = new RecordsSubscribeHandler(didResolver, messageStoreStub, eventStreamStub);
253252

254253
// stub the `parse()` function to throw an error
255254
sinon.stub(RecordsSubscribe, 'parse').throws('anyError');

0 commit comments

Comments
 (0)