Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding - Test coverage jest #2171

Merged
merged 68 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
f915142
Adding jest package
amankumarrr Feb 20, 2024
3f08b40
Adding jest-playwright library
amankumarrr Feb 20, 2024
6a0b13d
Adding single test for the code coverage
amankumarrr Feb 20, 2024
cae281b
Adding pipeline for the coverage
amankumarrr Feb 20, 2024
6d63c27
changing the case
amankumarrr Feb 20, 2024
4327382
Adding read write permission
amankumarrr Feb 20, 2024
9bde6c4
Changing the extension of the file
amankumarrr Feb 20, 2024
f0c4dec
changing the params
amankumarrr Feb 20, 2024
2e63fee
Adding working directory and threshold coverage
amankumarrr Feb 20, 2024
dbe4271
Changing threshold and adding rights for writing
amankumarrr Feb 20, 2024
09f7d2f
changing the path
amankumarrr Feb 20, 2024
88308a5
adding path as a string
amankumarrr Feb 20, 2024
02f800b
Adding a unit test
amankumarrr Feb 21, 2024
76abce7
Added unit test for Date.ts
amankumarrr Feb 21, 2024
d41f0c7
Rearranging the test
amankumarrr Feb 21, 2024
6916966
Adding test for the different year
amankumarrr Feb 21, 2024
c42c975
Removing code coverage from pipeline to run the unit tests
amankumarrr Feb 21, 2024
9a73b8b
skipping the step to compare with different branches
amankumarrr Feb 21, 2024
1f61290
Adding coverage file
amankumarrr Feb 21, 2024
d7c8928
removing base coverage file
amankumarrr Feb 21, 2024
e9e7c3e
Adding script to generate the scrip
amankumarrr Feb 21, 2024
174f11d
Changing the report type
amankumarrr Feb 21, 2024
5ab137a
Adding report.json
amankumarrr Feb 21, 2024
c0054de
Adding a step to install PNPM
amankumarrr Feb 21, 2024
5ed530e
Adding param to skip none
amankumarrr Feb 21, 2024
cadd369
Adding base file to opt out comparision
amankumarrr Feb 21, 2024
1a1a0db
Removing working directory to default
amankumarrr Feb 21, 2024
ec25ac0
Removing unused start from the test file
amankumarrr Feb 21, 2024
a7e269d
Adding fake test to fail
amankumarrr Feb 21, 2024
3846c96
Removing failed test from expect value
amankumarrr Feb 21, 2024
3e88a6b
Adding without the test report
amankumarrr Feb 21, 2024
59f1168
Running PR push to run the tests
amankumarrr Feb 21, 2024
11ed822
Installing dependencies step
amankumarrr Feb 21, 2024
cbc4810
Disabling the coverage threshold
amankumarrr Feb 21, 2024
b139705
Removing extra permissions
amankumarrr Feb 21, 2024
3c3648d
Adding base report and coverage
amankumarrr Feb 21, 2024
bd20995
Deleting coverage pipeline
amankumarrr Feb 21, 2024
720f061
Adding checkout for the generate report
amankumarrr Feb 21, 2024
2c0ba70
adding separate folder for pr reports
amankumarrr Feb 21, 2024
5dfcc5d
adding reporting step into the same job
amankumarrr Feb 21, 2024
cbd28a0
Adding step to not install dependencies and a checks API for write pe…
amankumarrr Feb 22, 2024
d818ae8
Removoing checks api rights
amankumarrr Feb 22, 2024
f1d85f8
Improving casing for the steps
amankumarrr Feb 22, 2024
e5f39aa
Adding tests for prod
amankumarrr Feb 22, 2024
d780277
Clean up for unused code coverage
amankumarrr Feb 22, 2024
c124dc8
Merge branch 'main' into test-coverage-jest
amankumarrr Feb 22, 2024
95738ba
Adding annotation for the Action Run
amankumarrr Feb 23, 2024
3c1ab1f
Adding missing quotation sign
amankumarrr Feb 23, 2024
b244769
Adding EOF for the mdx file
amankumarrr Feb 23, 2024
8f7c53f
Adding test summary for the github action
amankumarrr Feb 23, 2024
03653d1
Wrapping output into a string quote
amankumarrr Feb 23, 2024
f21326c
Adding the report content with the dollar sign
amankumarrr Feb 23, 2024
7d16d29
changing the variable wrapping
amankumarrr Feb 23, 2024
04227e0
Adding test action to run the summary
amankumarrr Feb 23, 2024
7245033
Adding new job to print sumarry
amankumarrr Feb 23, 2024
8fce29b
Adding summary job at the end
amankumarrr Feb 23, 2024
d419ada
Adding new flow to generate summary
amankumarrr Feb 23, 2024
7697b63
Removing the github call to external action
amankumarrr Feb 23, 2024
89f3130
Adding new job to write summary
amankumarrr Feb 23, 2024
809fa6d
Using third Party action for summary
amankumarrr Feb 23, 2024
ab5853d
Wrapping the input summary
amankumarrr Feb 23, 2024
39b58c7
Using annotation to show the report
amankumarrr Feb 23, 2024
e42bbb3
Adding PS command to add summary
amankumarrr Feb 23, 2024
bc73dc1
wrapping the output as it has double quotes with it
amankumarrr Feb 23, 2024
05e3c8c
Adding variable to incorporate all the changes
amankumarrr Feb 23, 2024
7b04ffa
Adding code coverage for the main build
amankumarrr Feb 23, 2024
cebd349
Fixing the typo
amankumarrr Feb 23, 2024
7bdcc8f
Adding meaningful name for the step
amankumarrr Feb 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/main-build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ permissions:
contents: read

jobs:
run-tests-and-coverage:
name: Run tests & coverage
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8
- name: Install dependencies
run: pnpm install

