Skip to content

Commit

Permalink
chore: better tests (#75)
Browse files Browse the repository at this point in the history
* chore: remove pycache stuff

* chore: ignore pycache

* fix: async tests now work properly

* chore: only release package if tests pass

* chore: bump version

* chore: enable renovate for python and gh actions
  • Loading branch information
Uninen authored Nov 14, 2024
1 parent 4363474 commit 609d4e8
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 45 deletions.
6 changes: 5 additions & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": ["config:recommended", "group:all", "schedule:weekly", ":widenPeerDependencies"],
"enabledManagers": ["npm"],
"enabledManagers": ["pep621", "npm", "github-actions"],
"packageRules": [
{
"matchManagers": ["npm"],
Expand All @@ -10,6 +10,10 @@
{
"rangeStrategy": "auto",
"matchPackageNames": ["/npm/"]
},
{
"matchPackagePatterns": ["github-actions"],
"automerge": true
}
],
"timezone": "Europe/Helsinki",
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
on:
push:
workflow_run:
workflows: ['Tests']
types:
- completed
branches:
- main
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}

steps:
- uses: actions/[email protected]
- uses: pnpm/[email protected]
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/e2e.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: E2E Test
name: Tests

on:
push:
Expand Down Expand Up @@ -28,6 +28,7 @@ jobs:
runs-on: ubuntu-latest

env:
CI: 1
DEBUG: 0
PLAYWRIGHT_BROWSERS_PATH: 0

Expand All @@ -49,7 +50,7 @@ jobs:
cache: 'pnpm'

- name: Install Playwright browsers
run: npx playwright install --with-deps
run: pnpm exec playwright install --with-deps

- name: Run e2e tests
run: pnpm test:ci-e2e
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
node_modules
dist
dist-ssr
__pycache__

/tests/e2e/videos/
/tests/e2e/screenshots/
Expand Down
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.1 (2024-11-14)

- Fix: fixed async tests.

## 0.3.0 (2024-11-14)

- Enhancement: made tests better, added Python api for proper local testing.
Expand Down
Binary file removed __pycache__/api.cpython-313-pytest-8.3.3.pyc
Binary file not shown.
Binary file removed __pycache__/api.cpython-313.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@slipmatio/toolbelt",
"type": "module",
"version": "0.3.0",
"version": "0.3.1",
"main": "dist/toolbelt.umd.cjs",
"module": "dist/toolbelt.js",
"exports": {
Expand Down
28 changes: 8 additions & 20 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@ const config: PlaywrightTestConfig = {
testDir: './tests/e2e',
timeout: 15 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 3000,
},
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 1 : 0,
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 2 : undefined,
workers: process.env.CI ? 1 : undefined,
use: {
actionTimeout: 0,
actionTimeout: 500,
baseURL: 'http://localhost:5173',
trace: 'on-first-retry',
// headless: !!process.env.CI,
},
webServer: {
command: 'vite dev',
Expand All @@ -30,25 +26,17 @@ const config: PlaywrightTestConfig = {
},
projects: [
{
name: 'iPhone 6',
name: 'iPhone SE',
use: {
browserName: 'webkit',
...devices['iPhone 6'],
},
},
{
name: 'Macbook 11',
use: {
browserName: 'firefox',
...devices['Macbook 11'],
video: 'on-first-retry',
...devices['iPhone SE'],
},
},
{
name: 'Desktop',
use: {
browserName: 'chromium',
...devices['Macbook Pro'],
browserName: 'firefox',
...devices['Desktop Firefox'],
},
},
],
Expand Down
9 changes: 5 additions & 4 deletions tests/e2e/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, test } from '@playwright/test'
test('clipboard should work', async ({ page }) => {
await page.goto('/')
await page.getByTestId('clipboard').click()
expect(page.getByTestId('clipboard-result')).toHaveText('true')
await expect(page.getByTestId('clipboard-result')).toHaveText('true')
})

test('getCookie should work', async ({ browser }) => {
Expand All @@ -16,12 +16,13 @@ test('getCookie should work', async ({ browser }) => {
const cookies = await context.cookies()
expect(cookies).toHaveLength(1)
await page.waitForSelector('[data-testid=cookie-results]')
expect(page.getByTestId('cookie-result1')).toHaveText('null')
expect(page.getByTestId('cookie-result2')).toHaveText('this-is-a-test')

await expect(page.getByTestId('cookie-result1')).toHaveText('null')
await expect(page.getByTestId('cookie-result2')).toHaveText('this-is-a-test')
})

test('localStorage should be available', async ({ page }) => {
await page.goto('/')
await page.getByTestId('localstorage').click()
expect(page.getByTestId('localstorage-result')).toHaveText('true')
await expect(page.getByTestId('localstorage-result')).toHaveText('true')
})
2 changes: 1 addition & 1 deletion tests/e2e/vue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { testUrls } from '../../src/testurls'
test('getNextPath should work on all inputs', async ({ page }) => {
for (const { testid, url, expected } of testUrls) {
await page.goto(url)
expect(page.getByTestId('path')).toHaveText(expected)
await expect(page.getByTestId('path')).toHaveText(expected)
console.log(`url: ${url}, expected: ${expected}`)
}
})
30 changes: 15 additions & 15 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 609d4e8

Please sign in to comment.