Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Test typescriptification continued#8327

Merged
kerryarchibald merged 21 commits into
developfrom
kerry/test-ts-utils
May 2, 2022
Merged

Test typescriptification continued#8327
kerryarchibald merged 21 commits into
developfrom
kerry/test-ts-utils

Conversation

@kerryarchibald
Copy link
Copy Markdown
Contributor

@kerryarchibald kerryarchibald commented Apr 14, 2022

element-hq/element-web#21965


This change is marked as an internal change (Task), so will not be included in the changelog.

Preview: https://pr8327--matrix-react-sdk.netlify.app
⚠️ Do you trust the author of this PR? Maybe this build will steal your keys or give you malware. Exercise caution. Use test accounts.

Kerry Archibald added 7 commits April 14, 2022 15:41
…ncryption-test.ts

Signed-off-by: Kerry Archibald <kerrya@element.io>
Signed-off-by: Kerry Archibald <kerrya@element.io>
Signed-off-by: Kerry Archibald <kerrya@element.io>
…r-test.ts

Signed-off-by: Kerry Archibald <kerrya@element.io>
Signed-off-by: Kerry Archibald <kerrya@element.io>
Signed-off-by: Kerry Archibald <kerrya@element.io>
Signed-off-by: Kerry Archibald <kerrya@element.io>
@kerryarchibald kerryarchibald added the T-Task Refactoring, enabling or disabling functionality, other engineering tasks label Apr 14, 2022
@kerryarchibald kerryarchibald requested a review from a team as a code owner April 14, 2022 14:41
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 14, 2022

Codecov Report

Merging #8327 (0726c3f) into develop (633229c) will decrease coverage by 0.09%.
The diff coverage is n/a.

❗ Current head 0726c3f differs from pull request most recent head 67f7754. Consider uploading reports for the commit 67f7754 to get more accurate results

@@             Coverage Diff             @@
##           develop    #8327      +/-   ##
===========================================
- Coverage    30.83%   30.74%   -0.10%     
===========================================
  Files          893      892       -1     
  Lines        50781    50706      -75     
  Branches     12923    12906      -17     
===========================================
- Hits         15657    15588      -69     
+ Misses       35124    35118       -6     
Impacted Files Coverage Δ
src/components/views/rooms/SearchBar.tsx 0.00% <0.00%> (-89.29%) ⬇️
src/utils/KeyVerificationStateObserver.ts 81.81% <0.00%> (-9.10%) ⬇️
src/hooks/useSettings.ts 81.25% <0.00%> (-6.25%) ⬇️
...ponents/views/beacon/LeftPanelLiveShareWarning.tsx 92.30% <0.00%> (-2.14%) ⬇️
src/components/structures/auth/Registration.tsx 30.17% <0.00%> (-0.90%) ⬇️
src/MatrixClientPeg.ts 30.33% <0.00%> (-0.78%) ⬇️
src/stores/OwnBeaconStore.ts 98.16% <0.00%> (-0.51%) ⬇️
src/events/EventTileFactory.tsx 66.66% <0.00%> (-0.36%) ⬇️
src/components/views/rooms/EventTile.tsx 46.35% <0.00%> (-0.10%) ⬇️
src/utils/beacon/geolocation.ts 96.22% <0.00%> (-0.07%) ⬇️
... and 14 more

Copy link
Copy Markdown
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise lgtm - the questions are legitimate questions, not necessarily hints that things need to change.

Comment thread test/DecryptionFailureTracker-test.ts Outdated
// This test uses localStorage, clear it beforehand
localStorage.clear();
// this functionality is commented out in DecryptionFailureTracker
// commenting as well as xit here to avoid fixing ts issues for dead code
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just delete it? (and the code in DecryptionFailureTracker)

we have git history if it needs to be recovered.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in favour of #8272

