Skip to content

Commit

Permalink
Move eslint & typescript configs into separate packages
Browse files Browse the repository at this point in the history
  • Loading branch information
serjonya-trili committed Jun 17, 2024
1 parent 6d3b711 commit df8dcb4
Show file tree
Hide file tree
Showing 21 changed files with 668 additions and 470 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
root: true,
extends: ["@umami/eslint-config/index.js"],
parserOptions: {
project: ["./apps/*/tsconfig.json", "./packages/*/tsconfig.json"],
parser: "@typescript-eslint/parser",
tsconfigRootDir: __dirname,
},
};
17 changes: 6 additions & 11 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,24 @@ jobs:
node-version: 20.x
cache: "yarn"

- name: Install dependencies
run: yarn install --immutable
- run: yarn install --immutable

- name: Install Playwright Browsers & build the app
run: yarn exec concurrently "yarn playwright install chromium --with-deps" "yarn build"
- name: Install Playwright browser
run: yarn workspace @umami/desktop playwright install chromium --with-deps

- name: Start server
run: yarn exec http-server build -p 3000 &

- name: Run cucumber tests
run: yarn test:e2e
- run: yarn test:e2e

- name: Cucumber Report to Annotations
uses: deblockt/[email protected]
if: always()
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "test-results/cucumber-report.json"
path: "apps/dekstop/test-results/cucumber-report.json"
show-global-summary-report: true

- uses: actions/upload-artifact@v4
if: always()
with:
name: cucumber-report
path: test-results/cucumber-report.html
path: apps/dekstop/test-results/cucumber-report.html
retention-days: 10
24 changes: 4 additions & 20 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:

jobs:
test:
runs-on: ubuntu-latest
runs-on: ubuntu-latest-m
env:
NODE_OPTIONS: "--max_old_space_size=4096"
steps:
Expand All @@ -32,24 +32,8 @@ jobs:
node-version: 20.x
cache: "yarn"

- name: Install packages
run: yarn install --immutable
- run: yarn install --immutable

- name: Run checks
run: turbo check-types lint:ci format:ci test
- run: yarn ci

- name: Circular dependencies check
run: npx madge --circular src/index.tsx

- name: Run tests
uses: ArtiomTr/[email protected]
with:
skip-step: install
test-script: yarn test
annotations: coverage
base-coverage-file: report.json
prnumber: ${{ steps.findPr.outputs.number }}

- name: Audit dependencies
# Exclude @toruslabs/customauth from audit until it's upgraded
run: yarn npm audit --exclude @toruslabs/customauth
- run: yarn test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ yarn-error.log*
.vscode

settings.json
/test-results/
test-results/

