-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathindex_spec.ts
129 lines (107 loc) · 3.76 KB
/
index_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* @license
* Copyright Google Inc. 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 { Architect } from '@angular-devkit/architect';
import { WorkspaceNodeModulesArchitectHost } from '@angular-devkit/architect/node';
import { TestProjectHost, TestingArchitectHost } from '@angular-devkit/architect/testing';
import {
getSystemPath,
join,
normalize,
schema,
virtualFs,
workspaces,
} from '@angular-devkit/core'; // tslint:disable-line:no-implicit-dependencies
import { map, take, tap } from 'rxjs/operators';
// Default timeout for large specs is 2.5 minutes.
jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;
// This flag controls whether AOT compilation uses Ivy or View Engine (VE).
export let veEnabled = process.argv.some(arg => arg == 'view_engine');
export const workspaceRoot = join(normalize(__dirname), `../../test/ng-packaged/`);
describe('NgPackagr Builder', () => {
const host = new TestProjectHost(workspaceRoot);
let architect: Architect;
beforeEach(async () => {
await host.initialize().toPromise();
const registry = new schema.CoreSchemaRegistry();
registry.addPostTransform(schema.transforms.addUndefinedDefaults);
const workspaceSysPath = getSystemPath(host.root());
const { workspace } = await workspaces.readWorkspace(
workspaceSysPath,
workspaces.createWorkspaceHost(host),
);
const architectHost = new TestingArchitectHost(
workspaceSysPath,
workspaceSysPath,
new WorkspaceNodeModulesArchitectHost(workspace, workspaceSysPath),
);
architect = new Architect(architectHost, registry);
// Set AOT compilation to use VE if needed.
if (veEnabled) {
host.replaceInFile('tsconfig.json', `"enableIvy": true,`, `"enableIvy": false,`);
}
});
afterEach(() => host.restore().toPromise());
it('builds and packages a library', async () => {
const run = await architect.scheduleTarget({ project: 'lib', target: 'build' });
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));
await run.stop();
expect(host.scopedSync().exists(normalize('./dist/lib/fesm2015/lib.js'))).toBe(true);
const content = virtualFs.fileBufferToString(
host.scopedSync().read(normalize('./dist/lib/fesm2015/lib.js')),
);
expect(content).toContain('lib works');
if (veEnabled) {
expect(content).not.toContain('ɵcmp');
} else {
expect(content).toContain('ɵcmp');
}
});
it('rebuilds on TS file changes', async () => {
const goldenValueFiles: { [path: string]: string } = {
'projects/lib/src/lib/lib.component.ts': `
import { Component } from '@angular/core';
@Component({
selector: 'lib',
template: 'lib update works!'
})
export class LibComponent { }
`,
};
const run = await architect.scheduleTarget(
{ project: 'lib', target: 'build' },
{ watch: true },
);
let buildNumber = 0;
await run.output.pipe(
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
map(() => {
const fileName = './dist/lib/fesm2015/lib.js';
const content = virtualFs.fileBufferToString(
host.scopedSync().read(normalize(fileName)),
);
return content;
}),
tap(content => {
buildNumber += 1;
switch (buildNumber) {
case 1:
expect(content).toMatch(/lib works/);
host.writeMultipleFiles(goldenValueFiles);
break;
case 2:
expect(content).toMatch(/lib update works/);
break;
default:
break;
}
}),
take(2),
).toPromise();
await run.stop();
});
});