UNPKG

@yolkai/nx-workspace

Version:

Extensible Dev Tools for Monorepos

172 lines (171 loc) 5.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const project_graph_models_1 = require("./project-graph-models"); const operators_1 = require("./operators"); const graph = { nodes: { 'app1-e2e': { name: 'app1-e2e', type: 'app', data: null }, app1: { name: 'app1', type: 'app', data: null }, lib1: { name: 'lib1', type: 'lib', data: null }, lib2: { name: 'lib2', type: 'lib', data: null }, lib3: { name: 'lib3', type: 'lib', data: null } }, dependencies: { 'app1-e2e': [ { type: project_graph_models_1.DependencyType.implicit, source: 'app1-e2e', target: 'app1' } ], app1: [ { type: project_graph_models_1.DependencyType.static, source: 'app1', target: 'lib1' } ], lib1: [ { type: project_graph_models_1.DependencyType.static, source: 'lib1', target: 'lib2' }, { type: project_graph_models_1.DependencyType.static, source: 'lib1', target: 'lib3' } ], lib2: [ { type: project_graph_models_1.DependencyType.static, source: 'lib2', target: 'lib3' } ] } }; describe('reverse', () => { it('should reverse dependency direction', () => { const result = operators_1.reverse(graph); expect(result).toEqual({ nodes: { 'app1-e2e': { name: 'app1-e2e', type: 'app', data: null }, app1: { name: 'app1', type: 'app', data: null }, lib1: { name: 'lib1', type: 'lib', data: null }, lib2: { name: 'lib2', type: 'lib', data: null }, lib3: { name: 'lib3', type: 'lib', data: null } }, dependencies: { app1: [ { type: project_graph_models_1.DependencyType.implicit, source: 'app1', target: 'app1-e2e' } ], lib1: [ { type: project_graph_models_1.DependencyType.static, source: 'lib1', target: 'app1' } ], lib2: [ { type: project_graph_models_1.DependencyType.static, source: 'lib2', target: 'lib1' } ], lib3: [ { type: project_graph_models_1.DependencyType.static, source: 'lib3', target: 'lib1' }, { type: project_graph_models_1.DependencyType.static, source: 'lib3', target: 'lib2' } ] } }); }); }); describe('withDeps', () => { it('should return a new graph with all dependencies included from original', () => { const affectedNodes = [ { name: 'app1-e2e', type: 'app', data: null }, { name: 'app1', type: 'app', data: null }, { name: 'lib1', type: 'lib', data: null } ]; const result = operators_1.withDeps(graph, affectedNodes); expect(result).toEqual({ nodes: { lib3: { name: 'lib3', type: 'lib', data: null }, lib2: { name: 'lib2', type: 'lib', data: null }, lib1: { name: 'lib1', type: 'lib', data: null }, app1: { name: 'app1', type: 'app', data: null }, 'app1-e2e': { name: 'app1-e2e', type: 'app', data: null } }, dependencies: { lib2: [ { type: 'static', source: 'lib2', target: 'lib3' } ], lib1: [ { type: 'static', source: 'lib1', target: 'lib2' }, { type: 'static', source: 'lib1', target: 'lib3' } ], app1: [ { type: 'static', source: 'app1', target: 'lib1' } ], 'app1-e2e': [ { type: 'implicit', source: 'app1-e2e', target: 'app1' } ] } }); }); });