5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
-
9
- import { TargetSpecifier } from '@angular-devkit/architect' ;
10
- import { TestProjectHost , runTargetSpec } from '@angular-devkit/architect/testing' ;
11
- import { join , normalize , virtualFs } from '@angular-devkit/core' ;
12
- import { debounceTime , map , take , tap } from 'rxjs/operators' ;
13
-
14
- const devkitRoot = normalize ( ( global as any ) . _DevKitRoot ) ; // tslint:disable-line:no-any
15
- const workspaceRoot = join ( devkitRoot , 'tests/angular_devkit/build_ng_packagr/ng-packaged/' ) ;
16
- export const host = new TestProjectHost ( workspaceRoot ) ;
8
+ import { WorkspaceNodeModulesArchitectHost } from '@angular-devkit/architect/node' ;
9
+ import { Architect } from '@angular-devkit/architect/src/index2' ;
10
+ import { TestProjectHost } from '@angular-devkit/architect/testing' ;
11
+ import { TestingArchitectHost } from '@angular-devkit/architect/testing/testing-architect-host' ;
12
+ import { experimental , join , normalize , schema , virtualFs } from '@angular-devkit/core' ;
13
+ import { map , take , tap } from 'rxjs/operators' ;
14
+
15
+ const devkitRoot = ( global as unknown as { _DevKitRoot : string } ) . _DevKitRoot ;
16
+ const workspaceRoot = join (
17
+ normalize ( devkitRoot ) ,
18
+ 'tests/angular_devkit/build_ng_packagr/ng-packaged/' ,
19
+ ) ;
17
20
18
21
describe ( 'NgPackagr Builder' , ( ) => {
19
- beforeEach ( done => host . initialize ( ) . toPromise ( ) . then ( done , done . fail ) ) ;
20
- afterEach ( done => host . restore ( ) . toPromise ( ) . then ( done , done . fail ) ) ;
21
-
22
- it ( 'works' , ( done ) => {
23
- const targetSpec : TargetSpecifier = { project : 'lib' , target : 'build' } ;
24
-
25
- runTargetSpec ( host , targetSpec ) . pipe (
26
- tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( true ) ) ,
27
- ) . toPromise ( ) . then ( done , done . fail ) ;
22
+ const host = new TestProjectHost ( workspaceRoot ) ;
23
+ let architect : Architect ;
24
+
25
+ beforeEach ( async ( ) => {
26
+ await host . initialize ( ) . toPromise ( ) ;
27
+
28
+ const registry = new schema . CoreSchemaRegistry ( ) ;
29
+ registry . addPostTransform ( schema . transforms . addUndefinedDefaults ) ;
30
+
31
+ const workspace = await experimental . workspace . Workspace . fromPath ( host , host . root ( ) , registry ) ;
32
+ const architectHost = new TestingArchitectHost (
33
+ host . root ( ) ,
34
+ host . root ( ) ,
35
+ new WorkspaceNodeModulesArchitectHost ( workspace , host . root ( ) ) ,
36
+ ) ;
37
+ architect = new Architect ( architectHost , registry ) ;
28
38
} ) ;
29
39
30
- it ( 'tests works' , ( done ) => {
31
- const targetSpec : TargetSpecifier = { project : 'lib' , target : 'test' } ;
40
+ afterEach ( ( ) => host . restore ( ) . toPromise ( ) ) ;
32
41
33
- runTargetSpec ( host , targetSpec ) . pipe (
34
- tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( true ) ) ,
35
- ) . toPromise ( ) . then ( done , done . fail ) ;
36
- } ) ;
42
+ it ( 'builds and packages a library' , async ( ) => {
43
+ const run = await architect . scheduleTarget ( { project : 'lib' , target : 'build' } ) ;
37
44
38
- it ( 'lint works' , ( done ) => {
39
- const targetSpec : TargetSpecifier = { project : 'lib' , target : 'lint' } ;
45
+ await expectAsync ( run . result ) . toBeResolvedTo ( jasmine . objectContaining ( { success : true } ) ) ;
40
46
41
- runTargetSpec ( host , targetSpec ) . pipe (
42
- tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( true ) ) ,
43
- ) . toPromise ( ) . then ( done , done . fail ) ;
44
- } ) ;
47
+ await run . stop ( ) ;
45
48
46
- it ( 'rebuilds on TS file changes' , ( done ) => {
47
- const targetSpec : TargetSpecifier = { project : 'lib' , target : 'build' } ;
49
+ expect ( host . scopedSync ( ) . exists ( normalize ( './dist/lib/fesm5/lib.js' ) ) ) . toBe ( true ) ;
50
+ const content = virtualFs . fileBufferToString (
51
+ host . scopedSync ( ) . read ( normalize ( './dist/lib/fesm5/lib.js' ) ) ,
52
+ ) ;
53
+ expect ( content ) . toContain ( 'lib works' ) ;
54
+ } ) ;
48
55
56
+ it ( 'rebuilds on TS file changes' , async ( ) => {
49
57
const goldenValueFiles : { [ path : string ] : string } = {
50
58
'projects/lib/src/lib/lib.component.ts' : `
51
59
import { Component } from '@angular/core';
@@ -58,16 +66,14 @@ describe('NgPackagr Builder', () => {
58
66
` ,
59
67
} ;
60
68
61
- const overrides = { watch : true } ;
69
+ const run = await architect . scheduleTarget (
70
+ { project : 'lib' , target : 'build' } ,
71
+ { watch : true } ,
72
+ ) ;
62
73
63
74
let buildNumber = 0 ;
64
75
65
- runTargetSpec ( host , targetSpec , overrides )
66
- . pipe (
67
- // We must debounce on watch mode because file watchers are not very accurate.
68
- // Changes from just before a process runs can be picked up and cause rebuilds.
69
- // In this case, cleanup from the test right before this one causes a few rebuilds.
70
- debounceTime ( 1000 ) ,
76
+ await run . output . pipe (
71
77
tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( true ) ) ,
72
78
map ( ( ) => {
73
79
const fileName = './dist/lib/fesm5/lib.js' ;
@@ -93,8 +99,8 @@ describe('NgPackagr Builder', () => {
93
99
}
94
100
} ) ,
95
101
take ( 2 ) ,
96
- )
97
- . toPromise ( )
98
- . then ( done , done . fail ) ;
102
+ ) . toPromise ( ) ;
103
+
104
+ await run . stop ( ) ;
99
105
} ) ;
100
106
} ) ;
0 commit comments