Skip to content

Commit

Permalink
testes: aumentando coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fonteeboa committed Dec 18, 2023
1 parent de206ac commit dcd29cf
Show file tree
Hide file tree
Showing 9 changed files with 428 additions and 4 deletions.
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ module.exports = {
'@babel/preset-react',
'@babel/preset-typescript',
],
compact: false,
};
3 changes: 3 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default {
clearMocks: true,
collectCoverage: true,
coverageDirectory: "coverage",
coveragePathIgnorePatterns: [
"<rootDir>/src/test/"
],
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/fileTransformer.js',
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
Expand Down
161 changes: 161 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"publishConfig": {
"registry": "https://www.npmjs.com/package/fblibrary-react"
},
},
"main": "dist/bundle.js",
"types": "dist/types/src/index.d.ts",
"scripts": {
Expand Down Expand Up @@ -47,6 +47,7 @@
"typescript": "^5.3.3"
},
"devDependencies": {
"@babel/core": "^7.23.6",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/preset-env": "^7.23.6",
"@babel/preset-react": "^7.23.3",
Expand All @@ -57,13 +58,16 @@
"@rollup/plugin-typescript": "^11.1.5",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^14.1.2",
"babel-jest": "^29.7.0",
"eslint": "^8.56.0",
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-solid": "^0.13.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"jest-junit": "^16.0.0",
"match-media-mock": "^0.1.1",
"node-fetch": "^3.3.2",
"react-app": "^1.1.2",
"rollup": "^2.79.1",
"rollup-plugin-copy": "^3.5.0",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ sonar.sourceEncoding=UTF-8
sonar.exclusions=src/test
sonar.tests=src/test
sonar.test.inclusions=**/*Test.tsx, **/*Test.ts, **/__tests__/**
sonar.coverage.exclusions=**/*Test.*,**/*Tests.*, src/test/**/*
sonar.coverage.exclusions=**/*Test.*,**/*Tests.*, src/test/**/*, src/assets/**/*, src/i18n/**/*, dist/**/*, .github/**/*
4 changes: 2 additions & 2 deletions src/infra/requests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const setTokenAuth = async (headers: Headers): Promise<Headers> => {
return headers;
}

async function makeFetchRequest<T>(params: ServiceParams, method: string): Promise<T | boolean> {
export async function makeFetchRequest<T>(params: ServiceParams, method: string): Promise<T | boolean> {
const { baseUrl, route = '', body, authToken, headers: customHeaders } = params;
const url = method === 'GET' && body ? new URL(baseUrl + route, body) : baseUrl + route;

Expand Down Expand Up @@ -37,7 +37,7 @@ async function makeFetchRequest<T>(params: ServiceParams, method: string): Promi
return false;
}

return method !== 'GET' ? await response.json() as T : true as unknown as T;
return await response.json() as T
} catch (error) {
console.error(`Error in ${method} request:`, error);
return false;
Expand Down
30 changes: 30 additions & 0 deletions src/test/mock/fetchMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const spyMockResponse =((url, options) => {
const method = options?.method || 'GET';

switch (method) {
case 'GET':
return Promise.resolve({
json: () => Promise.resolve({ data: 'test' }),
});

case 'POST':
return Promise.resolve({
json: () => Promise.resolve({ success: true }),
});

case 'PUT':
return Promise.resolve({
json: () => Promise.resolve({ updated: true }),
});

case 'DELETE':
return Promise.resolve({
json: () => Promise.resolve({ deleted: true }),
});

default:
return Promise.reject(new Error('Method not mocked'));
}
});

export default spyMockResponse;
Loading

0 comments on commit dcd29cf

Please sign in to comment.