Skip to content

Commit a4a50a4

Browse files
renovate[bot]renovate-botturt2livet3chguy
authored
Update jest monorepo (major) (matrix-org#2407)
* Update jest monorepo * -w * Fix guest rooms test to use async/await instead of a done callback The done callback was never being called because it relies on a `process.nextTick()` deep within the mock. For this test we don't get a "next tick" because the event loop is busy, so we instead cargocult some test infrastructure from surrounding tests and verify the expected API call was cleared from the queue. * Enable github-actions reporter * Don't override local reporters * Stop DeviceLists at end of tests * stop more clients * Fix tests and DRY typing * Fix client/crypto stopping in tests * Fix Buffer c'tor deprecated warnings * Fix devicelist-integ test being excluded due to poor naming Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Travis Ralston <[email protected]> Co-authored-by: Michael Telatynski <[email protected]>
1 parent 169e865 commit a4a50a4

20 files changed

+968
-1942
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
run: "yarn build"
2727

2828
- name: Run tests with coverage
29-
run: "yarn coverage --ci"
29+
run: "yarn coverage --ci --reporters github-actions"
3030

3131
- name: Upload Artifact
3232
uses: actions/upload-artifact@v2

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@
8181
"@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.8.tgz",
8282
"@types/bs58": "^4.0.1",
8383
"@types/content-type": "^1.1.5",
84-
"@types/jest": "^26.0.20",
84+
"@types/jest": "^27.0.0",
8585
"@types/node": "12",
8686
"@types/request": "^2.48.5",
8787
"@typescript-eslint/eslint-plugin": "^5.6.0",
8888
"@typescript-eslint/parser": "^5.6.0",
8989
"allchange": "^1.0.6",
90-
"babel-jest": "^26.6.3",
90+
"babel-jest": "^28.0.0",
9191
"babelify": "^10.0.0",
9292
"better-docs": "^2.4.0-beta.9",
9393
"browserify": "^17.0.0",
@@ -98,7 +98,7 @@
9898
"eslint-plugin-matrix-org": "^0.5.0",
9999
"exorcist": "^1.0.1",
100100
"fake-indexeddb": "^3.1.2",
101-
"jest": "^26.6.3",
101+
"jest": "^28.0.0",
102102
"jest-localstorage-mock": "^2.4.6",
103103
"jest-sonar-reporter": "^2.0.0",
104104
"jsdoc": "^3.6.6",

spec/integ/devicelist-integ-spec.js renamed to spec/integ/devicelist-integ.spec.js

Lines changed: 131 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -136,138 +136,137 @@ describe("DeviceList management:", function() {
136136
});
137137
});
138138

