/
remove-platform-server-exports_spec.ts
85 lines (71 loc) · 3.06 KB
/
remove-platform-server-exports_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
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { EmptyTree } from '@angular-devkit/schematics';
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
describe('Migration to delete platform-server exports', () => {
const schematicName = 'remove-platform-server-exports';
const schematicRunner = new SchematicTestRunner(
'migrations',
require.resolve('../migration-collection.json'),
);
let tree: EmptyTree;
beforeEach(() => {
tree = new EmptyTree();
});
const testTypeScriptFilePath = './test.ts';
describe(`Migration to remove '@angular/platform-server' exports`, () => {
it(`should delete '@angular/platform-server' export when 'renderModule' is the only exported symbol`, async () => {
tree.create(
testTypeScriptFilePath,
`
import { Path, join } from '@angular-devkit/core';
export { renderModule } from '@angular/platform-server';
`,
);
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
const content = newTree.readText(testTypeScriptFilePath);
expect(content).not.toContain('@angular/platform-server');
expect(content).toContain(`import { Path, join } from '@angular-devkit/core';`);
});
it(`should delete only 'renderModule' when there are additional exports`, async () => {
tree.create(
testTypeScriptFilePath,
`
import { Path, join } from '@angular-devkit/core';
export { renderModule, ServerModule } from '@angular/platform-server';
`,
);
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
const content = newTree.readContent(testTypeScriptFilePath);
expect(content).toContain(`import { Path, join } from '@angular-devkit/core';`);
expect(content).toContain(`export { ServerModule } from '@angular/platform-server';`);
});
it(`should not delete 'renderModule' when it's exported from another module`, async () => {
tree.create(
testTypeScriptFilePath,
`
export { renderModule } from '@angular/core';
`,
);
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
const content = newTree.readText(testTypeScriptFilePath);
expect(content).toContain(`export { renderModule } from '@angular/core';`);
});
it(`should not delete 'renderModule' when it's imported from '@angular/platform-server'`, async () => {
tree.create(
testTypeScriptFilePath,
`
import { renderModule } from '@angular/platform-server';
`,
);
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
const content = newTree.readText(testTypeScriptFilePath);
expect(content).toContain(`import { renderModule } from '@angular/platform-server'`);
});
});
});