Skip to content

Commit

Permalink
fix: flatten seems to work
Browse files Browse the repository at this point in the history
  • Loading branch information
bodinsamuel committed May 3, 2023
1 parent 18781a0 commit 9d4f100
Show file tree
Hide file tree
Showing 7 changed files with 524 additions and 50 deletions.
228 changes: 199 additions & 29 deletions src/analyser/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,105 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`techAnalyser > should register only component of the same tech 1`] = `
{
"childs": [
{
"childs": [],
"dependencies": [
[
"docker",
"postgres",
"15.1-alpine",
],
],
"edges": [],
"group": "component",
"id": "",
"inComponent": null,
"languages": {},
"name": "db",
"path": [
"/docker-compose.yml",
"/package.json",
],
"tech": "postgresql",
"techs": [
"postgresql",
],
},
{
"childs": [],
"dependencies": [
[
"npm",
"pg",
"1.0.0",
],
],
"edges": [
{
"portSource": "right",
"portTarget": "left",
"read": true,
"to": "",
"vertices": [],
"write": true,
},
],
"group": "component",
"id": "",
"inComponent": null,
"languages": {
"JSON": 1,
"YAML": 1,
},
"name": "test",
"path": [
"/package.json",
],
"tech": null,
"techs": [
"docker",
"nodejs",
"postgresql",
],
},
],
"dependencies": [
[
"docker",
"postgres",
"15.1-alpine",
],
[
"npm",
"pg",
"1.0.0",
],
],
"edges": [],
"group": "component",
"id": "",
"inComponent": null,
"languages": {
"JSON": 1,
"YAML": 1,
},
"name": "flatten",
"path": [
"/",
"/docker-compose.yml",
"/package.json",
],
"tech": null,
"techs": [
"docker",
"nodejs",
"postgresql",
],
}
`;