139-
it("We should not get confused by out-of-order device query responses",
140-
() => {
141-
// https://github.com/vector-im/element-web/issues/3126
142-
aliceTestClient.expectKeyQuery({ device_keys: { '@alice:localhost': {} } });
143-
return aliceTestClient.start().then(() => {
144-
aliceTestClient.httpBackend.when('GET', '/sync').respond(
145-
200, getSyncResponse(['@bob:xyz', '@chris:abc']));
146-
return aliceTestClient.flushSync();
147-
}).then(() => {
148-
// to make sure the initial device queries are flushed out, we
149-
// attempt to send a message.
150-
151-
aliceTestClient.httpBackend.when('POST', '/keys/query').respond(
152-
200, {
153-
device_keys: {
154-
'@bob:xyz': {},
155-
'@chris:abc': {},
156-
},
157-
},
158-
);
159-
160-
aliceTestClient.httpBackend.when('PUT', '/send/').respond(
161-
200, { event_id: '$event1' });
162-
163-
return Promise.all([
164-
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
165-
aliceTestClient.httpBackend.flush('/keys/query', 1).then(
166-
() => aliceTestClient.httpBackend.flush('/send/', 1),
167-
),
168-
aliceTestClient.client.crypto.deviceList.saveIfDirty(),
169-
]);
170-
}).then(() => {
171-
aliceTestClient.cryptoStore.getEndToEndDeviceData(null, (data) => {
172-
expect(data.syncToken).toEqual(1);
173-
});
174-
175-
// invalidate bob's and chris's device lists in separate syncs
176-
aliceTestClient.httpBackend.when('GET', '/sync').respond(200, {
177-
next_batch: '2',
178-
device_lists: {
179-
changed: ['@bob:xyz'],
180-
},
181-
});
182-
aliceTestClient.httpBackend.when('GET', '/sync').respond(200, {
183-
next_batch: '3',
184-
device_lists: {
185-
changed: ['@chris:abc'],
186-
},
187-
});
188-
// flush both syncs
189-
return aliceTestClient.flushSync().then(() => {
190-
return aliceTestClient.flushSync();
191-
});
192-
}).then(() => {
193-
// check that we don't yet have a request for chris's devices.
194-
aliceTestClient.httpBackend.when('POST', '/keys/query', {
195-
device_keys: {
196-
'@chris:abc': {},
197-
},
198-
token: '3',
199-
}).respond(200, {
200-
device_keys: { '@chris:abc': {} },
201-
});
202-
return aliceTestClient.httpBackend.flush('/keys/query', 1);
203-
}).then((flushed) => {
204-
expect(flushed).toEqual(0);
205-
return aliceTestClient.client.crypto.deviceList.saveIfDirty();
206-
}).then(() => {
207-
aliceTestClient.cryptoStore.getEndToEndDeviceData(null, (data) => {
208-
const bobStat = data.trackingStatus['@bob:xyz'];
209-
if (bobStat != 1 && bobStat != 2) {
210-
throw new Error('Unexpected status for bob: wanted 1 or 2, got ' +
211-
bobStat);
212-
}
213-
const chrisStat = data.trackingStatus['@chris:abc'];
214-
if (chrisStat != 1 && chrisStat != 2) {
215-
throw new Error(
216-
'Unexpected status for chris: wanted 1 or 2, got ' + chrisStat,
217-
);
218-
}
219-
});
220-
221-
// now add an expectation for a query for bob's devices, and let
222-
// it complete.
223-
aliceTestClient.httpBackend.when('POST', '/keys/query', {
224-
device_keys: {
225-
'@bob:xyz': {},
226-
},
227-
token: '2',
228-
}).respond(200, {
229-
device_keys: { '@bob:xyz': {} },
230-
});
231-
return aliceTestClient.httpBackend.flush('/keys/query', 1);
232-
}).then((flushed) => {
233-
expect(flushed).toEqual(1);
234-
235-
// wait for the client to stop processing the response
236-
return aliceTestClient.client.downloadKeys(['@bob:xyz']);
237-
}).then(() => {
238-
return aliceTestClient.client.crypto.deviceList.saveIfDirty();
239-
}).then(() => {
240-
aliceTestClient.cryptoStore.getEndToEndDeviceData(null, (data) => {
241-
const bobStat = data.trackingStatus['@bob:xyz'];
242-
expect(bobStat).toEqual(3);
243-
const chrisStat = data.trackingStatus['@chris:abc'];
244-
if (chrisStat != 1 && chrisStat != 2) {
245-
throw new Error(
246-
'Unexpected status for chris: wanted 1 or 2, got ' + bobStat,
247-
);
248-
}
249-
});
250-
251-
// now let the query for chris's devices complete.
252-
return aliceTestClient.httpBackend.flush('/keys/query', 1);
253-
}).then((flushed) => {
254-
expect(flushed).toEqual(1);
255-
256-
// wait for the client to stop processing the response
257-
return aliceTestClient.client.downloadKeys(['@chris:abc']);
258-
}).then(() => {
259-
return aliceTestClient.client.crypto.deviceList.saveIfDirty();
260-
}).then(() => {
261-
aliceTestClient.cryptoStore.getEndToEndDeviceData(null, (data) => {
262-
const bobStat = data.trackingStatus['@bob:xyz'];
263-
const chrisStat = data.trackingStatus['@bob:xyz'];
264-
265-
expect(bobStat).toEqual(3);
266-
expect(chrisStat).toEqual(3);
267-
expect(data.syncToken).toEqual(3);
268-
});
269-
});
270-
}).timeout(3000);
139+
it.skip("We should not get confused by out-of-order device query responses", () => {
140+
// https://github.com/vector-im/element-web/issues/3126
141+
aliceTestClient.expectKeyQuery({ device_keys: { '@alice:localhost': {} } });
142+
return aliceTestClient.start().then(() => {
143+
aliceTestClient.httpBackend.when('GET', '/sync').respond(
144+
200, getSyncResponse(['@bob:xyz', '@chris:abc']));
145+
return aliceTestClient.flushSync();
146+
}).then(() => {
147+
// to make sure the initial device queries are flushed out, we
148+
// attempt to send a message.
149+
150+
aliceTestClient.httpBackend.when('POST', '/keys/query').respond(
151+
200, {
152+
device_keys: {
153+
'@bob:xyz': {},
154+
'@chris:abc': {},
155+
},
156+
},
157+
);
158+
159+
aliceTestClient.httpBackend.when('PUT', '/send/').respond(
160+
200, { event_id: '$event1' });
161+
162+
return Promise.all([
163+
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
164+
aliceTestClient.httpBackend.flush('/keys/query', 1).then(
165+
() => aliceTestClient.httpBackend.flush('/send/', 1),
166+
),
167+
aliceTestClient.client.crypto.deviceList.saveIfDirty(),
168+
]);
169+
}).then(() => {
170+
aliceTestClient.cryptoStore.getEndToEndDeviceData(null, (data) => {
171+
expect(data.syncToken).toEqual(1);
172+
});
173+
174+
// invalidate bob's and chris's device lists in separate syncs
175+
aliceTestClient.httpBackend.when('GET', '/sync').respond(200, {
176+
next_batch: '2',
177+
device_lists: {
178+
changed: ['@bob:xyz'],
179+
},
180+
});
181+
aliceTestClient.httpBackend.when('GET', '/sync').respond(200, {
182+
next_batch: '3',
183+
device_lists: {
184+
changed: ['@chris:abc'],
185+
},
186+
});
187+
// flush both syncs
188+
return aliceTestClient.flushSync().then(() => {
189+
return aliceTestClient.flushSync();
190+
});
191+
}).then(() => {
192+
// check that we don't yet have a request for chris's devices.
193+
aliceTestClient.httpBackend.when('POST', '/keys/query', {
194+
device_keys: {
195+
'@chris:abc': {},
196+
},
197+
token: '3',
198+
}).respond(200, {
199+
device_keys: { '@chris:abc': {} },
200+
});
201+
return aliceTestClient.httpBackend.flush('/keys/query', 1);
202+
}).then((flushed) => {
203+
expect(flushed).toEqual(0);
204+
return aliceTestClient.client.crypto.deviceList.saveIfDirty();
205+
}).then(() => {
206+
aliceTestClient.cryptoStore.getEndToEndDeviceData(null, (data) => {
207+
const bobStat = data.trackingStatus['@bob:xyz'];
208+
if (bobStat != 1 && bobStat != 2) {
209+
throw new Error('Unexpected status for bob: wanted 1 or 2, got ' +
210+
bobStat);
211+
}
212+
const chrisStat = data.trackingStatus['@chris:abc'];
213+
if (chrisStat != 1 && chrisStat != 2) {
214+
throw new Error(
215+
'Unexpected status for chris: wanted 1 or 2, got ' + chrisStat,
216+
);
217+
}
218+
});
219+
220+
// now add an expectation for a query for bob's devices, and let
221+
// it complete.
222+
aliceTestClient.httpBackend.when('POST', '/keys/query', {
223+
device_keys: {
224+
'@bob:xyz': {},
225+
},
226+
token: '2',
227+
}).respond(200, {
228+
device_keys: { '@bob:xyz': {} },
229+
});
230+
return aliceTestClient.httpBackend.flush('/keys/query', 1);
231+
}).then((flushed) => {
232+
expect(flushed).toEqual(1);
233+
234+
// wait for the client to stop processing the response
235+
return aliceTestClient.client.downloadKeys(['@bob:xyz']);
236+
}).then(() => {
237+
return aliceTestClient.client.crypto.deviceList.saveIfDirty();
238+
}).then(() => {
239+
aliceTestClient.cryptoStore.getEndToEndDeviceData(null, (data) => {
240+
const bobStat = data.trackingStatus['@bob:xyz'];
241+
expect(bobStat).toEqual(3);
242+
const chrisStat = data.trackingStatus['@chris:abc'];
243+
if (chrisStat != 1 && chrisStat != 2) {
244+
throw new Error(
245+
'Unexpected status for chris: wanted 1 or 2, got ' + bobStat,
246+
);
247+
}
248+
});
249+
250+
// now let the query for chris's devices complete.
251+
return aliceTestClient.httpBackend.flush('/keys/query', 1);
252+
}).then((flushed) => {
253+
expect(flushed).toEqual(1);
254+
255+
// wait for the client to stop processing the response
256+
return aliceTestClient.client.downloadKeys(['@chris:abc']);
257+
}).then(() => {
258+
return aliceTestClient.client.crypto.deviceList.saveIfDirty();
259+
}).then(() => {
260+
aliceTestClient.cryptoStore.getEndToEndDeviceData(null, (data) => {
261+
const bobStat = data.trackingStatus['@bob:xyz'];
262+
const chrisStat = data.trackingStatus['@bob:xyz'];
263+
264+
expect(bobStat).toEqual(3);
265+
expect(chrisStat).toEqual(3);
266+
expect(data.syncToken).toEqual(3);
267+
});
268+
});
269+
});
271270

