Skip to content

Commit

Permalink
Merge pull request #9979 from linode/release-v1.108.0
Browse files Browse the repository at this point in the history
Release v1.108.0 - release -> `staging`
  • Loading branch information
jdamore-linode authored Dec 11, 2023
2 parents 41356e5 + 8332304 commit 3a2ebd2
Show file tree
Hide file tree
Showing 752 changed files with 15,836 additions and 10,936 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This directory contains the GitHub Actions workflows that power continuous integration and end-to-end testing for Linode Cloud Manager.

## Continuous Integration
The `ci` workflow handles testing, building, and publishing of packages in this repository. Tests are run via [Jest](https://jestjs.io/) for `api-v4` and `manager`.
The `ci` workflow handles testing, building, and publishing of packages in this repository. Tests are run using [Vitest](https://vitest.dev/) for `api-v4` and `manager`.

If the continuous integration workflow was triggered via a push to the `master` branch, the built packages are published:

Expand Down Expand Up @@ -54,4 +54,4 @@ Cypress tests are parallelized across four containers, and tests are automatical
* [_Introduction to Cypress_](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress) (`docs.cypress.io`)
* [Cypress: _GitHub Actions_](https://docs.cypress.io/guides/continuous-integration/github-actions#Cypress-GitHub-Action) (`docs.cypress.io`)
* [Cypress: _Parallelization_](https://docs.cypress.io/guides/guides/parallelization) (`docs.cypress.io`)
* [Jest: _Getting Started_](https://jestjs.io/docs/getting-started) (`jestjs.io`)
* [Vitest: _Getting Started_](https://vitest.dev/guide/) (`vitest.dev`)
94 changes: 94 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Code Coverage

on: [pull_request]

jobs:
base_branch:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.base_ref }} # The base branch of the PR (develop)

- name: Use Node.js v18.14.0
uses: actions/setup-node@v3
with:
node-version: "18.14"

- uses: actions/cache@v3
with:
path: |
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}

- name: Install Dependencies
run: yarn --frozen-lockfile

- name: Run build
run: yarn build

- name: Run Base Branch Coverage
run: yarn coverage:summary

- name: Write Base Coverage to an Artifact
run: |
coverage_json=$(cat ./packages/manager/coverage/coverage-summary.json)
pct=$(echo "$coverage_json" | jq -r '.total.statements.pct')
echo "$pct" > ref_code_coverage.txt
- name: Upload Base Coverage Artifact
uses: actions/upload-artifact@v3
with:
name: ref_code_coverage
path: ref_code_coverage.txt

current_branch:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
needs: base_branch

steps:
- uses: actions/checkout@v3

- name: Use Node.js v18.14.0
uses: actions/setup-node@v3
with:
node-version: "18.14"

- uses: actions/cache@v3
with:
path: |
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}

- name: Install Dependencies
run: yarn --frozen-lockfile

- name: Run Build
run: yarn build

- name: Run Current Branch Coverage
run: yarn coverage:summary

- name: Write PR Number to an Artifact
run: |
echo "${{ github.event.number }}" > pr_number.txt
- name: Write Current Coverage to an Artifact
run: |
coverage_json=$(cat ./packages/manager/coverage/coverage-summary.json)
pct=$(echo "$coverage_json" | jq -r '.total.statements.pct')
echo "$pct" > current_code_coverage.txt
- name: Upload PR Number Artifact
uses: actions/upload-artifact@v3
with:
name: pr_number
path: pr_number.txt

- name: Upload Current Coverage Artifact
uses: actions/upload-artifact@v3
with:
name: current_code_coverage
path: current_code_coverage.txt
52 changes: 52 additions & 0 deletions .github/workflows/coverage_badge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Coverage Badge

on:
push:
branches:
- master

jobs:
generate-coverage-badge:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Use Node.js v18.14.0
uses: actions/setup-node@v3
with:
node-version: "18.14"

- uses: actions/cache@v3
with:
path: |
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}

- name: Install Dependencies
run: yarn --frozen-lockfile

- name: Run Build
run: yarn build

- name: Run Base Branch Coverage
run: yarn coverage:summary

- name: Generate Coverage Badge
uses: jaywcjlove/coverage-badges-cli@7f0781807ef3e7aba97a145beca881d36451b7b7 # v1.1.1
with:
label: '@linode/manager coverage'
source: ./packages/manager/coverage/coverage-summary.json
output: ./packages/manager/coverage/badges.svg

- uses: jakejarvis/s3-sync-action@7ed8b112447abb09f1da74f3466e4194fc7a6311 # v0.5.1
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_ENDPOINT: https://us-east-1.linodeobjects.com
AWS_S3_BUCKET: ${{ secrets.COVERAGE_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.COVERAGE_BUCKET_ACCESS }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.COVERAGE_BUCKET_SECRET }}
AWS_REGION: us-east-1
SOURCE_DIR: ./packages/manager/coverage
67 changes: 67 additions & 0 deletions .github/workflows/coverage_comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Coverage Comment

