/
update-invalid-import-paths.spec.ts
85 lines (69 loc) · 2.28 KB
/
update-invalid-import-paths.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import type { Tree } from '@nrwl/devkit';
import { updateJson, joinPathFragments, readJson } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import libGenerator from '../../generators/library/library';
import updateInvalidImportPaths from './update-invalid-import-paths';
describe('Migration to fix invalid import paths in affected workspaces', () => {
let tree: Tree;
beforeEach(async () => {
tree = createTreeWithEmptyWorkspace();
// set up some libs
await libGenerator(tree, {
name: 'buildable1',
buildable: true,
directory: 'dir1',
});
await libGenerator(tree, {
name: 'buildable2',
buildable: true,
directory: 'dir1',
});
await libGenerator(tree, {
name: 'publishable1',
publishable: true,
directory: 'dir1',
importPath: '@proj/publishable1',
});
await libGenerator(tree, {
name: 'publishable2',
publishable: true,
directory: 'dir1',
importPath: '@proj/publishable2',
});
// break one of each kind
updateJson(
tree,
joinPathFragments('libs/dir1/buildable1', 'package.json'),
(pkgJson) => {
pkgJson.name = '@proj/dir1-buildable1';
return pkgJson;
}
);
updateJson(tree, 'tsconfig.base.json', (tsconfig) => {
const srcPath = tsconfig['@proj/publishable2'];
tsconfig['@proj/publishable2'] = undefined;
tsconfig['@proj/dir1/publishable2'] = srcPath;
return tsconfig;
});
});
it('should fix the invalid libraries', async () => {
// ACT
await updateInvalidImportPaths(tree);
// ASSERT
const fixedBuildable = readJson(
tree,
joinPathFragments('libs/dir1/buildable1', 'package.json')
);
const { compilerOptions } = readJson<{
compilerOptions: { paths: Record<string, string[]> };
}>(tree, 'tsconfig.base.json');
const { paths: tsConfigPaths } = compilerOptions;
const fixedPublishable = Boolean(tsConfigPaths['@proj/publishable2']);
const brokenPublishableShouldntExist = !Boolean(
tsConfigPaths['@proj/publishable2']
);
expect(fixedBuildable.name).toEqual('@proj/dir1/buildable1');
expect(fixedPublishable).toBeTruthy();
expect(brokenPublishableShouldntExist).toBeFalsy();
});
});