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

feat(chore): add test execution #38

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
19 changes: 19 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test Components

on:
pull_request_target:
types: [opened, reopened]

jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false # <--- this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does that comment mean 🤔 ?

Copy link
Contributor Author

@mnlfischer mnlfischer Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh I copied it from all other actions. I will remove it for all of them 👍🏻

- uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
- run: npm ci
- run: npm run test
3 changes: 0 additions & 3 deletions jest.config.js

This file was deleted.

8,419 changes: 3,105 additions & 5,314 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"storybook": "storybook dev -p 6006",
"clean": "rimraf ./dist",
"type-check": "tsc --project tsconfig.json",
"test": "jest",
"test": "vitest",
"test:coverage": "vitest run --coverage",
"lint": "eslint src --ext .ts,.tsx",
"lint:write": "eslint src --ext .ts,.tsx --fix",
"format:check": "prettier --check src",
Expand Down Expand Up @@ -68,13 +69,14 @@
"@storybook/react-vite": "^7.1.1",
"@storybook/testing-library": "^0.2.0",
"@svgr/cli": "8.0.1",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^14.0.0",
"@types/jest": "^29.5.2",
"@types/react": "^18.2.14",
"@typescript-eslint/eslint-plugin": "5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"@vitejs/plugin-react": "^4.0.4",
"@vitest/coverage-v8": "^0.34.4",
"autoprefixer": "^10.4.14",
"babel-jest": "^29.6.1",
"babel-loader": "^9.1.2",
"eslint": "8.44.0",
"eslint-config-airbnb": "19.0.4",
Expand All @@ -87,8 +89,7 @@
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-storybook": "0.6.13",
"eslint-plugin-tsdoc": "0.2.17",
"jest": "^29.6.1",
"jest-environment-jsdom": "^29.6.1",
"jsdom": "^22.1.0",
"prettier": "^3.0.0",
"prettier-plugin-tailwindcss": "0.3.0",
"prop-types": "^15.8.1",
Expand All @@ -105,7 +106,8 @@
"tailwind-merge": "^1.13.2",
"tailwindcss": "^3.3.3",
"typescript": "^5.1.6",
"vite": "^4.4.1"
"vite": "^4.4.1",
"vitest": "^0.34.4"
},
"peerDependencies": {
"react": ">=17.0.1",
Expand All @@ -114,9 +116,6 @@
"overrides": {
"optionator": {
"[email protected]": "1.2.5"
},
"jsdom@20": {
"[email protected]": "4.1.3"
}
}
}
21 changes: 21 additions & 0 deletions src/components/alert/alert.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, it } from "vitest";
import { getByText, render } from "@testing-library/react";
import React from "react";
import { Alert } from "./alert";

describe("Alert", () => {
it("renders an alert with a title and children", () => {
// ARRANGE
const { getByRole } = render(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using screen.getByRole is recommended by the creators, although it doesn't make a substantial difference 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change it to match the docs! Thanks for bringing that up. I run through different examples to get the additional "toBeInTheDocument()" functions to work and I guess I messed it up.

<Alert intent="info" title="Hello">
World
</Alert>
);

// ASSERT
const alert = getByRole("alert");
expect(alert).toBeInTheDocument();
expect(getByText(alert, "Hello")).toBeInTheDocument();
expect(getByText(alert, "World")).toBeInTheDocument();
});
});
63 changes: 31 additions & 32 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
{
"compilerOptions": {
/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "es2016",
/* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"esModuleInterop": true,
/* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true,
/* Enable all strict type-checking options. */
"strict": true,
/* Skip type checking all .d.ts files. */
"skipLibCheck": true,
"jsx": "react",
"module": "ESNext",
"noEmit": true,
// "declaration": true,
// "declarationDir": "types",
// "emitDeclarationOnly": true,
"sourceMap": true,
"outDir": "dist",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"*.cjs",
"*.js"
],
"exclude": [
"dist",
"node_modules"
]
"compilerOptions": {
/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "es2016",
/* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"esModuleInterop": true,
/* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true,
/* Enable all strict type-checking options. */
"strict": true,
/* Skip type checking all .d.ts files. */
"skipLibCheck": true,
"jsx": "react",
"module": "ESNext",
"noEmit": true,
// "declaration": true,
// "declarationDir": "types",
// "emitDeclarationOnly": true,
"sourceMap": true,
"outDir": "dist",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"*.cjs",
"*.js",
"vite.config.ts",
"vitest-setup.ts"
],
"exclude": ["dist", "node_modules"]
}
18 changes: 18 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// <reference types="vitest" />

// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from "vite";
// eslint-disable-next-line import/no-extraneous-dependencies
import react from "@vitejs/plugin-react";

// eslint-disable-next-line no-restricted-exports
export default defineConfig({
plugins: [react()],
test: {
environment: "jsdom",
setupFiles: ["./vitest-setup.ts"],
coverage: {
reporter: ["text"],
},
},
});
2 changes: 2 additions & 0 deletions vitest-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import "@testing-library/jest-dom/vitest";