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

Commit b9ee1a3

Browse files
authored
Merge branch 'develop' into kerry/fix/21997/map-thread-display
2 parents 093a36f + 3b1e715 commit b9ee1a3

File tree

14 files changed

+163
-80
lines changed

14 files changed

+163
-80
lines changed

.github/codecov.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/sonarqube.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: SonarQube
2+
on:
3+
workflow_run:
4+
workflows: [ "Tests" ]
5+
types:
6+
- completed
7+
jobs:
8+
sonarqube:
9+
name: SonarQube
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
15+
16+
# There's a 'download artifact' action, but it hasn't been updated for the workflow_run action
17+
# (https://github.com/actions/download-artifact/issues/60) so instead we get this mess:
18+
- name: Download Coverage Report
19+
uses: actions/[email protected]
20+
if: github.event.workflow_run.conclusion == 'success'
21+
with:
22+
script: |
23+
const artifacts = await github.actions.listWorkflowRunArtifacts({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
run_id: ${{ github.event.workflow_run.id }},
27+
});
28+
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
29+
return artifact.name == "coverage"
30+
})[0];
31+
const download = await github.actions.downloadArtifact({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
artifact_id: matchArtifact.id,
35+
archive_format: 'zip',
36+
});
37+
const fs = require('fs');
38+
fs.writeFileSync('${{github.workspace}}/coverage.zip', Buffer.from(download.data));
39+
- name: Extract Coverage Report
40+
run: unzip -d coverage coverage.zip && rm coverage.zip
41+
if: github.event.workflow_run.conclusion == 'success'
42+
43+
- name: SonarCloud Scan
44+
uses: SonarSource/sonarcloud-github-action@master
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
47+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/static_analysis.yaml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,3 @@ jobs:
8787

8888
- name: Run Linter
8989
run: "yarn run lint:style"
90-
91-
sonarqube:
92-
name: "SonarQube"
93-
runs-on: ubuntu-latest
94-
steps:
95-
- uses: actions/checkout@v2
96-
with:
97-
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
98-
- name: SonarCloud Scan
99-
uses: SonarSource/sonarcloud-github-action@master
100-
env:
101-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/tests.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@ env:
1111
PR_NUMBER: ${{ github.event.pull_request.number }}
1212
jobs:
1313
jest:
14-
name: Jest with Codecov
14+
name: Jest
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Checkout code
1818
uses: actions/checkout@v2
19-
with:
20-
# If this is a pull request, make sure we check out its head rather than the
21-
# automatically generated merge commit, so that the coverage diff excludes
22-
# unrelated changes in the base branch
23-
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || '' }}
2419

2520
- name: Yarn cache
2621
uses: actions/setup-node@v3
@@ -31,11 +26,12 @@ jobs:
3126
run: "./scripts/ci/install-deps.sh --ignore-scripts"
3227

3328
- name: Run tests with coverage
34-
run: "yarn coverage"
29+
run: "yarn coverage --ci"
3530

36-
- name: Upload coverage
37-
uses: codecov/codecov-action@v2
31+
- name: Upload Artifact
32+
uses: actions/upload-artifact@v2
3833
with:
39-
fail_ci_if_error: false
40-
verbose: true
41-
override_commit: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || '' }}
34+
name: coverage
35+
path: |
36+
coverage
37+
!coverage/lcov-report

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
"jest-fetch-mock": "^3.0.3",
185185
"jest-mock": "^27.5.1",
186186
"jest-raw-loader": "^1.0.1",
187+
"jest-sonar-reporter": "^2.0.0",
187188
"matrix-mock-request": "^1.2.3",
188189
"matrix-react-test-utils": "^0.2.3",
189190
"matrix-web-i18n": "^1.2.0",
@@ -233,9 +234,14 @@
233234
"<rootDir>/src/**/*.{js,ts,tsx}"
234235
],
235236
"coverageReporters": [
236-
"text",
237-
"json"
238-
]
237+
"text-summary",
238+
"lcov"
239+
],
240+
"testResultsProcessor": "jest-sonar-reporter"
241+
},
242+
"jestSonar": {
243+
"reportPath": "coverage",
244+
"sonar56x": true
239245
},
240246
"typings": "./lib/index.d.ts"
241247
}

