Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Sep 23, 2024
2 parents 82a3971 + a8efd93 commit c314666
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 18 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Here you can see an example card for failed test results:

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.

As the incoming webhook functionality will stop working on October 1, 2024, it is recommended to use the Power Automate connector functionality.
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.

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

> [!WARNING]
> When using the PowerAutomate template, a template footer will automatically be included like: `<name> used a Workflow template to send this card. Get template`.
> You can remove this footer by creating a copy of the flow, and use the new one instead.
> 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/).
### Microsoft Teams incoming webhook (retiring October 1, 2024)

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).
Expand Down Expand Up @@ -97,6 +102,7 @@ The reporter supports the following configuration options:
| `enableEmoji` | Show an emoji based on the test status | `boolean` | `false` | `false` |
| `quiet` | Do not show any output in the console | `boolean` | `false` | `false` |
| `debug` | Show debug information | `boolean` | `false` | `false` |
| `shouldRun` | Conditional reporting | ` Suite => boolean` | `false` | `true` |

### Mention users

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

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.

### Conditional reporting (shouldRun)

Example (report only from jenkins runs - project name set as 'dev__jenkins'):
```javascript
shouldRun: (suite) => {
if (suite.suites[0].project()?.name.includes('_jenkins')) return true

return false
}
```
#### Github
```javascript
Expand Down
18 changes: 2 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "playwright-msteams-reporter",
"version": "0.0.10",
"version": "0.0.11",
"description": "Microsoft Teams reporter for Playwright which allows you to send notifications about the status of your E2E tests.",
"main": "dist/index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const config: PlaywrightTestConfig<{}, {}> = {
mentionOnFailureText: "",
enableEmoji: false,
debug: true,
shouldRun: () => true,
},
],
],
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface MsTeamsReporterOptions {
enableEmoji?: boolean;
quiet?: boolean;
debug?: boolean;
shouldRun?: ((suite: Suite) => boolean);
}

export default class MsTeamsReporter implements Reporter {
Expand All @@ -41,6 +42,7 @@ export default class MsTeamsReporter implements Reporter {
enableEmoji: false,
quiet: false,
debug: false,
shouldRun: () => true
};

this.options = { ...defaultOptions, ...options };
Expand Down
18 changes: 18 additions & 0 deletions src/processResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const DEFAULT_OPTIONS: MsTeamsReporterOptions = {
mentionOnFailureText: "{mentions} please validate the test results.",
quiet: false,
debug: false,
shouldRun: () => true
};

const SUITE_MOCK_PASSED = {
Expand Down Expand Up @@ -123,6 +124,23 @@ describe("processResults", () => {
consoleLogSpy.mockReset();
});

it("should return early if shouldRun is false", async () => {
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation();

const fetchMock = jest.fn();
global.fetch = fetchMock;
const options = {
...DEFAULT_OPTIONS,
webhookUrl: undefined,
shouldRun: () => false
};
await processResults(undefined, options);
expect(fetchMock).not.toHaveBeenCalled();
expect(consoleLogSpy).not.toHaveBeenCalled();

consoleLogSpy.mockReset();
});

it("should send a message successfully", async () => {
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation();
const fetchMock = jest
Expand Down
2 changes: 2 additions & 0 deletions src/processResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const processResults = async (
return;
}

if (options.shouldRun && !options?.shouldRun(suite)) return

// Clone the base adaptive card and table
const adaptiveCard = structuredClone(BaseAdaptiveCard);
const table = structuredClone(BaseTable);
Expand Down

0 comments on commit c314666

Please sign in to comment.