*.tsbuildinfo
docs/
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
root: true,
extends: ["@umami/eslint-config/index.js"],
parserOptions: {
// tsconfig.e2e.json includes both src and src/e2e
project: "./tsconfig.e2e.json",
parser: "@typescript-eslint/parser",
tsconfigRootDir: __dirname,
},
};
File renamed without changes.
4 changes: 2 additions & 2 deletions apps/desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ We use [jest](https://jestjs.io/) as the test runner.

This will run the e2e tests for you. Please make sure that you have docker & docker-compose [installed](https://docs.docker.com/desktop/install/mac-install/).

Note: the test runner expects the server with the app running at localhost:3000. You can use the dev server (`yarn start`) for that.
Note: the test runner expects the server with the app running at localhost:3000. You can use the dev server (`yarn dev`) for that.
On CI we build the app and serve the production build on the same port (check `.github/workflows/e2e.yaml` for details).

When you're working on a specific scenario, you can mark it with a `@focus` tag and use `yarn test:e2e:focus` to run it exclusively.
Expand All @@ -37,7 +37,7 @@ It correctly bundles React in production mode and optimizes the build for the be

Runs the electron app in the development mode.
In order to get the dev tools work please make sure to set the `devTools` to `true` in the `webPreferences` in `public/electron.js`
Note: you still have to have your `yarn start` running in a separate terminal
Note: you still have to have your `yarn dev` running in a separate terminal

### `yarn electron:package:(mac|win|linux)`

Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const config: Config = {
// projects: undefined,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,
reporters: process.env.CI ? ["github-actions"] : ["default", "summary"],

// Automatically reset mock state before every test
resetMocks: true,
Expand Down Expand Up @@ -153,7 +153,7 @@ const config: Config = {
setupFilesAfterEnv: ["<rootDir>/src/setupTests.ts"],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,
slowTestThreshold: 15,

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],
Expand Down
36 changes: 12 additions & 24 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "umami-desktop",
"name": "@umami/desktop",
"productName": "umami",
"version": "2.2.0",
"author": "Trilitech <[email protected]>",
Expand All @@ -13,22 +13,24 @@
"type": "commonjs",
"main": "build/electron.js",
"scripts": {
"audit": "yarn npm audit --exclude @toruslabs/customauth",
"build": "vite build",
"dev": "vite dev --host 127.0.0.1",
"preview": "vite preview",
"preview": "vite preview --host 127.0.0.1 --port 3000",
"electron:package:linux": "electron-builder -l",
"electron:package:mac": "electron-builder -m",
"electron:package:mac:debug": "DEBUG=true yarn build --mode dev && sed -i='' 's@devTools: false@devTools: true@g' build/electron.js && yarn electron:package:mac -c electron-builder.dev.yml && rm -rf build",
"electron:package:win": "electron-builder -w",
"electron:start": "electronmon .",
"check-circular-deps": "npx madge --circular src/index.tsx",
"docs": "typedoc --tsconfig tsconfig.e2e.json",
"format:ci": "prettier --check .",
"format:ci": "prettier --ignore-path ../../.gitignore --check .",
"format": "prettier --write .",
"lint:ci": "eslint src --ext .js,.jsx,.ts,.tsx --max-warnings=0",
"lint": "eslint src --ext .js,.jsx,.ts,.tsx --fix --config ../../.eslintrc",
"test": "cross-env TZ=CET jest",
"lint": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
"test": "cross-env TS_NODE_PROJECT=./tsconfig.json TZ=CET jest",
"test:watch": "cross-env DEV=true yarn test --watch",
"test:e2e": "cross-env TS_NODE_PROJECT=tsconfig.e2e.json cucumber-js",
"test:e2e": "cross-env TS_NODE_PROJECT=tsconfig.e2e.json start-server-and-test \"yarn preview\" http://127.0.0.1:3000 cucumber-js",
"test:e2e:focus": "yarn test:e2e --tags='@focus'",
"theme:watch": "chakra-cli tokens src/style/theme.ts --watch",
"theme": "chakra-cli tokens src/style/theme.ts",
Expand Down Expand Up @@ -82,36 +84,21 @@
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@types/react-test-renderer": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.13.0",
"@typescript-eslint/parser": "^7.13.0",
"@tzkt/sdk-api": "^2.2.1",
"@umami/eslint-config": "workspace:*",
"@umami/typescript-config": "workspace:*",
"@vitejs/plugin-react": "^4.3.1",
"axios": "^1.7.2",
"babel-jest": "^29.7.0",
"bignumber.js": "^9.1.2",
"bip39": "^3.1.0",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
"date-fns": "^3.6.0",
"electron": "^31.0.1",
"electron-builder": "^24.13.3",
"electronmon": "^2.0.3",
"eslint": "^8.57.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-chakra-ui": "^0.11.0",
"eslint-plugin-deprecation": "^3.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-jest-dom": "^5.4.0",
"eslint-plugin-playwright": "^1.6.2",
"eslint-plugin-react": "^7.34.2",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-redux": "^4.1.0",
"eslint-plugin-testing-library": "^6.2.2",
"eslint-plugin-tsdoc": "^0.3.0",
"eslint-plugin-unused-imports": "^3.2.0",
"framer-motion": "^11.2.10",
"http-server": "^14.1.1",
"identity-obj-proxy": "^3.0.0",
"immer": "^10.1.1",
"jest": "29.7.0",
Expand Down Expand Up @@ -145,6 +132,7 @@
"react-test-renderer": "^18.3.1",
"redux": "^5.0.1",
"redux-persist": "^6.0.0",
"start-server-and-test": "^2.0.4",
"ts-node": "^10.9.2",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.3.0",
Expand All @@ -155,7 +143,7 @@
"zipurl": "^0.2.18",
"zod": "^3.23.8"
},
"packageManager": "yarn@4.2.2",
"packageManager": "yarn@4.3.0",
"dependencies": {
"electron-updater": "^6.2.1"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/e2e/steps/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const resourceCleanup = () => {
};

BeforeAll({ timeout: secondsToMilliseconds(20) }, async function () {
browser = await chromium.launch({ headless: !!process.env.CI });
browser = await chromium.launch({ headless: !process.env.OPEN_BROWSER });
process.on("SIGINT", resourceCleanup);

Object.defineProperty(global, "crypto", crypto);
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/env.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const IS_DEV = import.meta.env.DEV;
export const IS_DEV = !!import.meta.env.DEV;
4 changes: 2 additions & 2 deletions apps/desktop/tsconfig.e2e.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"extends": "./tsconfig.json",
"extends": "@umami/typescript-config/tsconfig.json",
"compilerOptions": {
// until we migrated to ESM modules, we need to use CommonJS for e2e tests
"module": "CommonJS"
},
"exclude": [], // override the exclusion of src/e2e in tsconfig.json
"include": ["src", "jest.config.ts"],
"typedocOptions": {
"entryPoints": ["src"],
"entryPointStrategy": "expand",
Expand Down
21 changes: 2 additions & 19 deletions apps/desktop/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
{
"compilerOptions": {
"target": "ES6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"incremental": true,
"types": ["vite/client"]
},
"compilerOptions": { "types": ["vite/client"] },
"extends": "@umami/typescript-config/tsconfig.json",
"include": ["src", "vite.config.ts", "jest.config.ts"],
"exclude": ["src/e2e"]
}
File renamed without changes.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
"test": "turbo test",
"lint": "turbo lint",
"format": "turbo format",
"ci": "turbo check-types lint:ci format:ci audit check-circular-deps",
"test:e2e": "turbo test:e2e",
"dev:desktop": "turbo dev --filter='./apps/desktop'"
},
"devDependencies": {
"turbo": "^2.0.3"
"jest": "^29.7.0",
"turbo": "^2.0.4"
}
}
9 changes: 2 additions & 7 deletions .eslintrc → packages/eslint-config/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
module.exports = {
"root": true,
"parserOptions": {
// tsconfig.e2e.json includes both src and src/e2e
"project": "./tsconfig.e2e.json",
"parser": "@typescript-eslint/parser",
},
"plugins": [
"@stylistic/eslint-plugin",
"@typescript-eslint",
Expand Down Expand Up @@ -38,7 +33,7 @@
},
},
"rules": {
"@typescript-eslint/no-explicit-any": "off", // TODO: change to error https://app.asana.com/0/0/1204322668303155/f
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": ["warn", { "allow": ["arrowFunctions"] }],
"@typescript-eslint/switch-exhaustiveness-check": "warn",

Expand Down
32 changes: 32 additions & 0 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@umami/eslint-config",
"main": "index.js",
"type": "commonjs",
"packageManager": "[email protected]",
"license": "MIT",
"files": [
"index.js"
],
"dependencies": {
"@stylistic/eslint-plugin": "^2.1.0",
"@tanstack/eslint-plugin-query": "^5.43.1",
"@typescript-eslint/eslint-plugin": "^7.13.0",
"@typescript-eslint/parser": "^7.13.0",
"@umami/typescript-config": "workspace:*",
"eslint": "^8.57.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-chakra-ui": "^0.11.0",
"eslint-plugin-deprecation": "^3.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-jest-dom": "^5.4.0",
"eslint-plugin-playwright": "^1.6.2",
"eslint-plugin-react": "^7.34.2",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-redux": "^4.1.0",
"eslint-plugin-testing-library": "^6.2.2",
"eslint-plugin-tsdoc": "^0.3.0",
"eslint-plugin-unused-imports": "^3.2.0",
"typescript": "^5.4.5"
}
}
7 changes: 7 additions & 0 deletions packages/typescript-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@umami/typescript-config",
"license": "MIT",
"files": [
"tsconfig.json"
]
}
20 changes: 20 additions & 0 deletions packages/typescript-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"incremental": true
}
}
Loading

0 comments on commit df8dcb4

Please sign in to comment.