Skip to content

Commit

Permalink
wip: adding more unit tests and playwrite config
Browse files Browse the repository at this point in the history
WIP: #9
  • Loading branch information
shivan-s committed Oct 1, 2023
1 parent 79bd591 commit 4b2c662
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ node_modules
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
coverage/*
/coverage
39 changes: 36 additions & 3 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { type PlaywrightTestConfig, devices } from '@playwright/test';

const config: PlaywrightTestConfig = {
webServer: {
command: 'npm run build && npm run preview',
port: 4173
reuseExistingServer: !process.env.CI,
url: 'http://localhost:4173'
},
fullyParallel: true,
testDir: 'tests',
testMatch: /(.+\.)?(test|spec)\.[jt]s/
testMatch: /(.+\.)?(test|spec)\.[jt]s/,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'http://localhost:4173',
trace: 'on-first-retry'
},
expect: { timeout: 30000 },
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] }
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] }
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] }
},
{
name: 'Mobile Chrome',
use: { ...devices['Pixel 5'] }
},
{
name: 'Mobile Safari',
use: { ...devices['iPhone 12'] }
}
]
};

export default config;
2 changes: 1 addition & 1 deletion src/lib/calculators/oneRM/oneRM.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('oneRM', () => {
'$input passed into epley should calculate',
({ input }) => {
const result = epley(input);
expect(result).not.toBeNaN();
expect(result).not.toBeNaN();
}
);
it.each([{ input: { weight: 190, rpe: 8.5, reps: 3 } }])(
Expand Down
13 changes: 9 additions & 4 deletions src/lib/calculators/targetWeight/targetWeight.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { describe, it, expect } from 'vitest';
import { calculateTargetWeight } from './targetWeight';

describe('sum test', () => {
it('adds 1 + 2 to equal 3', () => {
expect(1 + 2).toBe(3);
});
describe('targetWeight', () => {
it.each([{ input: { oneRM: 190, targetReps: 3, targetRPE: 8.5 } }])(
'should calculate',
({ input }) => {
const result = calculateTargetWeight(input);
expect(result).not.toBeNaN();
}
);
});
4 changes: 2 additions & 2 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script lang="ts">
import '../app.css';
import { page } from '$app/stores';
import Navbar from '$lib/components/navbar.svelte';
import Footer from '$lib/components/footer.svelte';
import { Navbar, Footer } from '$components';
$: pageTitle = $page.data['pageTitle'];
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/routes/one-rm/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { calculateOneRM } from '$lib';
import { enhance } from '$app/forms';
import RpeSelect from '$lib/components/RpeSelect.svelte';
import { RpeSelect } from '$components';
import type { ActionData } from './$types';
export let form: ActionData;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/rpe-weight/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { calculateTargetWeight } from '$lib';
import RpeSelect from '$lib/components/RpeSelect.svelte';
import { RpeSelect } from '$components';
let oneRM = 190;
let targetReps = 3;
Expand Down
17 changes: 17 additions & 0 deletions tests/screenshots.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from '@playwright/test';

test.describe('Screenshots', () => {
const urls = [
{ name: 'Index', url: '/' },
{ name: 'Index', url: '/one-rm' },
{ name: 'Index', url: '/rpe-weight' }
];
for (const { name, url } of urls) {
test(`screenshot for ${name}`, async ({ page, request }) => {
const response = await request.get(url);
expect(response.status).toBe(200);
await page.goto(url);
await page.screenshot();
});
}
});
6 changes: 0 additions & 6 deletions tests/test.ts

This file was deleted.

0 comments on commit 4b2c662

Please sign in to comment.