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: Added test infrastructure and initial component tests #253

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
38b9fd1
feat(security): implemented pre-signed URL upload approach
amjedidiah Nov 6, 2024
9569c41
fix(upload): resolved CORS issues in pre-signed URL upload
amjedidiah Nov 6, 2024
801c4ec
fix(app): build and prettier fixes
amjedidiah Nov 6, 2024
355cde2
chore(app): undoing unnecessary commit changes
amjedidiah Nov 12, 2024
ad9be44
feat(storage): implemented and refined cloud storage SDK integrations
amjedidiah Nov 14, 2024
61dc085
feat(storage): implemented Azure SDK integrations
amjedidiah Nov 15, 2024
7d7a98b
chore(app): removed todo from commit
amjedidiah Nov 15, 2024
cb659dc
refactor(app): streamline storageConfig prop values
amjedidiah Nov 17, 2024
84c8946
feat(storage): implemented DO SDK integrations
amjedidiah Nov 18, 2024
d9504af
feat(app): s3 compliant support
amjedidiah Nov 20, 2024
93a2502
feat(app): merged azure and s3 SDK into one
amjedidiah Nov 20, 2024
edfe2ea
fix(app): fixed console warning about ETag header
amjedidiah Nov 21, 2024
b0da73a
feat(app): backend logic
amjedidiah Nov 21, 2024
8a030c4
chore(app): build fixes and clean up
amjedidiah Nov 22, 2024
b565959
chore(app): better path resolutions and prettier fixes
amjedidiah Nov 22, 2024
a46fc3d
feat(app): dual builds
amjedidiah Nov 22, 2024
0291443
feat(app): successful merged builds
amjedidiah Nov 22, 2024
0320120
fix(app): prettier fixes
amjedidiah Nov 22, 2024
135ca18
fix(app): review fixes
amjedidiah Nov 25, 2024
d35a853
feat(tests): added comprehensive test setup
amjedidiah Nov 26, 2024
7602ba9
test(s3): added comprehensive tests for s3GeneratePresignedUrl and up…
amjedidiah Nov 26, 2024
6b9be4f
chore(test): setting threshold to 1 pending when others tests will be…
amjedidiah Nov 26, 2024
a06ad62
chore(app): fixed deprecated artifact actions version
amjedidiah Nov 26, 2024
a5b68a7
Merge branch 'master' into feat/test-setup
amjedidiah Nov 27, 2024
2f313a5
Merge branch 'master' into feat/test-setup
amjedidiah Dec 4, 2024
7e0af09
refactor(test): better arrangement in tests in central folder
amjedidiah Dec 4, 2024
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
95 changes: 94 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,88 @@ jobs:
- name: Prettier Check
run: pnpm run prettier-check

Test:
name: Run Tests and Coverage
runs-on: ubuntu-latest
needs: [Prettier-check]
steps:
- name: Checkout repo
uses: actions/checkout@v3

- uses: actions/setup-node@v3
id: cache-primes
with:
node-version-file: '.nvmrc'

- name: Setup PNPM environment
if: steps.cache-primes.outputs.cache-hit != 'true'
run: |
npm install -g pnpm@latest
pnpm config set store-dir ~/.pnpm-store

- name: Cache PNPM dependencies
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-v3-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-v3-

- name: Install dependencies
if: steps.cache-primes.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile

- name: Run Tests with Coverage
run: pnpm run test:coverage

- name: Check Coverage Thresholds
run: |
COVERAGE_OUTPUT=$(cat coverage/coverage-summary.json)

STATEMENTS_PCT=$(echo $COVERAGE_OUTPUT | jq -r '.total.statements.pct')
BRANCHES_PCT=$(echo $COVERAGE_OUTPUT | jq -r '.total.branches.pct')
FUNCTIONS_PCT=$(echo $COVERAGE_OUTPUT | jq -r '.total.functions.pct')
LINES_PCT=$(echo $COVERAGE_OUTPUT | jq -r '.total.lines.pct')

THRESHOLD=1

if (( $(echo "$STATEMENTS_PCT < $THRESHOLD" | bc -l) )); then
echo "❌ Statement coverage ($STATEMENTS_PCT%) is below threshold ($THRESHOLD%)"
exit 1
fi

if (( $(echo "$BRANCHES_PCT < $THRESHOLD" | bc -l) )); then
echo "❌ Branch coverage ($BRANCHES_PCT%) is below threshold ($THRESHOLD%)"
exit 1
fi

