Skip to content

Commit

Permalink
tests: mock id to be able to track them correctly, fix missing combin…
Browse files Browse the repository at this point in the history
…e top in flatten
  • Loading branch information
bodinsamuel committed May 3, 2023
1 parent 9d4f100 commit f4d0f3a
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 72 deletions.
124 changes: 87 additions & 37 deletions src/analyser/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports[`techAnalyser > should register only component of the same tech 1`] = `
],
"edges": [],
"group": "component",
"id": "",
"id": "3",
"inComponent": null,
"languages": {},
"name": "db",
Expand All @@ -41,13 +41,13 @@ exports[`techAnalyser > should register only component of the same tech 1`] = `
"portSource": "right",
"portTarget": "left",
"read": true,
"to": "",
"to": "3",
"vertices": [],
"write": true,
},
],
"group": "component",
"id": "",
"id": "4",
"inComponent": null,
"languages": {
"JSON": 1,
Expand Down Expand Up @@ -76,14 +76,24 @@ exports[`techAnalyser > should register only component of the same tech 1`] = `
"pg",
"1.0.0",
],
[
"docker",
"postgres",
"15.1-alpine",
],
[
"npm",
"pg",
"1.0.0",
],
],
"edges": [],
"group": "component",
"id": "",
"id": "6",
"inComponent": null,
"languages": {
"JSON": 1,
"YAML": 1,
"JSON": 2,
"YAML": 2,
},
"name": "flatten",
"path": [
Expand Down Expand Up @@ -114,7 +124,7 @@ exports[`techAnalyser > should run correctly 1`] = `
],
"edges": [],
"group": "component",
"id": "",
"id": "9",
"inComponent": null,
"languages": {},
"name": "db",
Expand All @@ -133,7 +143,7 @@ exports[`techAnalyser > should run correctly 1`] = `
"dependencies": [],
"edges": [],
"group": "thirdparty",
"id": "",
"id": "14",
"inComponent": null,
"languages": {},
"name": "datadog",
Expand Down Expand Up @@ -171,13 +181,13 @@ exports[`techAnalyser > should run correctly 1`] = `
"portSource": "right",
"portTarget": "left",
"read": true,
"to": "",
"to": "14",
"vertices": [],
"write": true,
},
],
"group": "component",
"id": "",
"id": "13",
"inComponent": null,
"languages": {
"JSON": 1,
Expand All @@ -202,7 +212,7 @@ exports[`techAnalyser > should run correctly 1`] = `
"dependencies": [],
"edges": [],
"group": "hosting",
"id": "",
"id": "16",
"inComponent": null,
"languages": {},
"name": "vercel",
Expand Down Expand Up @@ -237,8 +247,8 @@ exports[`techAnalyser > should run correctly 1`] = `
],
"edges": [],
"group": "component",
"id": "",
"inComponent": "",
"id": "15",
"inComponent": "16",
"languages": {
"HTML": 1,
"JSON": 1,
Expand Down Expand Up @@ -270,7 +280,7 @@ exports[`techAnalyser > should run correctly 1`] = `
],
"edges": [],
"group": "hosting",
"id": "",
"id": "18",
"inComponent": null,
"languages": {},
"name": "GCP",
Expand All @@ -291,7 +301,7 @@ exports[`techAnalyser > should run correctly 1`] = `
],
"edges": [],
"group": "hosting",
"id": "",
"id": "19",
"inComponent": null,
"languages": {},
"name": "Vercel",
Expand Down Expand Up @@ -331,7 +341,7 @@ exports[`techAnalyser > should run correctly 1`] = `
],
"edges": [],
"group": "component",
"id": "",
"id": "12",
"inComponent": null,
"languages": {
"HCL": 1,
Expand Down Expand Up @@ -363,7 +373,7 @@ exports[`techAnalyser > should run correctly 1`] = `
],
"edges": [],
"group": "component",
"id": "",
"id": "10",
"inComponent": null,
"languages": {},
"name": "redis",
Expand All @@ -384,7 +394,7 @@ exports[`techAnalyser > should run correctly 1`] = `
],
"edges": [],
"group": "component",
"id": "",
"id": "11",
"inComponent": null,
"languages": {},
"name": "unknown",
Expand All @@ -398,7 +408,7 @@ exports[`techAnalyser > should run correctly 1`] = `
"dependencies": [],
"edges": [],
"group": "component",
"id": "",
"id": "7",
"inComponent": null,
"languages": {},
"name": "main",
Expand Down Expand Up @@ -442,13 +452,13 @@ exports[`techAnalyser > should run correctly 2`] = `
"portSource": "right",
"portTarget": "left",
"read": true,
"to": "",
"to": "14",
"vertices": [],
"write": true,
},
],
"group": "component",
"id": "",
"id": "13",
"inComponent": null,
"languages": {
"JSON": 1,
Expand Down Expand Up @@ -495,14 +505,14 @@ exports[`techAnalyser > should run correctly 2`] = `
"portSource": "right",
"portTarget": "left",
"read": true,
"to": "",
"to": "13",
"vertices": [],
"write": true,
},
],
"group": "component",
"id": "",
"inComponent": "",
"id": "15",
"inComponent": "16",
"languages": {
"HTML": 1,
"JSON": 1,
Expand Down Expand Up @@ -534,7 +544,7 @@ exports[`techAnalyser > should run correctly 2`] = `
],
"edges": [],
"group": "hosting",
"id": "",
"id": "18",
"inComponent": null,
"languages": {},
"name": "GCP",
Expand All @@ -549,7 +559,7 @@ exports[`techAnalyser > should run correctly 2`] = `
"dependencies": [],
"edges": [],
"group": "thirdparty",
"id": "",
"id": "14",
"inComponent": null,
"languages": {},
"name": "datadog",
Expand All @@ -570,7 +580,7 @@ exports[`techAnalyser > should run correctly 2`] = `
],
"edges": [],
"group": "component",
"id": "",
"id": "9",
"inComponent": null,
"languages": {},
"name": "db",
Expand Down Expand Up @@ -611,7 +621,7 @@ exports[`techAnalyser > should run correctly 2`] = `
],
"edges": [],
"group": "component",
"id": "",
"id": "12",
"inComponent": null,
"languages": {
"HCL": 1,
Expand Down Expand Up @@ -645,7 +655,7 @@ exports[`techAnalyser > should run correctly 2`] = `
],
"edges": [],
"group": "component",
"id": "",
"id": "10",
"inComponent": null,
"languages": {},
"name": "redis",
Expand All @@ -666,7 +676,7 @@ exports[`techAnalyser > should run correctly 2`] = `
],
"edges": [],
"group": "component",
"id": "",
"id": "11",
"inComponent": null,
"languages": {},
"name": "unknown",
Expand All @@ -687,7 +697,7 @@ exports[`techAnalyser > should run correctly 2`] = `
],
"edges": [],
"group": "hosting",
"id": "",
"id": "16",
"inComponent": null,
"languages": {},
"name": "vercel",
Expand Down Expand Up @@ -792,17 +802,57 @@ exports[`techAnalyser > should run correctly 2`] = `
"typescript",
"4.9.5",
],
[
"docker",
"postgres",
"14.5-alpine",
],
[
"docker",
"redis",
"7.0.4-alpine",
],
[
"docker",
"unknown",
"7.17.5",
],
[
"npm",
"@typescript-eslint/eslint-plugin",
"5.57.1",
],
[
"npm",
"@typescript-eslint/parser",
"5.57.1",
],
[
"npm",
"eslint",
"8.39.0",
],
[
"npm",
"prettier",
"2.8.7",
],
[
"npm",
"typescript",
"4.9.5",
],
],
"edges": [],
"group": "component",
"id": "",
"id": "20",
"inComponent": null,
"languages": {
"HCL": 1,
"HTML": 2,
"JSON": 5,
"SCSS": 2,
"YAML": 1,
"HCL": 2,
"HTML": 3,
"JSON": 8,
"SCSS": 3,
"YAML": 2,
},
"name": "flatten",
"path": [
Expand Down
23 changes: 13 additions & 10 deletions src/analyser/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import path from 'node:path';

import { describe, it, expect } from 'vitest';
import { describe, it, expect, vi, beforeEach } from 'vitest';

import { flatten } from '../payload/helpers';
import { FakeProvider } from '../provider/fake';
import { FSProvider } from '../provider/fs';
import { cleanSnapshot } from '../tests/helpers';
import type { TechAnalyser } from '../types';

import { techAnalyser } from '.';
Expand All @@ -21,7 +20,16 @@ services:
- POSTGRES_PASSWORD=postgres
`;

let id = 0;
vi.mock('../common/nid.ts', () => {
return { nid: () => `${id++}` };
});

describe('techAnalyser', () => {
beforeEach(() => {
vi.resetAllMocks();
});

it('should not find anything', async () => {
const res = await techAnalyser({
provider: new FakeProvider({
Expand Down Expand Up @@ -61,10 +69,7 @@ describe('techAnalyser', () => {
});

const flat = flatten(res);
const json: TechAnalyser = cleanSnapshot(
JSON.parse(JSON.stringify(flat.toJson()))
);

const json: TechAnalyser = JSON.parse(JSON.stringify(flat.toJson()));
expect(json).toMatchSnapshot();
expect(flat.childs[0].id).toEqual(flat.childs[1].edges[0].to.id);
});
Expand All @@ -76,7 +81,7 @@ describe('techAnalyser', () => {
}),
});

expect(cleanSnapshot(res.toJson())).toMatchSnapshot();
expect(res.toJson()).toMatchSnapshot();

const flatted = flatten(res);

Expand All @@ -90,8 +95,6 @@ describe('techAnalyser', () => {
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();
expect(JSON.parse(JSON.stringify(flatted.toJson()))).toMatchSnapshot();
});
});
1 change: 1 addition & 0 deletions src/payload/__snapshots__/helpers.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ exports[`flatten > should flatten 1`] = `
"name": "flatten",
"path": [
"/",
"",
],
"tech": null,
"techs": [],
Expand Down
2 changes: 2 additions & 0 deletions src/payload/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ export function flatten(src: Payload): Payload {
dest.combine(child);
});

dest.combine(src);

// for (let index = 0; index < dest.childs.length; index++) {
// const child = dest.childs[index];

Expand Down
Loading

0 comments on commit f4d0f3a

Please sign in to comment.