sonar-project.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ sonar.organization=matrix-org
1414
sonar.sources=src,res
1515
sonar.tests=test,cypress
1616
sonar.exclusions=__mocks__,docs
17+
18+
sonar.typescript.tsconfigPath=./tsconfig.json
19+
sonar.javascript.lcov.reportPaths=coverage/lcov.info
20+
sonar.coverage.exclusions=spec/*.ts
21+
sonar.testExecutionReportPaths=coverage/test-report.xml
22+
sonar.genericcoverage.unitTestReportPaths=coverage/test-report.xml

src/components/views/location/Map.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ const useMapWithStyle = ({ id, centerGeoUri, onError, interactive, bounds }) =>
5151
try {
5252
const coords = parseGeoUri(centerGeoUri);
5353
map.setCenter({ lon: coords.longitude, lat: coords.latitude });
54-
} catch (error) {
55-
logger.error('Could not set map center', centerGeoUri);
54+
} catch (_error) {
55+
logger.error('Could not set map center');
5656
}
5757
}
5858
}, [map, centerGeoUri]);
@@ -65,8 +65,8 @@ const useMapWithStyle = ({ id, centerGeoUri, onError, interactive, bounds }) =>
6565
[bounds.east, bounds.north],
6666
);
6767
map.fitBounds(lngLatBounds, { padding: 100, maxZoom: 15 });
68-
} catch (error) {
69-
logger.error('Invalid map bounds', error);
68+
} catch (_error) {
69+
logger.error('Invalid map bounds');
7070
}
7171
}
7272
}, [map, bounds]);

src/linkify-matrix.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ export const options = {
225225
rel: 'noreferrer noopener',
226226
},
227227

228+
ignoreTags: ['pre', 'code'],
229+
228230
className: 'linkified',
229231

230232
target: function(href: string, type: Type | string): string {

test/components/stub-component.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/components/views/dialogs/ForwardDialog-test.js renamed to test/components/views/dialogs/ForwardDialog-test.tsx

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,59 @@ limitations under the License.
1717
import React from "react";
1818
import { mount } from "enzyme";
1919
import { act } from "react-dom/test-utils";
20+
import { MatrixEvent, EventType } from "matrix-js-sdk/src/matrix";
2021

21-
import * as TestUtils from "../../../test-utils";
2222
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
23+
import ForwardDialog from "../../../../src/components/views/dialogs/ForwardDialog";
2324
import DMRoomMap from "../../../../src/utils/DMRoomMap";
2425
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
25-
import ForwardDialog from "../../../../src/components/views/dialogs/ForwardDialog";
26+
import {
27+
getMockClientWithEventEmitter,
28+
mkEvent,
29+
mkMessage,
30+
mkStubRoom,
31+
} from "../../../test-utils";
2632

2733
describe("ForwardDialog", () => {
2834
const sourceRoom = "!111111111111111111:example.org";
29-
const defaultMessage = TestUtils.mkMessage({
35+
const aliceId = "@alice:example.org";
36+
const defaultMessage = mkMessage({
3037
room: sourceRoom,
31-
user: "@alice:example.org",
38+
user: aliceId,
3239
msg: "Hello world!",
3340
event: true,
3441
});
35-
const defaultRooms = ["a", "A", "b"].map(name => TestUtils.mkStubRoom(name, name));
42+
const accountDataEvent = new MatrixEvent({
43+
type: EventType.Direct,
44+
sender: aliceId,
45+
content: {},
46+
});
47+
const mockClient = getMockClientWithEventEmitter({
48+
getUserId: jest.fn().mockReturnValue(aliceId),
49+
isGuest: jest.fn().mockReturnValue(false),
50+
getVisibleRooms: jest.fn().mockReturnValue([]),
51+
getRoom: jest.fn(),
52+
getAccountData: jest.fn().mockReturnValue(accountDataEvent),
53+
getPushActionsForEvent: jest.fn(),
54+
mxcUrlToHttp: jest.fn().mockReturnValue(''),
55+
isRoomEncrypted: jest.fn().mockReturnValue(false),
56+
getProfileInfo: jest.fn().mockResolvedValue({
57+
displayname: 'Alice',
58+
}),
59+
decryptEventIfNeeded: jest.fn(),
60+
sendEvent: jest.fn(),
61+
});
62+
const defaultRooms = ["a", "A", "b"].map(name => mkStubRoom(name, name, mockClient));
3663

3764
const mountForwardDialog = async (message = defaultMessage, rooms = defaultRooms) => {
38-
const client = MatrixClientPeg.get();
39-
client.getVisibleRooms = jest.fn().mockReturnValue(rooms);
65+
mockClient.getVisibleRooms.mockReturnValue(rooms);
66+
mockClient.getRoom.mockImplementation(roomId => rooms.find(room => room.roomId === roomId));
4067

4168
let wrapper;
4269
await act(async () => {
4370
wrapper = mount(
4471
<ForwardDialog
45-
matrixClient={client}
72+
matrixClient={mockClient}
4673
event={message}
4774
permalinkCreator={new RoomPermalinkCreator(undefined, sourceRoom)}
4875
onFinished={jest.fn()}
@@ -57,9 +84,14 @@ describe("ForwardDialog", () => {
5784
};
5885

5986
beforeEach(() => {
60-
TestUtils.stubClient();
6187
DMRoomMap.makeShared();
62-
MatrixClientPeg.get().getUserId = jest.fn().mockReturnValue("@bob:example.org");
88+
jest.clearAllMocks();
89+
mockClient.getUserId.mockReturnValue("@bob:example.org");
90+
mockClient.sendEvent.mockReset();
91+
});
92+
93+
afterAll(() => {
94+
jest.spyOn(MatrixClientPeg, 'get').mockRestore();
6395
});
6496

6597
it("shows a preview with us as the sender", async () => {
@@ -91,7 +123,7 @@ describe("ForwardDialog", () => {
91123
// Make sendEvent require manual resolution so we can see the sending state
92124
let finishSend;
93125
let cancelSend;
94-
MatrixClientPeg.get().sendEvent = jest.fn(() => new Promise((resolve, reject) => {
126+
mockClient.sendEvent.mockImplementation(() => new Promise((resolve, reject) => {
95127
finishSend = resolve;
96128
cancelSend = reject;
97129
}));
@@ -135,7 +167,7 @@ describe("ForwardDialog", () => {
135167
});
136168

137169
it("can render replies", async () => {
138-
const replyMessage = TestUtils.mkEvent({
170+
const replyMessage = mkEvent({
139171
type: "m.room.message",
140172
room: "!111111111111111111:example.org",
141173
user: "@alice:example.org",
@@ -156,9 +188,9 @@ describe("ForwardDialog", () => {
156188
});
157189

158190
it("disables buttons for rooms without send permissions", async () => {
159-
const readOnlyRoom = TestUtils.mkStubRoom("a", "a");
191+
const readOnlyRoom = mkStubRoom("a", "a", mockClient);
160192
readOnlyRoom.maySendMessage = jest.fn().mockReturnValue(false);
161-
const rooms = [readOnlyRoom, TestUtils.mkStubRoom("b", "b")];
193+
const rooms = [readOnlyRoom, mkStubRoom("b", "b", mockClient)];
162194

163195
const wrapper = await mountForwardDialog(undefined, rooms);
164196

0 commit comments

Comments
 (0)