if (( $(echo "$FUNCTIONS_PCT < $THRESHOLD" | bc -l) )); then
echo "❌ Function coverage ($FUNCTIONS_PCT%) is below threshold ($THRESHOLD%)"
exit 1
fi

if (( $(echo "$LINES_PCT < $THRESHOLD" | bc -l) )); then
echo "❌ Line coverage ($LINES_PCT%) is below threshold ($THRESHOLD%)"
exit 1
fi

echo "✅ All coverage thresholds met!"
echo "Statements: $STATEMENTS_PCT%"
echo "Branches: $BRANCHES_PCT%"
echo "Functions: $FUNCTIONS_PCT%"
echo "Lines: $LINES_PCT%"

- name: Archive code coverage results
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: coverage/
retention-days: 30

Build:
name: Build project
runs-on: ubuntu-latest
needs: [ Prettier-check ]
needs: [Prettier-check, Test]
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand Down Expand Up @@ -73,3 +150,19 @@ jobs:

- name: Build
run: pnpm run build

Status-Check:
name: Status Check
runs-on: ubuntu-latest
needs: [Prettier-check, Test, Build]
if: always()
steps:
- name: Check status
run: |
if [ "${{ needs.Prettier-check.result }}" != "success" ] || \
[ "${{ needs.Test.result }}" != "success" ] || \
[ "${{ needs.Build.result }}" != "success" ]; then
echo "One or more jobs failed"
exit 1
fi
echo "All jobs passed successfully"
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dist
.idea
.vscode


# storybook
storybook-static

Expand All @@ -16,4 +17,7 @@ storybook-static

# public folder temp files
public
/stories/Uploader.stories.js
/stories/Uploader.stories.js

# Tests
coverage
46 changes: 46 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/** @type {import('jest').Config} */
module.exports = {
roots: ['<rootDir>/src'],
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'],
moduleNameMapper: {
'^frontend/(.*)$': '<rootDir>/src/frontend/$1',
'^backend/(.*)$': '<rootDir>/src/backend/$1',
'^lib/(.*)$': '<rootDir>/src/lib/$1',
'\\.css$': 'identity-obj-proxy',
'^@/(.*)$': '<rootDir>/src/$1',
},
transform: {
'^.+\\.(t|j)sx?$': [
'ts-jest',
{
tsconfig: 'tsconfig.json',
},
],
},
transformIgnorePatterns: ['node_modules/(?!(@mui|framer-motion)/)'],
testMatch: [
'<rootDir>/src/**/__tests__/**/*.{ts,tsx}',
'<rootDir>/src/**/*.{spec,test}.{ts,tsx}',
],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/*.d.ts',
'!src/version.ts',
],
coverageReporters: [
'json-summary', // Creates coverage-summary.json used by CI
'text', // Console output
'lcov', // Detailed HTML report
'clover', // Additional machine-readable format
],
coverageThreshold: {
global: {
branches: 1,
functions: 1,
lines: 1,
statements: 1,
},
},
}
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
"build:browser": "tsdx build --entry ./src/index.browser.ts --tsconfig ./tsconfig.browser.json --format esm,cjs --name browser",
"build:node": "tsdx build --entry ./src/index.node.ts --tsconfig ./tsconfig.node.json --format cjs --name node",
"build": "node scripts/build.js",
"test": "tsdx test --passWithNoTests",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"test:ci": "jest --coverage --ci --maxWorkers=2",
"lint": "tsdx lint",
"prepare": "tsdx build",
"size": "size-limit",
Expand Down Expand Up @@ -99,6 +102,10 @@
"@storybook/react": "^7.6.20",
"@storybook/react-webpack5": "^7.6.20",
"@storybook/testing-library": "^0.2.2",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "29.5.11",
"@types/node": "^20.10.0",
"@types/pako": "^2.0.3",
"@types/react": "^18.2.39",
Expand All @@ -110,6 +117,10 @@
"babel-loader": "^9.1.3",
"highlight.js": "10.7.3",
"husky": "^8.0.3",
"identity-obj-proxy": "^3.0.0",
"jest": "29.7.0",
"jest-canvas-mock": "^2.5.2",
"jest-environment-jsdom": "29.7.0",
"lowlight": "1.20.0",
"postcss": "^8.4.31",
"prettier": "3.0.3",
Expand All @@ -124,6 +135,7 @@
"size-limit": "^10.0.3",
"storybook": "^7.5.3",
"tailwindcss": "^3.3.5",
"ts-jest": "29.1.1",
"tsdx": "^0.14.1",
"tslib": "^2.6.2",
"typescript": "^5.3.2",
Expand Down
Loading
Loading