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: better tests #74

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 7 additions & 25 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
{
"extends": [
"config:base",
"group:all",
"schedule:weekly",
":widenPeerDependencies"
],
"enabledManagers": [
"npm"
],
"extends": ["config:recommended", "group:all", "schedule:weekly", ":widenPeerDependencies"],
"enabledManagers": ["npm"],
"packageRules": [
{
"matchManagers": [
"npm"
],
"matchManagers": ["npm"],
"automerge": true,
"stabilityDays": 2
},
{
"matchPackagePatterns": [
"npm"
],
"rangeStrategy": "auto"
"minimumReleaseAge": "2 days"
},
{
"matchPackageNames": [
"vite-plugin-dts"
],
"matchCurrentVersion": "3.2.0",
"enabled": false
"rangeStrategy": "auto",
"matchPackageNames": ["/npm/"]
}
],
"timezone": "Europe/Helsinki",
"dependencyDashboard": true
}
}
14 changes: 7 additions & 7 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ jobs:
PLAYWRIGHT_BROWSERS_PATH: 0

steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
- uses: actions/checkout@v4.2.2
- uses: actions/cache@v4.1.2
with:
path: /home/runner/.local/share/pnpm/store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v2.4.1
with:
version: 8
version: 9
run_install: true
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4.1.0
with:
node-version: 20
node-version: 22
cache: 'pnpm'

- name: Install Playwright browsers
Expand All @@ -54,7 +54,7 @@ jobs:
- name: Run e2e tests
run: pnpm test:ci-e2e

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4.4.3
if: always()
with:
name: playwright-report
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/checkout@v4.2.2
- uses: pnpm/action-setup@v2.4.1
with:
version: 8
version: 9
run_install: false
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4.1.0
with:
node-version: '20'
node-version: '22'

- run: |
pnpm i --frozen-lockfile
pnpm build

- uses: JS-DevTools/npm-publish@v2
- uses: JS-DevTools/npm-publish@v3.1.1
id: publish
with:
token: ${{ secrets.NPM_TOKEN }}

- name: Create Tag
if: ${{ steps.publish.outputs.type }}
id: create_tag
uses: jaywcjlove/create-tag-action@main
uses: jaywcjlove/create-tag-action@v2.2.0
with:
package-path: ./package.json

- name: Generate Changelog
id: changelog
uses: jaywcjlove/changelog-generator@main
uses: jaywcjlove/changelog-generator@v2.2.2
if: steps.create_tag.outputs.successful
with:
head-ref: ${{steps.create_tag.outputs.version}}
Expand All @@ -45,7 +45,7 @@ jobs:
run: echo "${{ steps.changelog.outputs.changelog }}"

- name: Create Release
uses: ncipollo/release-action@v1
uses: ncipollo/release-action@v1.14.0
if: steps.create_tag.outputs.successful
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.3.0 (2024-11-14)

- Enhancement: made tests better, added Python api for proper local testing.

## 0.2.2 (2024-01-05)

- Feat: allow passing Router instance to `getNextPath`.
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,20 @@ General utilities for Web development

`pnpm dev`

### Run tests
### Testing

`pnpm test`
#### Unittests

1. `pnpm test`

#### E2E

1. Run the backend: `uv run uvicorn api:app --reload`
2. `pnpm test:e2e`

### Publishing

Bump version number in `package.json`, merge to main.

## Contributing

Expand Down
Binary file added __pycache__/api.cpython-313-pytest-8.3.3.pyc
Binary file not shown.
Binary file added __pycache__/api.cpython-313.pyc
Binary file not shown.
46 changes: 46 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from fastapi import FastAPI, Request, Response
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)


@app.get("/cookie/set/{name}/{value}/")
async def set_cookie(name: str, value: str, response: Response):
response.set_cookie(key=name, value=value, secure=False)
return {"status": "ok"}


@app.get("/cookie/get/{name}/")
async def get_cookie(request: Request, name: str):
return {"value": request.cookies.get(name)}


def test_cookie_flow():
from fastapi.testclient import TestClient

with TestClient(app) as client:
# Set cookie
response = client.get("/cookie/set/test/value123/")
assert response.status_code == 200

# Verify cookie is set
assert "test" in client.cookies
assert client.cookies["test"] == "value123"

# Get cookie
response = client.get("/cookie/get/test/")
assert response.json()["value"] == "value123"


if __name__ == "__main__":
import uvicorn

uvicorn.run(app, host="0.0.0.0", port=8000)
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@slipmatio/toolbelt",
"type": "module",
"version": "0.2.2",
"version": "0.3.0",
"main": "dist/toolbelt.umd.cjs",
"module": "dist/toolbelt.js",
"exports": {
Expand All @@ -28,15 +28,15 @@
"@playwright/test": "1.48.2",
"@tsconfig/node20": "20.1.4",
"@types/node": "22.9.0",
"@vitejs/plugin-vue": "5.1.4",
"@vitest/coverage-v8": "2.1.4",
"@vitejs/plugin-vue": "5.2.0",
"@vitest/coverage-v8": "2.1.5",
"@vue/test-utils": "2.4.6",
"@vue/tsconfig": "0.5.1",
"happy-dom": "15.11.0",
"@vue/tsconfig": "0.6.0",
"happy-dom": "15.11.6",
"typescript": "5.6.3",
"vite": "5.4.10",
"vite": "5.4.11",
"vite-plugin-dts": "4.3.0",
"vitest": "2.1.4",
"vitest": "2.1.5",
"vue": "3.5.12",
"vue-router": "4.4.5",
"vue-tsc": "2.1.10"
Expand All @@ -56,4 +56,4 @@
"url": "https://github.com/slipmatio/toolbelt/issues"
},
"homepage": "https://github.com/slipmatio/toolbelt"
}
}
Loading
Loading