Skip to content
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
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
pull_request:
branches: [ main, master ]
push:
branches: [ main, master ]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [22.x]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run linter
run: npm run lint

- name: Run tests
run: npm test

- name: Run build
run: npm run build
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ tmp/
.idea/
*.iml
node_modules/
src/**/*.js

# SASS
.sass-cache
Expand Down
12 changes: 6 additions & 6 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const esbuild = require('esbuild');
const { sassPlugin } = require('esbuild-sass-plugin');
const fs = require('fs');
const path = require('path');
const PACKAGE = require('./package.json');
import esbuild from 'esbuild';
import { sassPlugin } from 'esbuild-sass-plugin';
import fs from 'fs';
import path from 'path';
import PACKAGE from './package.json' with { type: 'json' };

const ENV = process.env.WEBPACK_ENV;
const libraryName = 'gh-profile-card';
Expand All @@ -12,7 +12,7 @@ const banner = `/**
*/
`;

const outfilePath = path.resolve(__dirname, 'dist', `${libraryName}.min.js`);
const outfilePath = path.resolve('dist', `${libraryName}.min.js`);

esbuild
.build({
Expand Down
1 change: 1 addition & 0 deletions src/gh-cache-storage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
import { CacheStorage, CacheEntry } from './gh-cache-storage';
import { InMemoryStorage } from './testing/in-memory-storage';
import { BrowserStorage } from './interface/storage';
Expand Down
20 changes: 14 additions & 6 deletions src/gh-data-loader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import {
beforeEach,
describe,
expect,
it,
afterEach,
jest,
} from '@jest/globals';
import { GitHubApiLoader } from './gh-data-loader';
import { CacheStorage } from './gh-cache-storage';

Expand Down Expand Up @@ -168,15 +176,15 @@
headers: {
get: jest.fn().mockReturnValue('Mon, 18 Mar 2019 20:40:35 GMT'),
},
json: jest.fn().mockResolvedValue(mockProfile),
})
json: jest.fn(() => Promise.resolve(mockProfile)),
} as any)
.mockResolvedValueOnce({
status: 200,
headers: {
get: jest.fn().mockReturnValue('Mon, 18 Mar 2019 20:40:35 GMT'),
},
json: jest.fn().mockResolvedValue(mockRepositories),
});
json: jest.fn(() => Promise.resolve(mockRepositories)),
} as any);

// When
const result = await loader.loadUserData('testuser');
Expand Down Expand Up @@ -223,7 +231,7 @@
});

describe('loadRepositoriesLanguages', () => {
it('should load language statistics for repositories', (done) => {

Check warning on line 234 in src/gh-data-loader.spec.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Return a Promise instead of relying on callback parameter
// Setup language mocks using utility
setupLanguageMocks(mockLanguageStats);
setupEmptyCache(mockCache);
Expand All @@ -242,27 +250,27 @@
);
done();
} catch (error) {
done(error);
done(error as Error);
}
},
);
});

it('should handle empty repositories array', (done) => {

Check warning on line 259 in src/gh-data-loader.spec.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Return a Promise instead of relying on callback parameter
loader.loadRepositoriesLanguages([], (langStats) => {
expect(langStats).toEqual([]);
done();
});
});

it('should handle null repositories', (done) => {

Check warning on line 266 in src/gh-data-loader.spec.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Return a Promise instead of relying on callback parameter
loader.loadRepositoriesLanguages(null as any, (langStats) => {
expect(langStats).toEqual([]);
done();
});
});

it('should handle failed language requests gracefully', (done) => {

Check warning on line 273 in src/gh-data-loader.spec.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Return a Promise instead of relying on callback parameter
mockFetch
.mockResolvedValueOnce(createSuccessResponse(mockLanguageStats[0]))
.mockRejectedValueOnce(createNetworkError('Network error'));
Expand All @@ -279,13 +287,13 @@
);
done();
} catch (error) {
done(error);
done(error as Error);
}
},
);
});

it('should handle repositories without language URLs', (done) => {

Check warning on line 296 in src/gh-data-loader.spec.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Return a Promise instead of relying on callback parameter
const reposWithoutLangUrl = mockRepositories.map((repo) => ({
...repo,
languages_url: undefined as any,
Expand Down
1 change: 1 addition & 0 deletions src/gh-dom-operator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeEach, describe, expect, it } from '@jest/globals';
import { DOMOperator } from './gh-dom-operator';
import { ApiError, ApiProfile, ApiRepository } from './interface/IGitHubApi';

Expand Down
1 change: 1 addition & 0 deletions src/gh-dom.utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeEach, describe, expect, it } from '@jest/globals';
import {
createProfile,
createName,
Expand Down
1 change: 1 addition & 0 deletions src/gh-profile-card.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
import { GitHubCardWidget } from './gh-profile-card';
import { GitHubApiLoader } from './gh-data-loader';
import { DOMOperator } from './gh-dom-operator';
Expand Down
3 changes: 2 additions & 1 deletion src/gh-widget-init.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Mock the GitHubCardWidget
import { beforeEach, describe, expect, it, jest } from '@jest/globals';

jest.mock('./gh-profile-card');

import { GitHubCardWidget } from './gh-profile-card';
Expand Down
14 changes: 8 additions & 6 deletions src/testing/fetch-mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Fetch mock utilities for testing
*/
import { jest } from '@jest/globals';
import { ApiProfile, ApiRepository } from '../interface/IGitHubApi';

export interface MockResponse {
status: number;
Expand All @@ -25,8 +24,8 @@ export function setupFetchMock(): void {
/**
* Creates a successful HTTP response mock
*/
export function createSuccessResponse(
data: any,
export function createSuccessResponse<T>(
data: T,
headers: Record<string, string> = {},
): MockResponse {
return {
Expand Down Expand Up @@ -88,7 +87,10 @@ export function resetFetchMock(): void {
/**
* Sets up common fetch mock responses for user data loading
*/
export function setupUserDataMocks(profile: any, repositories: any[]): void {
export function setupUserDataMocks(
profile: ApiProfile,
repositories: ApiRepository[],
): void {
mockFetch
.mockResolvedValueOnce(
createSuccessResponse(profile, {
Expand Down
1 change: 1 addition & 0 deletions src/testing/style-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
2 changes: 1 addition & 1 deletion src/testing/test-setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import { jest } from '@jest/globals';
import { jest, beforeEach, expect, afterEach } from '@jest/globals';

// Mock console methods during tests to reduce noise
const originalError = console.error;
Expand Down
13 changes: 10 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": false,
"module": "es2015",
"module": "es2022",
"target": "es2017",
"sourceMap": true,
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
"allowSyntheticDefaultImports": true,
"moduleResolution": "nodenext",
"strict": false,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"types": ["jest", "node"]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
Loading