Skip to content

Commit

Permalink
feat: add test converage report support (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu-dixit authored Sep 3, 2024
1 parent 675876c commit 020f9ad
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 8 deletions.
68 changes: 66 additions & 2 deletions .github/workflows/run_js_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: Run JS SDK test

on:
push:
workflow_dispatch:
branches:
- master
pull_request:


jobs:
Expand Down Expand Up @@ -30,4 +32,66 @@ jobs:
- name: pnpm build
run: cd js && pnpm build
- name: run test
run: cd js && pnpm test
run: cd js && pnpm test:coverage


- name: Upload `coverage` folder to R2
if: ${{ always() }}
uses: ryand56/r2-upload-action@latest
with:
r2-account-id: ${{ secrets.R2_ACCOUNT_ID }}
r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }}
r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }}
r2-bucket: github-action
source-dir: js/coverage
destination-dir: coverage-${{ github.run_id }}/coverage

- name: Print unique URL
if: ${{ always() }}
run: |
echo "URL: 'https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/coverage-${{ github.run_id }}/coverage/index.html'"
- name: Upload jest html-reporters folder to R2
if: ${{ always() }}
uses: ryand56/r2-upload-action@latest
with:
r2-account-id: ${{ secrets.R2_ACCOUNT_ID }}
r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }}
r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }}
r2-bucket: github-action
source-dir: js/html-report
destination-dir: html-report-${{ github.run_id }}/html-report
- name: Print HTML report folder unique URL
if: ${{ always() }}
run: |
echo "HTML report folder unique URL: 'https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/html-report-${{ github.run_id }}/html-report/report.html'"
- name: Find Comment
if: ${{ always() }}
uses: peter-evans/find-comment@v3
id: fc
continue-on-error: true
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: This comment was generated by github-actions[bot]!

- name: Create or update comment
if: ${{ github.event_name == 'pull_request' && always() }}
uses: peter-evans/create-or-update-comment@v4
continue-on-error: true
with:
edit-mode: replace
issue-number: ${{ github.event.pull_request.number }}
body: |
This comment was generated by github-actions[bot]!
## JS SDK Coverage Report
📊 Coverage report for JS SDK can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/coverage-${{ github.run_id }}/coverage/index.html
📁 Test report folder can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/html-report-${{ github.run_id }}/html-report/report.html
reactions: rocket
comment-id: ${{ steps.fc.outputs.comment-id }}

3 changes: 2 additions & 1 deletion js/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ lib/
*.log
ks/test-results/*
coverage/
jest_html_reporters.html
jest_html_reporters.html
html-report/
1 change: 0 additions & 1 deletion js/config/getTestConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const getTestConfig = (): BACKEND_CONFIG => {
return JSON.parse(JSON.stringify(require(path))) as unknown as BACKEND_CONFIG;
} catch (error) {
console.error("Error loading test config file:", error);

throw new Error("Error loading test config file. You can create test.{{env}}.json file in the config folder.");
}
}
20 changes: 18 additions & 2 deletions js/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,26 @@ module.exports = {
testTimeout: 6000000,
collectCoverage: true,
coverageReporters: [
"html"
"html",
"text",
],
reporters: [
"default",
"jest-html-reporters"
["jest-html-reporters", {
"pageTitle": "Composio SDK Coverage Report",
"publicPath": "./html-report",
"filename": "report.html",
"includeConsoleLog": true,
"includeTestCoverage": true,
"includeTime": true,
"showSummary": true,
"showTable": true,
}]
],
"coveragePathIgnorePatterns": [
"src/sdk/client/*",
"src/env/*",
"src/sdk/testUtils/*",
"config/*",
]
};
3 changes: 1 addition & 2 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"build": "tsc --project . --outDir lib",
"build:watch": "tsc --watch --project . --outDir lib --watch",
"type-docs": "typedoc",
"openapispec:generate": "npx @hey-api/openapi-ts",
"start-client": "ts-node src/sdk/baseClient.ts"
"openapispec:generate": "npx @hey-api/openapi-ts"
},
"keywords": [],
"author": "Utkarsh Dixit <[email protected]>",
Expand Down
60 changes: 60 additions & 0 deletions js/src/utils/shared.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { jsonSchemaToTsType, jsonSchemaToModel, getEnvVariable, nodeExternalRequire } from './shared';
import z from 'zod';

describe('shared utilities', () => {
describe('jsonSchemaToTsType', () => {
it('should convert json schema types to TypeScript types', () => {
expect(jsonSchemaToTsType({ type: 'string' })).toBe(String);
expect(jsonSchemaToTsType({ type: 'integer' })).toBe(Number);
expect(jsonSchemaToTsType({ type: 'number' })).toBe(Number);
expect(jsonSchemaToTsType({ type: 'boolean' })).toBe(Boolean);
expect(jsonSchemaToTsType({ type: 'null' })).toBe(null);
expect(() => jsonSchemaToTsType({ type: 'unknown' })).toThrow('Unsupported JSON schema type: unknown');
});
});

describe('jsonSchemaToModel', () => {
it('should convert json schema to zod model', () => {
const schema = {
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'integer' },
},
required: ['name']
};
const model = jsonSchemaToModel(schema);
expect(model).toBeInstanceOf(z.ZodObject);
expect(() => model.parse({ name: 'John', age: 'not a number' })).toThrow();
expect(model.parse({ name: 'John', age: 30 })).toEqual({ name: 'John', age: 30 });
});
});

describe('getEnvVariable', () => {
it('should return the environment variable if set', () => {
process.env.TEST_VAR = 'test';
expect(getEnvVariable('TEST_VAR')).toBe('test');
});

it('should return undefined if the environment variable is not set', () => {
delete process.env.TEST_VAR;
expect(getEnvVariable('TEST_VAR')).toBeUndefined();
});

it('should return the default value if the environment variable is not set and default is provided', () => {
expect(getEnvVariable('TEST_VAR', 'default')).toBe('default');
});
});

describe('nodeExternalRequire', () => {
it('should require a module', () => {
const module = nodeExternalRequire('path');
expect(module).toBeDefined();
});

it('should return null if the module cannot be required', () => {
const module = nodeExternalRequire('nonexistent-module');
expect(module).toBeNull();
});
});
});

0 comments on commit 020f9ad

Please sign in to comment.