Skip to content

Commit 3fa3720

Browse files
committed
added workflows for linting and type checking
2 parents 3d3c73b + bc6dafc commit 3fa3720

20 files changed

Lines changed: 1108 additions & 231 deletions

.github/workflows/lint.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '18'
23+
cache: 'yarn'
24+
25+
- name: Install dependencies
26+
run: yarn install --frozen-lockfile
27+
28+
- name: Run ESLint
29+
run: yarn lint

.github/workflows/test.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '18'
23+
cache: 'yarn'
24+
25+
- name: Install dependencies
26+
run: yarn install --frozen-lockfile
27+
28+
- name: Run tests
29+
run: yarn test
30+
31+
- name: Run tests with coverage
32+
run: yarn test:coverage
33+
34+
- name: Upload coverage reports
35+
uses: codecov/codecov-action@v4
36+
if: always()
37+
with:
38+
files: ./coverage/coverage-final.json
39+
fail_ci_if_error: false
40+
env:
41+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/type-check.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Type Check
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
type-check:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '18'
23+
cache: 'yarn'
24+
25+
- name: Install dependencies
26+
run: yarn install --frozen-lockfile
27+
28+
- name: Run TypeScript type checking
29+
run: yarn type-check

src/lib/api/localStorage.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { afterEach, describe, expect, it, vi } from 'vitest';
2+
import { getLocalStorage, localStorageKey, setLocalStorage } from './localStorage';
3+
4+
afterEach(() => {
5+
localStorage.clear();
6+
vi.resetModules();
7+
});
8+
9+
describe('localStorage helpers', () => {
10+
it('prefixes keys with the OAuth client id', async () => {
11+
// Ensure staging values are used for deterministic keys
12+
Object.defineProperty(window, 'location', {
13+
value: { ...window.location, search: '?staging=true' },
14+
writable: true,
15+
});
16+
await import('./wca-env');
17+
18+
expect(localStorageKey('token')).toContain('delegate-dashboard.example-application-id.token');
19+
});
20+
21+
it('sets and retrieves data consistently', async () => {
22+
Object.defineProperty(window, 'location', {
23+
value: { ...window.location, search: '?staging=true' },
24+
writable: true,
25+
});
26+
await import('./wca-env');
27+
28+
setLocalStorage('token', 'abc123');
29+
expect(getLocalStorage('token')).toBe('abc123');
30+
});
31+
});

src/lib/api/wca-env.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { afterEach, describe, expect, it, vi } from 'vitest';
2+
3+
const setLocationSearch = (search: string) => {
4+
Object.defineProperty(window, 'location', {
5+
value: { ...window.location, search },
6+
writable: true,
7+
});
8+
};
9+
10+
afterEach(() => {
11+
vi.resetModules();
12+
});
13+
14+
describe('wca env helpers', () => {
15+
it('prefers staging configuration when staging query is present', async () => {
16+
setLocationSearch('?staging=true');
17+
const env = await import('./wca-env');
18+
19+
expect(env.STAGING_QUERY_PARAMS).toBe(true);
20+
expect(env.WCA_ORIGIN).toBe('https://staging.worldcubeassociation.org');
21+
expect(env.WCA_OAUTH_CLIENT_ID).toBe('example-application-id');
22+
});
23+
24+
it('falls back to environment variables when staging is absent', async () => {
25+
process.env.VITE_WCA_ORIGIN = 'https://prod.example';
26+
process.env.VITE_WCA_OAUTH_CLIENT_ID = 'prod-client';
27+
setLocationSearch('');
28+
29+
const env = await import('./wca-env');
30+
31+
expect(env.STAGING_QUERY_PARAMS).toBe(false);
32+
expect(env.WCA_ORIGIN).toBe('https://prod.example');
33+
expect(env.WCA_OAUTH_CLIENT_ID).toBe('prod-client');
34+
});
35+
});

src/lib/api/wca-env.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
console.log('env', import.meta.env);
21
const searchParams = new URLSearchParams(window.location.search);
32
export const STAGING_QUERY_PARAMS = searchParams.has('staging');
43

0 commit comments

Comments
 (0)