exports[`techAnalyser > should run correctly 1`] = `
{
"childs": [
Expand Down Expand Up @@ -27,8 +127,29 @@ exports[`techAnalyser > should run correctly 1`] = `
{
"childs": [
{
"childs": [],
"childs": [
{
"childs": [],
"dependencies": [],
"edges": [],
"group": "thirdparty",
"id": "",
"inComponent": null,
"languages": {},
"name": "datadog",
"path": [
"/pkgs/api/package.json",
],
"tech": "datadog",
"techs": [],
},
],
"dependencies": [
[
"npm",
"dd-trace",
"1.0.1",
],
[
"npm",
"fastify",
Expand All @@ -45,7 +166,16 @@ exports[`techAnalyser > should run correctly 1`] = `
"5.0.4",
],
],
"edges": [],
"edges": [
{
"portSource": "right",
"portTarget": "left",
"read": true,
"to": "",
"vertices": [],
"write": true,
},
],
"group": "component",
"id": "",
"inComponent": null,
Expand All @@ -58,6 +188,7 @@ exports[`techAnalyser > should run correctly 1`] = `
],
"tech": null,
"techs": [
"datadog",
"fastify",
"nodejs",
"prisma",
Expand Down Expand Up @@ -285,6 +416,11 @@ exports[`techAnalyser > should run correctly 2`] = `
{
"childs": [],
"dependencies": [
[
"npm",
"dd-trace",
"1.0.1",
],
[
"npm",
"fastify",
Expand All @@ -301,7 +437,16 @@ exports[`techAnalyser > should run correctly 2`] = `
"5.0.4",
],
],
"edges": [],
"edges": [
{
"portSource": "right",
"portTarget": "left",
"read": true,
"to": "",
"vertices": [],
"write": true,
},
],
"group": "component",
"id": "",
"inComponent": null,
Expand All @@ -314,6 +459,7 @@ exports[`techAnalyser > should run correctly 2`] = `
],
"tech": null,
"techs": [
"datadog",
"fastify",
"nodejs",
"prisma",
Expand Down Expand Up @@ -344,7 +490,16 @@ exports[`techAnalyser > should run correctly 2`] = `
"4.3.3",
],
],
"edges": [],
"edges": [
{
"portSource": "right",
"portTarget": "left",
"read": true,
"to": "",
"vertices": [],
"write": true,
},
],
"group": "component",
"id": "",
"inComponent": "",
Expand Down Expand Up @@ -389,6 +544,21 @@ exports[`techAnalyser > should run correctly 2`] = `
"tech": "gcp",
"techs": [],
},
{
"childs": [],
"dependencies": [],
"edges": [],
"group": "thirdparty",
"id": "",
"inComponent": null,
"languages": {},
"name": "datadog",
"path": [
"/pkgs/api/package.json",
],
"tech": "datadog",
"techs": [],
},
{
"childs": [],
"dependencies": [
Expand Down Expand Up @@ -445,7 +615,9 @@ exports[`techAnalyser > should run correctly 2`] = `
"inComponent": null,
"languages": {
"HCL": 1,
"JSON": 1,
"HTML": 1,
"JSON": 3,
"SCSS": 1,
"YAML": 1,
},
"name": "fake",
Expand All @@ -462,21 +634,6 @@ exports[`techAnalyser > should run correctly 2`] = `
"typescript",
],
},
{
"childs": [],
"dependencies": [],
"edges": [],
"group": "component",
"id": "",
"inComponent": null,
"languages": {},
"name": "main",
"path": [
"/",
],
"tech": null,
"techs": [],
},
{
"childs": [],
"dependencies": [
Expand Down Expand Up @@ -539,7 +696,9 @@ exports[`techAnalyser > should run correctly 2`] = `
"/terraform/.terraform.lock.hcl",
],
"tech": "vercel",
"techs": [],
"techs": [
"vercel",
],
},
],
"dependencies": [
Expand All @@ -558,6 +717,11 @@ exports[`techAnalyser > should run correctly 2`] = `
"unknown",
"7.17.5",
],
[
"npm",
"dd-trace",
"1.0.1",
],
[
"npm",
"fastify",
Expand All @@ -573,6 +737,11 @@ exports[`techAnalyser > should run correctly 2`] = `
"typescript",
"5.0.4",
],
[
"terraform",
"registry.terraform.io/vercel/vercel",
"4.61.0",
],
[
"npm",
"@fake/api",
Expand All @@ -598,11 +767,6 @@ exports[`techAnalyser > should run correctly 2`] = `
"registry.terraform.io/hashicorp/google",
"4.61.0",
],
[
"terraform",
"registry.terraform.io/vercel/vercel",
"4.61.0",
],
[
"npm",
"@typescript-eslint/eslint-plugin",
Expand Down Expand Up @@ -635,17 +799,23 @@ exports[`techAnalyser > should run correctly 2`] = `
"inComponent": null,
"languages": {
"HCL": 1,
"HTML": 1,
"JSON": 3,
"SCSS": 1,
"HTML": 2,
"JSON": 5,
"SCSS": 2,
"YAML": 1,
},
"name": "flatten",
"path": [
"/",
"/docker-compose.yml",
"/pkgs/api/package.json",
"/pkgs/app/package.json",
"/terraform/.terraform.lock.hcl",
"/package.json",
],
"tech": null,
"techs": [
"datadog",
"docker",
"eslint",
"fastify",
Expand Down
11 changes: 11 additions & 0 deletions src/analyser/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ describe('techAnalyser', () => {
expect(cleanSnapshot(res.toJson())).toMatchSnapshot();

const flatted = flatten(res);

// Check that inComponent was updated
const vercel = flatted.childs.find((child) => child.name === 'vercel')!;
const app = flatted.childs.find((child) => child.name === '@fake/app');
expect(app!.inComponent!.id).toBe(vercel.id);

// Check that edge.to was updated
const datadog = flatted.childs.find((child) => child.name === 'datadog')!;
const api = flatted.childs.find((child) => child.name === '@fake/api');
expect(api!.edges[0].to.id).toBe(datadog.id);

expect(
cleanSnapshot(JSON.parse(JSON.stringify(flatted.toJson())))
).toMatchSnapshot();
Expand Down
Loading

0 comments on commit 9d4f100

Please sign in to comment.