Skip to content

Commit

Permalink
Merge pull request #15 from siteriaitaliana/main
Browse files Browse the repository at this point in the history
Added extra param to control when to report based on suite values
  • Loading branch information
estruyf authored Sep 23, 2024
2 parents 4da46b7 + de96706 commit a8efd93
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,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 @@ -133,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 a8efd93

Please sign in to comment.