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/hook tests #130

Merged
merged 11 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
7 changes: 7 additions & 0 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ jobs:

- name: Run package tests
run: pnpm test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
directory: "./packages/graph-explorer/coverage"
files: "*.info"
fail_ci_if_error: true
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules/
packages/graph-explorer-proxy-server/node_modules/
packages/graph-explorer/node_modules/
**/node_modules/
**/coverage/
cubeddu marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 22 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,34 @@
"author": "amazon",
"license": "Apache-2.0",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.41.0",
"concurrently": "^7.5.0",
"eslint": "^7.32.0",
"eslint-plugin-react": "^7.31.10",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"concurrently": "^8.2.0",
"eslint": "^8.43.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.0",
"lint-staged": "^13.0.3",
"prettier": "2.1.2",
"typescript": "^4.8.4"
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"prettier": "2.8.8",
"typescript": "^5.1.3"
},
"lint-staged": {
"*.{ts,tsx}": [
"eslint --fix",
"prettier --write"
]
},
"pnpm": {
"overrides": {
"json5@>=2.0.0 <2.2.2": ">=2.2.2",
"minimatch@<3.0.5": ">=3.0.5",
"loader-utils@>=2.0.0 <2.0.4": ">=2.0.4",
"webpack@>=5.0.0 <5.76.0": ">=5.76.0",
"decode-uri-component@<0.2.1": ">=0.2.1",
"yaml@>=2.0.0-5 <2.2.2": ">=2.2.2",
"vite@>=3.0.2 <3.2.7": ">=3.2.7",
"xml2js@<0.5.0": ">=0.5.0",
"semver@<7.5.2": ">=7.5.2"
}
}
}
1 change: 1 addition & 0 deletions packages/graph-explorer/.npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
auto-install-peers=true
engine-strict=true
public-hoist-pattern[]=*
cubeddu marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 10 additions & 2 deletions packages/graph-explorer/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
module.exports = {
presets: [
"@babel/preset-env",
["@babel/preset-react", { runtime: "automatic" }],
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
'@babel/preset-react',
'@babel/preset-typescript',
],
};
68 changes: 66 additions & 2 deletions packages/graph-explorer/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,73 @@
import type { Config } from "jest";

const config: Config = {
displayName: 'graph-explorer',
verbose: true,
preset: "ts-jest",
testEnvironment: "jsdom",
preset: 'ts-jest',
testEnvironment: 'node',
moduleFileExtensions: [
'js',
'ts',
'tsx',
'json'
],
rootDir: 'src',
testRegex: '.test.ts$',
transformIgnorePatterns: [
"node_modules/(?!(swiper|dom7)/)",
"node_modules/(?!(react-dnd-html5-backend)/)"
],
testPathIgnorePatterns: [
'<rootDir>/node_modules/'
],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/packages/$1/src',
},
coverageDirectory: '../coverage',
collectCoverage: true, // collect coverage info
coverageReporters: [
"lcov",
"text",
"json",
"clover"
],
collectCoverageFrom: [ // collect and exclude files from coverage
"**/*.{ts,tsx}",
"!**/node_modules/**",
"!**/jest.config.js",
"!**/coverage/**",
"!**/reports/**",
"!**/*.styles.ts",
"!**/index.tsx",
"!**/*.types.ts",
"!/src/@types/**",
],
coveragePathIgnorePatterns: [
// These files have not been tested and will cause the coverage report to be incomplete.
'/src/components/utils/canvas/drawImage.ts',
'/src/components/Graph/hooks/useRenderBadges.ts',
'/src/modules/KeywordSearch/toAdvancedList.ts',
'/src/connector/gremlin/GremlinConnector.ts',
'/src/connector/sparql/SPARQLConnector.ts',
'/src/core/ConfigurationProvider/fetchConfiguration.ts',
'/src/core/ConfigurationProvider/isConfiguration.ts',
'/src/core/ConnectorProvider/useConnector.ts',
'/src/core/StateProvider/StateProvider.tsx',
'/src/hooks/useSchemaSync.ts',
'/src/index.tsx',
'/src/@types',
'src/components/Graph/styles',
// These files have not been tested and will cause the coverage report to be incomplete.
],
coverageProvider: "v8",
coverageThreshold: {
global: {
branches: 31,
functions: 14,
lines: 9,
statements: -0,
},
},
};

export default config;
4 changes: 4 additions & 0 deletions packages/graph-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"@babel/core": "^7.19.3",
"@babel/preset-env": "^7.19.4",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.22.5",
"@react-aria/overlays": "3.9.1",
"@react-stately/radio": "^3.5.0",
"@react-types/button": "^3.6.1",
Expand Down Expand Up @@ -131,6 +132,9 @@
"husky": "^8.0.0",
"jest": "^28.1.3",
"jest-environment-jsdom": "^29.0.1",
"jest-github-actions-reporter": "^1.0.3",
"jest-junit": "^16.0.0",
"jest-localstorage-mock": "^2.4.26",
"lint-staged": "^13.0.3",
"prettier": "2.1.2",
"react-test-renderer": "^17.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const fetchNeighbors = async (
rawIds: Map<string, "string" | "number">
): Promise<NeighborsResponse> => {
const idType = rawIds.get(req.vertexId) ?? "string";
const gremlinTemplate = oneHopTemplate({...req, idType});
const gremlinTemplate = oneHopTemplate({ ...req, idType });
const data = await gremlinFetch<RawOneHopRequest>(gremlinTemplate);

const verticesResponse =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ describe("Gremlin > edgesSchemaTemplate", () => {

expect(template).toBe(
'g.E().project("route","contain")' +
'.by(V().bothE("route").limit(1))' +
'.by(V().bothE("contain").limit(1))' +
".limit(1)"
'.by(V().bothE("route").limit(1))' +
'.by(V().bothE("contain").limit(1))' +
".limit(1)"
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import isErrorResponse from './isErrorResponse';

describe('isErrorResponse', () => {
it('should return true for error response', () => {
const errorResponse = {
code: 400,
detailedMessage: 'Detailed error message',
};

expect(isErrorResponse(errorResponse)).toBe(true);
});

it('should return false for non-error response', () => {
const nonErrorResponse = {
status: 200,
message: 'OK',
};

expect(isErrorResponse(nonErrorResponse)).toBe(false);
});

it('should return false for error-like response missing code', () => {
const errorLikeResponse = {
detailedMessage: 'Detailed error message',
};

expect(isErrorResponse(errorLikeResponse)).toBe(false);
});

it('should return false for error-like response missing detailedMessage', () => {
const errorLikeResponse = {
code: 400,
};

expect(isErrorResponse(errorLikeResponse)).toBe(false);
});
});
Loading