Skip to content

Commit c314666

Browse files
committed
Merge branch 'main' into dev
2 parents 82a3971 + a8efd93 commit c314666

File tree

7 files changed

+44
-18
lines changed

7 files changed

+44
-18
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Here you can see an example card for failed test results:
1818

1919
To use this reporter, you must have a Microsoft Teams webhook URL. You can create a webhook URL using the Microsoft Teams Power Automate connector or the Microsoft Teams incoming webhook functionality.
2020

21-
As the incoming webhook functionality will stop working on October 1, 2024, it is recommended to use the Power Automate connector functionality.
21+
As the incoming webhook functionality will stop working on October 1, 2024 (extended to December 2025), it is recommended to use the Power Automate connector functionality.
2222

2323
> **Important**: You need to copy the `webhook URL` from the configuration, as you will need it to configure the reporter.
2424
@@ -40,6 +40,11 @@ To create a Power Automate webhook for Microsoft Teams, you can follow these ste
4040
- Click on the **Save** button
4141
- Click on **When a Teams webhook request is received** and copy the **HTTP URL**
4242

43+
> [!WARNING]
44+
> When using the PowerAutomate template, a template footer will automatically be included like: `<name> used a Workflow template to send this card. Get template`.
45+
> You can remove this footer by creating a copy of the flow, and use the new one instead.
46+
> You can find more information about this procedure in the following blog post: [How to remove "<Name> used a Workflow template to send this card. Get template"](https://docs.hetrixtools.com/microsoft-teams-how-to-remove-name-used-a-workflow-template-to-send-this-card-get-template/).
47+
4348
### Microsoft Teams incoming webhook (retiring October 1, 2024)
4449

4550
To use this reporter, you need to create an incoming webhook for your Microsoft Teams channel. You can find more information on how to do this in the [Microsoft documentation](https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=newteams%2Cdotnet#create-an-incoming-webhook).
@@ -97,6 +102,7 @@ The reporter supports the following configuration options:
97102
| `enableEmoji` | Show an emoji based on the test status | `boolean` | `false` | `false` |
98103
| `quiet` | Do not show any output in the console | `boolean` | `false` | `false` |
99104
| `debug` | Show debug information | `boolean` | `false` | `false` |
105+
| `shouldRun` | Conditional reporting | ` Suite => boolean` | `false` | `true` |
100106

101107
### Mention users
102108

@@ -128,6 +134,17 @@ The format can be either the full name and email (`"Full name <email>"`) or just
128134

129135
With the `linkToResultsUrl` option, you can provide a link to the test results. For example, you can view the test results on your CI/CD platform.
130136

137+
### Conditional reporting (shouldRun)
138+
139+
Example (report only from jenkins runs - project name set as 'dev__jenkins'):
140+
```javascript
141+
shouldRun: (suite) => {
142+
if (suite.suites[0].project()?.name.includes('_jenkins')) return true
143+
144+
return false
145+
}
146+
```
147+
131148
#### Github
132149
133150
```javascript

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "playwright-msteams-reporter",
3-
"version": "0.0.10",
3+
"version": "0.0.11",
44
"description": "Microsoft Teams reporter for Playwright which allows you to send notifications about the status of your E2E tests.",
55
"main": "dist/index.js",
66
"scripts": {

playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const config: PlaywrightTestConfig<{}, {}> = {
3030
mentionOnFailureText: "",
3131
enableEmoji: false,
3232
debug: true,
33+
shouldRun: () => true,
3334
},
3435
],
3536
],

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface MsTeamsReporterOptions {
2323
enableEmoji?: boolean;
2424
quiet?: boolean;
2525
debug?: boolean;
26+
shouldRun?: ((suite: Suite) => boolean);
2627
}
2728

2829
export default class MsTeamsReporter implements Reporter {
@@ -41,6 +42,7 @@ export default class MsTeamsReporter implements Reporter {
4142
enableEmoji: false,
4243
quiet: false,
4344
debug: false,
45+
shouldRun: () => true
4446
};
4547

4648
this.options = { ...defaultOptions, ...options };

src/processResults.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const DEFAULT_OPTIONS: MsTeamsReporterOptions = {
1515
mentionOnFailureText: "{mentions} please validate the test results.",
1616
quiet: false,
1717
debug: false,
18+
shouldRun: () => true
1819
};
1920

2021
const SUITE_MOCK_PASSED = {
@@ -123,6 +124,23 @@ describe("processResults", () => {
123124
consoleLogSpy.mockReset();
124125
});
125126

127+
it("should return early if shouldRun is false", async () => {
128+
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation();
129+
130+
const fetchMock = jest.fn();
131+
global.fetch = fetchMock;
132+
const options = {
133+
...DEFAULT_OPTIONS,
134+
webhookUrl: undefined,
135+
shouldRun: () => false
136+
};
137+
await processResults(undefined, options);
138+
expect(fetchMock).not.toHaveBeenCalled();
139+
expect(consoleLogSpy).not.toHaveBeenCalled();
140+
141+
consoleLogSpy.mockReset();
142+
});
143+
126144
it("should send a message successfully", async () => {
127145
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation();
128146
const fetchMock = jest

src/processResults.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const processResults = async (
3030
return;
3131
}
3232

33+
if (options.shouldRun && !options?.shouldRun(suite)) return
34+
3335
// Clone the base adaptive card and table
3436
const adaptiveCard = structuredClone(BaseAdaptiveCard);
3537
const table = structuredClone(BaseTable);

0 commit comments

Comments
 (0)