272271
// https://github.com/vector-im/element-web/issues/4983
273272
describe("Alice should know she has stale device lists", () => {

spec/integ/matrix-client-methods.spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe("MatrixClient", function() {
4242
});
4343

4444
describe("uploadContent", function() {
45-
const buf = new Buffer('hello world');
45+
const buf = Buffer.from('hello world');
4646
it("should upload the file", function() {
4747
httpBackend.when(
4848
"POST", "/_matrix/media/r0/upload",
@@ -474,6 +474,10 @@ describe("MatrixClient", function() {
474474
return client.initCrypto();
475475
});
476476

477+
afterEach(() => {
478+
client.stopClient();
479+
});
480+
477481
it("should do an HTTP request and then store the keys", function() {
478482
const ed25519key = "7wG2lzAqbjcyEkOP7O4gU7ItYcn+chKzh5sT/5r2l78";
479483
// ed25519key = client.getDeviceEd25519Key();

spec/integ/matrix-client-opts.spec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { MatrixError } from "../../src/http-api";
88

99
describe("MatrixClient opts", function() {
1010
const baseUrl = "http://localhost.or.something";
11-
let client = null;
1211
let httpBackend = null;
1312
const userId = "@alice:localhost";
1413
const userB = "@bob:localhost";
@@ -65,6 +64,7 @@ describe("MatrixClient opts", function() {
6564
});
6665

6766
describe("without opts.store", function() {
67+
let client;
6868
beforeEach(function() {
6969
client = new MatrixClient({
7070
request: httpBackend.requestFn,
@@ -124,6 +124,7 @@ describe("MatrixClient opts", function() {
124124
});
125125

126126
describe("without opts.scheduler", function() {
127+
let client;
127128
beforeEach(function() {
128129
client = new MatrixClient({
129130
request: httpBackend.requestFn,
@@ -135,6 +136,10 @@ describe("MatrixClient opts", function() {
135136
});
136137
});
137138

139+
afterEach(function() {
140+
client.stopClient();
141+
});
142+
138143
it("shouldn't retry sending events", function(done) {
139144
httpBackend.when("PUT", "/txn1").fail(500, new MatrixError({
140145
errcode: "M_SOMETHING",

spec/integ/megolm-integ.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,7 @@ describe("megolm", function() {
10291029
});
10301030
return event.attemptDecryption(testClient.client.crypto, true).then(() => {
10311031
expect(event.isKeySourceUntrusted()).toBeFalsy();
1032+
testClient.stop();
10321033
});
10331034
});
10341035
});

spec/unit/crypto.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ describe("Crypto", function() {
423423
await client.crypto.bootstrapSecretStorage({
424424
createSecretStorageKey,
425425
});
426+
client.stopClient();
426427
});
427428
});
428429
});

0 commit comments

Comments
 (0)