Skip to content

Commit

Permalink
HEAT-230 Tidy up and add tests (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrlee authored Apr 8, 2024
1 parent cb14e18 commit 9cc9cdc
Show file tree
Hide file tree
Showing 18 changed files with 565 additions and 103 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ components.json
.env
dist
.eslintcache
test_results/
231 changes: 231 additions & 0 deletions package-lock.json

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

41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,45 @@
"node": "^20",
"npm": "^10"
},
"jest": {
"transform": {
"^.+\\.tsx?$": [
"ts-jest",
{
"isolatedModules": true
}
]
},
"collectCoverageFrom": [
"server/**/*.{ts,js,jsx,mjs}"
],
"testMatch": [
"<rootDir>/(src)/**/?(*.)(cy|test).{ts,js,jsx,mjs}"
],
"testEnvironment": "node",
"reporters": [
"default",
[
"jest-junit",
{
"outputDirectory": "test_results/jest/"
}
],
[
"./node_modules/jest-html-reporter",
{
"outputPath": "test_results/unit-test-reports.html"
}
]
],
"moduleFileExtensions": [
"web.js",
"js",
"json",
"node",
"ts"
]
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@types/superagent": "^8.1.6",
Expand All @@ -44,6 +83,8 @@
"eslint-plugin-prettier": "^5.1.3",
"husky": "^9.0.11",
"jest": "^27.5.1",
"jest-html-reporter": "^3.10.2",
"jest-junit": "^16.0.0",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"ts-jest": "^27.1.3",
Expand Down
21 changes: 15 additions & 6 deletions src/component-node.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import type { Dependency } from './data/ComponentInfo'
import type { Component, Dependency } from './data/Components'
import categorise from './dependency-categoriser'

export default class ComponentNode {
public unknownDependencies: Dependency[] = []

public reliedUponBy: ComponentNode[] = []
public reliedUponBy: Record<string, ComponentNode> = {}

public knownDependencies: Record<string, ComponentNode> = {}

public dependencyCategories: string[] = []

constructor(readonly name: string) {}
constructor(
readonly name: string,
readonly component: Component,
) {}

public addUnknownDependency(dependency: Dependency) {
const category = categorise(dependency)
Expand All @@ -24,12 +27,18 @@ export default class ComponentNode {
}
}

public addDependency(componentName: string) {
public addComponentDependency(componentName: string) {
if (!this.dependencyCategories.includes('HTTP')) {
this.dependencyCategories.push('HTTP')
}
this.knownDependencies[componentName] = undefined
}

public resolveDependency(componentName: string, ref: ComponentNode) {
if (ref) ref.reliedUponBy.push(this)
if (ref) {
// eslint-disable-next-line no-param-reassign
ref.reliedUponBy[this.name] = this
}
this.knownDependencies[componentName] = ref
}

Expand Down Expand Up @@ -58,7 +67,7 @@ export default class ComponentNode {
if (!component.reliedUponBy.length) {
return [path]
}
const result = component.reliedUponBy.flatMap(rel => this.getAllDependentPaths_int(rel, [...path]))
const result = Object.values(component.reliedUponBy).flatMap(rel => this.getAllDependentPaths_int(rel, [...path]))
return result
}

Expand Down
Loading

0 comments on commit 9cc9cdc

Please sign in to comment.