Skip to content

Commit

Permalink
Figure out static checks for TypeScript/Next.js portion of the app (#23)
Browse files Browse the repository at this point in the history
Adding: 
* next lint for catching JS errors, and adding it to the pre-commit hook and static code checks github action.
* prettier for UI code format, and adding it to the pre-commit hook and static code checks github action
* jest for testing, and adding it to the unit test github action
* Adding one sample unit test for page.tsx
* Adding instructions on how to run front-end tests
* Adding autofix commit bots as per
* Enable pre-commit ci and add default config aieng-template#10
* Adding unit test runs in pre-commit hooks
* Deleting package-lock.json, we don't need it since we use yarn and it has yarn-lock.json.
  • Loading branch information
lotif authored Apr 29, 2024
1 parent 8e5ee52 commit 5252cb3
Show file tree
Hide file tree
Showing 20 changed files with 2,906 additions and 7,756 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/node_modules/**
**/.next/**
tsconfig.json
*.min.js
9 changes: 9 additions & 0 deletions .github/workflows/integration_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ jobs:
source $(poetry env info --path)/bin/activate
poetry install --with docs,test
coverage run -m pytest florist/tests/integration && coverage xml && coverage report -m
# TODO enable this once we have intergation tests for the UI
# - name: Setup yarn
# uses: mskelton/setup-yarn@v1
# - name: Install nextjs dependencies and check code
# run: |
# yarn
# yarn integration-test

# - name: Upload coverage to Codecov
# uses: Wandalen/[email protected]
# with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/static_code_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ jobs:
with:
python-version: '3.9'
cache: 'poetry'
- name: Setup yarn
uses: mskelton/setup-yarn@v1
- name: Install dependencies and check code
run: |
yarn
poetry env use '3.9'
source .venv/bin/activate
poetry install --with test --all-extras
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,19 @@ jobs:
- uses: actions/[email protected]
with:
python-version: '3.9'
- name: Install dependencies and check code
cache: 'poetry'
- name: Install python dependencies and check code
run: |
poetry env use '3.9'
source $(poetry env info --path)/bin/activate
poetry install --with docs,test
coverage run -m pytest florist/tests/unit && coverage xml && coverage report -m
- name: Setup yarn
uses: mskelton/setup-yarn@v1
- name: Install nextjs dependencies and check code
run: |
yarn
yarn unit-test
# - name: Upload coverage to Codecov
# uses: Wandalen/[email protected]
# with:
Expand Down
45 changes: 45 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,55 @@ repos:
- id: nbqa-ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: local
hooks:
- id: nextjs-lint
name: nextjs-lint
entry: yarn lint-gh-action florist
files: "florist/app"
language: system

- repo: local
hooks:
- id: prettier-js-format
name: prettier-js-format
entry: yarn prettier
files: "florist/app"
language: system

- repo: local
hooks:
- id: doctest
name: doctest
entry: python3 -m doctest -o NORMALIZE_WHITESPACE
files: "(^florist/api/|florist/tests/api/)"
language: system

- repo: local
hooks:
- id: pytest-unit
name: pytest-unit
entry: python -m pytest florist/tests/unit
language: system
pass_filenames: false
always_run: true

- repo: local
hooks:
- id: nextjs-unit
name: nextjs-unit
entry: yarn unit-test
language: system
pass_filenames: false
always_run: true

ci:
autofix_commit_msg: |
[pre-commit.ci] Add auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
autofix_prs: true
autoupdate_branch: ''
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: weekly
skip: [pytest-unit,nextjs-unit,doctest,mypy,nextjs-lint]
submodules: false
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
florist/app/assets/css/material-dashboard.css
*.min.js
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tabWidth": 4
}
9 changes: 7 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using [Homebrew](https://brew.sh/):
brew install yarn
```

Then install the project dependencies:
Then install the project dependencies in development mode:
```shell
yarn
```
Expand All @@ -55,11 +55,16 @@ yarn dev

## Running the tests

To run the unit tests, simply execute:
To run the python unit tests, simply execute:
```shell
pytest florist/tests/unit
```

To run the nextjs unit tests, simply execute:
```shell
yarn unit-test
```

To run the integration tests, first make sure you:
- Have a Redis server running on your local machine on port 6379 by following [these instructions](README.md#start-servers-redis-instance).
- Have a MongoDB server running on your local machine on port 27017 by following [these instructions](README.md#start-mongodbs-instance).
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ using [Homebrew](https://brew.sh/):
brew install yarn
```

Then install the project dependencies:
Then install the project dependencies in production mode:
```shell
yarn
yarn --prod
```

### Pulling Redis' Docker
Expand Down
Loading

0 comments on commit 5252cb3

Please sign in to comment.