Comment thread test/DecryptionFailureTracker-test.ts Outdated
Comment on lines +295 to +297
const error1 = new MockDecryptionError(undefined);
const error2 = new MockDecryptionError(undefined);
const error3 = new MockDecryptionError(undefined);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was testing the unknown error code behaviour? undefined does aggregate, but so should the 3 stringy error codes (according to the test)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duxovni is this the correct behaviour? Should DecryptionFailureTracker actually being aggregating the errors my their mapped code before calling the tracking function in trackFailures? Feels like the description of the test and the actual behaviour are at odds

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in favour of #8272

Comment thread test/DecryptionFailureTracker-test.ts Outdated
class MockDecryptionError extends Error {
constructor(code) {
constructor(
public readonly errcode,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a type

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in favour of #8272

const counts = {};
const tracker = new DecryptionFailureTracker(
(total, errorCode) => counts[errorCode] = (counts[errorCode] || 0) + total,
(errorCode) => Array.from(errorCode).reverse().join(''),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seemed important to the test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was testing that error codes are being run through this map function by asserting the reversed error code was present on the error map expect(counts['1_EDOC_RORRE']).toBe(1)

Because types, and I think because it tests the code in use in our app better, I've tested using the actual error code mapper that the singleton instance uses (

}, (errorCode) => {
// Map JS-SDK error codes to tracker codes for aggregation
switch (errorCode) {
case 'MEGOLM_UNKNOWN_INBOUND_SESSION_ID':
return 'OlmKeysNotSentError';
case 'OLM_UNKNOWN_MESSAGE_INDEX':
return 'OlmIndexError';
case undefined:
return 'OlmUnspecifiedError';
default:
return 'UnknownError';
}
});
)
and asserted that MEGOLM_UNKNOWN_INBOUND_SESSION_ID maps to OlmKeysNotSentError and that the track function is called with the mapped error code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in favour of #8272

Comment thread test/utils/ShieldUtils-test.ts
Comment thread test/utils/ShieldUtils-test.ts Outdated

import {
MatrixClient,
Room } from 'matrix-js-sdk/src/matrix';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Room } from 'matrix-js-sdk/src/matrix';
Room,
} from 'matrix-js-sdk/src/matrix';

Kerry Archibald added 6 commits April 19, 2022 09:16
Signed-off-by: Kerry Archibald <kerrya@element.io>
Signed-off-by: Kerry Archibald <kerrya@element.io>
Signed-off-by: Kerry Archibald <kerrya@element.io>
Signed-off-by: Kerry Archibald <kerrya@element.io>
Signed-off-by: Kerry Archibald <kerrya@element.io>
Copy link
Copy Markdown
Contributor

@duxovni duxovni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already typescriptified test/DecryptionFailureTracker-test.ts in #8272 (along with changing some functionality and adding a bunch of other tests); would you be up for reverting this file, and leaving feedback there if there's anything from this PR I should add into mine?

Kerry Archibald added 5 commits April 21, 2022 08:58
This reverts commit 1ae748c.

Signed-off-by: Kerry Archibald <kerrya@element.io>
Signed-off-by: Kerry Archibald <kerrya@element.io>
@kerryarchibald
Copy link
Copy Markdown
Contributor Author

Thanks @duxovni, I've reverted my changes to DecryptionFailureTracker here in favour of #8272

@RiotRobot RiotRobot temporarily deployed to Netlify April 28, 2022 08:49 Destroyed
Copy link
Copy Markdown
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! apologies for the horribly long review (please poke me in a DM if that happens)

@kerryarchibald kerryarchibald enabled auto-merge (squash) May 2, 2022 07:51
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 2, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@github-actions github-actions Bot temporarily deployed to Netlify May 2, 2022 07:56 Destroyed
@kerryarchibald kerryarchibald merged commit 4a04be6 into develop May 2, 2022
@kerryarchibald kerryarchibald deleted the kerry/test-ts-utils branch May 2, 2022 07:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

T-Task Refactoring, enabling or disabling functionality, other engineering tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants