From f7182024b5724111ee1372e6b984df1aa44ee6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anto=20Kein=C3=A4nen?= <62938747+antoKeinanen@users.noreply.github.com> Date: Sun, 14 Jul 2024 10:27:25 +0300 Subject: [PATCH] ci: automatic lint, test, typecheck, and format action (#18) * ci: add checking scripts * ci: add code checking action * fix: correctly type the useTheme hook * test: add dummy test to make jest happy * test: remove obsolete test snapshot --- .github/workflows/check-code.yml | 37 +++++++++++++++++++ .gitignore | 3 ++ .../__snapshots__/ThemedText-test.tsx.snap | 24 ------------ components/__tests__/dummyTest.test.ts | 8 ++++ components/timetable/DateSelector.tsx | 3 +- package.json | 6 ++- styles/index.ts | 3 +- styles/themes.ts | 2 + 8 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/check-code.yml delete mode 100644 components/__tests__/__snapshots__/ThemedText-test.tsx.snap create mode 100644 components/__tests__/dummyTest.test.ts diff --git a/.github/workflows/check-code.yml b/.github/workflows/check-code.yml new file mode 100644 index 0000000..61e86d9 --- /dev/null +++ b/.github/workflows/check-code.yml @@ -0,0 +1,37 @@ +name: Typecheck, lint, format and test + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +jobs: + lint-typecheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + + - name: Install dependencies + run: npm install + + - name: Typecheck + run: npm run check:types + + - name: Lint + run: npm run check:lint + + - name: Format + run: npm run check:format + + - name: Test + run: npm run check:test diff --git a/.gitignore b/.gitignore index 2e028e7..f5f5c27 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,9 @@ npm-debug.* web-build/ .env +# Test stuff +coverage/ + # macOS .DS_Store diff --git a/components/__tests__/__snapshots__/ThemedText-test.tsx.snap b/components/__tests__/__snapshots__/ThemedText-test.tsx.snap deleted file mode 100644 index b68e53e..0000000 --- a/components/__tests__/__snapshots__/ThemedText-test.tsx.snap +++ /dev/null @@ -1,24 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders correctly 1`] = ` - - Snapshot test! - -`; diff --git a/components/__tests__/dummyTest.test.ts b/components/__tests__/dummyTest.test.ts new file mode 100644 index 0000000..dada9e6 --- /dev/null +++ b/components/__tests__/dummyTest.test.ts @@ -0,0 +1,8 @@ +// Jest requires at least one test file in the project to run the tests. +// This is a dummy test file to make Jest happy. + +describe('It should pass', () => { + it('should pass', () => { + expect(1).toBe(1); + }); +}); diff --git a/components/timetable/DateSelector.tsx b/components/timetable/DateSelector.tsx index 75effd7..9b5efae 100644 --- a/components/timetable/DateSelector.tsx +++ b/components/timetable/DateSelector.tsx @@ -1,3 +1,4 @@ +import { DarkTheme } from '@/styles/index'; import dayjs from 'dayjs'; import 'dayjs/locale/en'; import 'dayjs/locale/fi'; @@ -23,7 +24,7 @@ const DateSelector = ({ nextVisible = true, previousVisible = true, }: DateSelectorProps) => { - const theme = useTheme(); + const theme = useTheme(); const { i18n } = useTranslation(); dayjs.locale(i18n.language); diff --git a/package.json b/package.json index 0b992c6..4d36fcc 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,11 @@ "web": "expo start --web", "test": "jest --watchAll", "lint": "expo lint", - "pretty": "prettier --write \"./**/*.{js,jsx,mjs,cjs,ts,tsx,json}\"" + "pretty": "prettier --write \"./**/*.{js,jsx,mjs,cjs,ts,tsx,json}\"", + "check:types": "tsc --noEmit", + "check:lint": "expo lint", + "check:format": "prettier --check \"./**/*.{js,jsx,mjs,cjs,ts,tsx,json}\"", + "check:test": "jest --bail --ci" }, "jest": { "preset": "jest-expo" diff --git a/styles/index.ts b/styles/index.ts index d1ec294..72790ea 100644 --- a/styles/index.ts +++ b/styles/index.ts @@ -1,4 +1,5 @@ import Colors from './colors'; import Themes from './themes'; +import { DarkTheme } from './themes'; -export { Colors, Themes }; +export { Colors, Themes, DarkTheme }; diff --git a/styles/themes.ts b/styles/themes.ts index e412c1a..f91e57f 100644 --- a/styles/themes.ts +++ b/styles/themes.ts @@ -29,4 +29,6 @@ const Themes = { }, }; +export type DarkTheme = (typeof Themes)['dark']['default']; + export default Themes;