nx/packages/workspace/src/utils/buildable-libs-utils.spec.ts
Miroslav Jonaš 117ee9308a
cleanup(core): use isNpmProject and cleanup project graph utils (#6522)
* cleanup(core): use isNpmProject and cleanup project graph utils

* chore(core): mark utils/buildable-libs-utils as deprecated
2021-07-29 11:17:31 -04:00

89 lines
2.1 KiB
TypeScript

import {
calculateProjectDependencies,
DependentBuildableProjectNode,
updatePaths,
} from './buildable-libs-utils';
import {
DependencyType,
ProjectGraph,
ProjectType,
} from '../core/project-graph';
import { getMockContext } from './testing';
// TODO(v13): remove this deprecated file
describe('updatePaths', () => {
const deps: DependentBuildableProjectNode[] = [
{ name: '@proj/lib', node: {} as any, outputs: ['dist/libs/lib'] },
];
it('should add path', () => {
const paths: Record<string, string[]> = {
'@proj/test': ['libs/test/src/index.ts'],
};
updatePaths(deps, paths);
expect(paths).toEqual({
'@proj/lib': ['dist/libs/lib'],
'@proj/test': ['libs/test/src/index.ts'],
});
});
it('should replace paths', () => {
const paths: Record<string, string[]> = {
'@proj/lib': ['libs/lib/src/index.ts'],
'@proj/lib/sub': ['libs/lib/sub/src/index.ts'],
};
updatePaths(deps, paths);
expect(paths).toEqual({
'@proj/lib': ['dist/libs/lib'],
'@proj/lib/sub': ['dist/libs/lib/sub'],
});
});
});
describe('calculateProjectDependencies', () => {
it('should include npm packages in dependency list', async () => {
const graph: ProjectGraph = {
nodes: {
example: {
type: ProjectType.lib,
name: 'example',
data: {
files: [],
root: '/root/example',
},
},
'npm:formik': {
type: 'npm',
name: 'npm:formik',
data: {
files: [],
packageName: 'formik',
version: '0.0.0',
},
},
},
dependencies: {
example: [
{
source: 'example',
target: 'npm:formik',
type: DependencyType.static,
},
],
},
};
const context = await getMockContext();
context.target.project = 'example';
const results = await calculateProjectDependencies(graph, context);
expect(results).toMatchObject({
target: {
type: ProjectType.lib,
name: 'example',
},
dependencies: [{ name: 'formik' }],
});
});
});