on:
workflow_run:
workflows: ["Code Coverage"]
types:
- completed

permissions:
pull-requests: write

jobs:
comment:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Use Node.js v18.14.0
uses: actions/setup-node@v3
with:
node-version: "18.14"

- name: Download PR Number Artifact
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e #v2.28.0
with:
workflow: "coverage.yml"
run_id: ${{ github.event.workflow_run.id }}
name: pr_number

- name: Download Base Coverage Artifact
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e #v2.28.0
with:
workflow: "coverage.yml"
run_id: ${{ github.event.workflow_run.id }}
name: ref_code_coverage

- name: Download Current Coverage Artifact
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e #v2.28.0
with:
workflow: "coverage.yml"
run_id: ${{ github.event.workflow_run.id }}
name: current_code_coverage

- name: Set PR Number Environment Variables
run: |
echo "PR_NUMBER=$(cat pr_number.txt)" >> $GITHUB_ENV
- name: Generate Coverage Comment
run: |
base_coverage=$(cat ref_code_coverage.txt)
current_coverage=$(cat current_code_coverage.txt)
if (( $(echo "$current_coverage < $base_coverage" | bc -l) )); then
icon="❌" # Error icon
else
icon="✅" # Check mark icon
fi
comment_message="**Coverage Report:** $icon<br>Base Coverage: $base_coverage%<br>Current Coverage: $current_coverage%"
echo "Coverage: $comment_message"
echo "$comment_message" > updated_comment.txt
- name: Post Comment
uses: mshick/add-pr-comment@7c0890544fb33b0bdd2e59467fbacb62e028a096 #v2.8.1
with:
issue: ${{ env.PR_NUMBER }}
message-path: updated_comment.txt
2 changes: 2 additions & 0 deletions .github/workflows/e2e_schedule_and_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
matrix:
user: ["USER_1", "USER_2", "USER_3", "USER_4"]
steps:
- name: install command line utilities
run: sudo apt-get install -y expect
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Default code owners
* @linode/frontend

# Frontend SDET code owners for Cypress tests
/packages/manager/cypress/ @linode/frontend-sdet
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
Akamai Connected Cloud Manager
</h2>

<p align="center">
<img alt="Linode Manager Code Coverage" src="https://cloud-manager-coverage.us-east-1.linodeobjects.com/badges.svg?v=1" />
</p>

<p align="center">
<a href="https://github.com/linode/manager/actions/workflows/ci.yml">
<img src="https://github.com/linode/manager/actions/workflows/ci.yml/badge.svg?branch=develop" alt="CI Build Stats on develop" />
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ x-e2e-runners:
condition: service_healthy
env_file: ./packages/manager/.env
volumes: *default-volumes
entrypoint: ['yarn', 'cy:ci']
entrypoint: ['yarn', 'cy:e2e']

services:
# Serves a local instance of Cloud Manager for Cypress to use for its tests.
Expand Down
29 changes: 16 additions & 13 deletions docs/development-guide/08-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Unit Tests