- name: Run Tests & Coverage
run: pnpm test-and-coverage --outputFile=base-coverage/report.json
amankumarrr marked this conversation as resolved.
Show resolved Hide resolved

build:
name: Build and upload artifacts
uses: ./.github/workflows/template-build.yml
Expand Down
28 changes: 27 additions & 1 deletion .github/workflows/pr-push-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ defaults:
shell: pwsh

jobs:
run-tests-and-coverage:
name: Run tests & coverage
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8
- name: Install dependencies
run: pnpm install

- name: Run Tests & Coverage
run: pnpm test-and-coverage --outputFile=pr-coverage/report.json

- name: Upload Coverage Report to PR
uses: ArtiomTr/jest-coverage-report-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
coverage-file: ./pr-coverage/report.json
base-coverage-file: ./base-coverage/report.json
skip-step: all
annotations: none

build:
name: Build and upload artifacts
uses: ./.github/workflows/template-build.yml
Expand Down Expand Up @@ -67,7 +93,7 @@ jobs:
repo-token-user-login: "github-actions[bot]"
allow-repeats: true

test:
ui-test:
name: Run Playwright Tests
needs: pr-deploy
uses: ./.github/workflows/template-ui-tests.yml
Expand Down
111 changes: 111 additions & 0 deletions __tests__/helpers/dates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import {
formatEventDate,
formatEventLongDate,
formatRelativeEventDate,
} from "../../helpers/dates";

describe("formatEventDate", () => {
it("Single Day Event - Date format", () => {
const startDate = new Date(2024, 1, 1); // February 1, 2024
const endDate = new Date(2024, 1, 1); // February 1, 2024
const result = formatEventDate(startDate, endDate);
expect(result).toBe("Feb 1");
});

it("Single Day Event - Different year - Date format", () => {
const startDate = new Date(2025, 1, 1); // February 1, 2024
const endDate = new Date(2025, 1, 1); // February 1, 2024
const result = formatEventDate(startDate, endDate);
expect(result).toBe("Feb 1 2025");
});

it("Mutiple Days Event - Date format", () => {
const startDate = new Date(2024, 1, 1); // February 1, 2024
const endDate = new Date(2024, 1, 2); // February 2, 2024
const result = formatEventDate(startDate, endDate);
expect(result).toBe("Feb 1 - Feb 2");
});

it("No date provided - Date format", () => {
const result = formatEventDate(null, null);
expect(result).toBe("");
});
});

describe("formatEventLongDate", () => {
it("Single Day Event - Date format", () => {
const startDate = new Date(2024, 1, 1); // February 1, 2024
const endDate = new Date(2024, 1, 1); // February 1, 2024
const result = formatEventLongDate(startDate, endDate);
expect(result).toBe("Thursday, February 1, 2024 12:00 AM - 12:00 AM");
});

it("Mutiple Days Event - Date format", () => {
const startDate = new Date(2024, 1, 1); // February 1, 2024
const endDate = new Date(2024, 1, 2); // February 2, 2024
const result = formatEventLongDate(startDate, endDate);
expect(result).toBe(
"Thursday, February 1, 2024 12:00 AM - Friday, February 2, 2024 12:00 AM"
);
});

it("No date provided - Date format", () => {
const result = formatEventLongDate(null, null);
expect(result).toBe("");
});
});

describe("formatRelativeEventDate", () => {
it("2 Days ago - Date format", () => {
const startDate = new Date();
startDate.setDate(startDate.getDate() - 2); // subtract 2 days from the current date
const endDate = new Date();
endDate.setDate(endDate.getDate() - 2); // subtract 2 days from the current date
const result = formatRelativeEventDate(startDate, endDate);
expect(result).toBe("2 days ago");
});

it("1 Day ago - Date format", () => {
const startDate = new Date();
startDate.setDate(startDate.getDate() - 1); // subtract 1 days from the current date
const endDate = new Date();
endDate.setDate(endDate.getDate() - 1); // subtract 1 day from the current date
const result = formatRelativeEventDate(startDate, endDate);
expect(result).toBe("1 day ago");
});

it("Running now - Date format", () => {
const startDate = new Date(); // Today's Date
startDate.setHours(startDate.getHours() - 1); // subtract 1 hours from the current time
const endDate = new Date();
endDate.setHours(endDate.getHours() + 1); // add 1 hours to the current time

const result = formatRelativeEventDate(startDate, endDate);
expect(result).toBe("now running");
});

it("Today - Date format", () => {
const startDate = new Date(); // Today's date
const endDate = new Date(); // Today's date
const result = formatRelativeEventDate(startDate, endDate);
expect(result).toBe("today");
});

it("1 day to go - Date format", () => {
const startDate = new Date(); // Today's date
const endDate = new Date(); // Today's date
startDate.setDate(startDate.getDate() + 1); // add 1 day to the current date
endDate.setDate(endDate.getDate() + 1); // add 1 days to the current date
const result = formatRelativeEventDate(startDate, endDate);
expect(result).toBe("1 day to go");
});

it("2 days to go - Date format", () => {
const startDate = new Date(); // Today's date
const endDate = new Date(); // Today's date
startDate.setDate(startDate.getDate() + 2); // add 2 days to the current date
endDate.setDate(endDate.getDate() + 2); // add 2 days to the current date
const result = formatRelativeEventDate(startDate, endDate);
expect(result).toBe("2 days to go");
});
});
1 change: 1 addition & 0 deletions base-coverage/report.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions coverage-report.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions helpers/dates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import dayjs from "dayjs";
import isBetween from "dayjs/plugin/isBetween";
dayjs.extend(isBetween);

export const EventStatus = {
TODAY: "today",
Expand Down
Loading
Loading