The unit tests for Cloud Manager are written in Typescript using the [Jest](https://facebook.github.io/jest/) testing framework. Unit tests end with either `.test.tsx` or `.test.ts` file extensions and can be found throughout the codebase.
The unit tests for Cloud Manager are written in Typescript using the [Vitest](https://vitest.dev/) testing framework. Unit tests end with either `.test.tsx` or `.test.ts` file extensions and can be found throughout the codebase.

To run tests, first build the **api-v4** package:

Expand All @@ -29,7 +29,7 @@ yarn test myFile.test.tsx
yarn test src/some-folder
```

Jest has built-in pattern matching, so you can also do things like run all tests whose filename contains "Linode" with:
Vitest has built-in pattern matching, so you can also do things like run all tests whose filename contains "Linode" with:

```
yarn test linode
Expand All @@ -45,7 +45,7 @@ Test execution will stop at the debugger statement, and you will be able to use

### React Testing Library

We have some older tests that still use the Enzyme framework, but for new tests we generally use [React Testing Library](https://testing-library.com/docs/react-testing-library/intro). This library provides a set of tools to render React components from within the Jest environment. The library's philosophy is that components should be tested as closely as possible to how they are used.
We have some older tests that still use the Enzyme framework, but for new tests we generally use [React Testing Library](https://testing-library.com/docs/react-testing-library/intro). This library provides a set of tools to render React components from within the Vitest environment. The library's philosophy is that components should be tested as closely as possible to how they are used.

A simple test using this library will look something like this:

Expand All @@ -68,7 +68,7 @@ import { fireEvent } from "@testing-library/react";
import { renderWithTheme } from "src/utilities/testHelpers";
import Component from "./wherever";

const props = { onClick: jest.fn() };
const props = { onClick: vi.fn() };

describe("My component", () => {
it("should have some text", () => {
Expand All @@ -92,19 +92,23 @@ await wait(() => fireEvent.click(getByText('Delete')));

### Mocking

Jest has substantial built-in mocking capabilities, and we use many of the available patterns. We generally use them to avoid making network requests in unit tests, but there are some other cases (mentioned below).
Vitest has substantial built-in mocking capabilities, and we use many of the available patterns. We generally use them to avoid making network requests in unit tests, but there are some other cases (mentioned below).

In general, components that make network requests should take any request handlers as props. Then testing is as simple as passing `someProp: jest.fn()` and making assertions normally. When that isn't possible, you can do the following:
In general, components that make network requests should take any request handlers as props. Then testing is as simple as passing `someProp: vi.fn()` and making assertions normally. When that isn't possible, you can do the following:

```js
jest.mock("@linode/api-v4/lib/kubernetes", () => ({
getKubeConfig: () => jest.fn(),
}));
vi.mock('@linode/api-v4/lib/kubernetes', async () => {
const actual = await vi.importActual<any>('@linode/api-v4/lib/kubernetes');
return {
...actual,
getKubeConfig: () => vi.fn(),
};
});
```

Some components, such as our ActionMenu, don't lend themselves well to unit testing (they often have complex DOM structures from MUI and it's hard to target). We have mocks for most of these components in a `__mocks__` directory adjacent to their respective components. To make use of these, just tell Jest to use the mock:
Some components, such as our ActionMenu, don't lend themselves well to unit testing (they often have complex DOM structures from MUI and it's hard to target). We have mocks for most of these components in a `__mocks__` directory adjacent to their respective components. To make use of these, just tell Vitest to use the mock:

jest.mock('src/components/ActionMenu/ActionMenu');
vi.mock('src/components/ActionMenu/ActionMenu');

Any `<ActionMenu>`s rendered by the test will be simplified versions that are easier to work with.

Expand Down Expand Up @@ -140,8 +144,7 @@ const { getByTestId } = renderWithTheme(<MyComponent />, {

We support mocking API requests both in test suites and the browser using the [msw](https://www.npmjs.com/package/msw) library. See [07-mocking-data](07-mocking-data.md) for more details.

These mocks are automatically enabled for tests (using `beforeAll` and `afterAll` in src/setupTests.ts, which is run when setting up
the Jest environment).
These mocks are automatically enabled for tests (using `beforeAll` and `afterAll` in src/setupTests.ts, which is run when setting up the Vitest environment).

## End-to-End tests

Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@
"start:manager": "yarn workspace linode-manager start",
"start:manager:ci": "yarn workspace linode-manager start:ci",
"clean": "rm -rf node_modules && rm -rf packages/@linode/api-v4/node_modules && rm -rf packages/manager/node_modules && rm -rf packages/@linode/validation/node_modules",
"test": "yarn workspace linode-manager test --maxWorkers=4",
"test": "yarn workspace linode-manager test",
"package-versions": "node ./scripts/package-versions/index.js",
"storybook": "yarn workspace linode-manager storybook",
"cy:run": "yarn workspace linode-manager cy:run",
"cy:e2e": "yarn workspace linode-manager cy:e2e",
"cy:ci": "yarn cypress install && yarn cy:e2e",
"cy:ci": "yarn cy:e2e",
"cy:debug": "yarn workspace linode-manager cy:debug",
"cy:rec-snap": "yarn workspace linode-manager cy:rec-snap",
"changeset": "node scripts/changelog/changeset.mjs",
"generate-changelogs": "node scripts/changelog/generate-changelogs.mjs"
"generate-changelogs": "node scripts/changelog/generate-changelogs.mjs",
"coverage": "yarn workspace linode-manager coverage",
"coverage:summary": "yarn workspace linode-manager coverage:summary"
},
"resolutions": {
"minimist": "^1.2.3",
Expand All @@ -53,7 +55,6 @@
"lodash": "^4.17.21",
"glob-parent": "^5.1.2",
"hosted-git-info": "^5.0.0",
"minimatch": "^9.0.2",
"@types/react": "^17",
"yaml": "^2.3.0",
"word-wrap": "^1.2.4",
Expand All @@ -70,4 +71,4 @@
"node": "18.14.1"
},
"dependencies": {}
}
}
Loading

0 comments on commit 3a2ebd2

Please sign in to comment.