66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import { runTargetSpec } from '@angular-devkit/architect/testing ' ;
9+ import { Architect } from '@angular-devkit/architect/src/index2 ' ;
1010import { join , normalize , virtualFs } from '@angular-devkit/core' ;
1111import { take , tap } from 'rxjs/operators' ;
12- import { BuildWebpackServerSchema } from '../../src/server/schema' ;
13- import { host } from '../utils' ;
12+ import { BrowserBuilderOutput } from '../../src/browser/index2' ;
13+ import { Schema as BuildWebpackServerSchema } from '../../src/server/schema' ;
14+ import { createArchitect , host } from '../utils' ;
1415
1516
1617describe ( 'Server Builder' , ( ) => {
17- const outputPath = normalize ( 'dist-server' ) ;
18+ const target = { project : 'app' , target : 'server' } ;
19+ let architect : Architect ;
1820
19- beforeEach ( done => host . initialize ( ) . toPromise ( ) . then ( done , done . fail ) ) ;
20- afterEach ( done => host . restore ( ) . toPromise ( ) . then ( done , done . fail ) ) ;
21+ beforeEach ( async ( ) => {
22+ await host . initialize ( ) . toPromise ( ) ;
23+ architect = ( await createArchitect ( host . root ( ) ) ) . architect ;
24+ } ) ;
25+ afterEach ( async ( ) => host . restore ( ) . toPromise ( ) ) ;
2126
22- it ( 'works (base)' , ( done ) => {
23- const overrides = { } ;
27+ const outputPath = normalize ( 'dist-server' ) ;
2428
25- runTargetSpec ( host , { project : 'app' , target : 'server' } , overrides ) . pipe (
26- tap ( ( buildEvent ) => {
27- expect ( buildEvent . success ) . toBe ( true ) ;
29+ it ( 'works (base)' , async ( ) => {
30+ const run = await architect . scheduleTarget ( target ) ;
31+ const output = await run . result as BrowserBuilderOutput ;
32+ expect ( output . success ) . toBe ( true ) ;
2833
29- const fileName = join ( outputPath , 'main.js' ) ;
30- const content = virtualFs . fileBufferToString ( host . scopedSync ( ) . read ( normalize ( fileName ) ) ) ;
31- expect ( content ) . toMatch ( / A p p S e r v e r M o d u l e N g F a c t o r y / ) ;
32- } ) ,
33- ) . toPromise ( ) . then ( done , done . fail ) ;
34+ const fileName = join ( outputPath , 'main.js' ) ;
35+ const content = virtualFs . fileBufferToString ( host . scopedSync ( ) . read ( normalize ( fileName ) ) ) ;
36+ expect ( content ) . toMatch ( / A p p S e r v e r M o d u l e N g F a c t o r y / ) ;
37+
38+ await run . stop ( ) ;
3439 } ) ;
3540
36- it ( 'supports sourcemaps' , ( done ) => {
41+ it ( 'supports sourcemaps' , async ( ) => {
3742 const overrides = { sourceMap : true } ;
3843
39- runTargetSpec ( host , { project : 'app' , target : 'server' } , overrides ) . pipe (
40- tap ( ( buildEvent ) => {
41- expect ( buildEvent . success ) . toBe ( true ) ;
44+ const run = await architect . scheduleTarget ( target , overrides ) ;
45+ const output = await run . result as BrowserBuilderOutput ;
46+ expect ( output . success ) . toBe ( true ) ;
4247
43- const fileName = join ( outputPath , 'main.js' ) ;
44- const content = virtualFs . fileBufferToString ( host . scopedSync ( ) . read ( normalize ( fileName ) ) ) ;
45- expect ( content ) . toMatch ( / A p p S e r v e r M o d u l e N g F a c t o r y / ) ;
46- expect ( host . scopedSync ( ) . exists ( join ( outputPath , 'main.js.map' ) ) ) . toBeTruthy ( ) ;
47- } ) ,
48- ) . toPromise ( ) . then ( done , done . fail ) ;
48+ const fileName = join ( outputPath , 'main.js' ) ;
49+ const content = virtualFs . fileBufferToString ( host . scopedSync ( ) . read ( normalize ( fileName ) ) ) ;
50+ expect ( content ) . toMatch ( / A p p S e r v e r M o d u l e N g F a c t o r y / ) ;
51+ expect ( host . scopedSync ( ) . exists ( join ( outputPath , 'main.js.map' ) ) ) . toBeTruthy ( ) ;
52+
53+ await run . stop ( ) ;
4954 } ) ;
5055
51- it ( 'supports scripts only sourcemaps' , ( done ) => {
52- const overrides : Partial < BuildWebpackServerSchema > = {
56+ it ( 'supports scripts only sourcemaps' , async ( ) => {
57+ host . writeMultipleFiles ( {
58+ 'src/app/app.component.css' : `p { color: red; }` ,
59+ } ) ;
60+
61+ const run = await architect . scheduleTarget ( target , {
5362 sourceMap : {
5463 styles : false ,
5564 scripts : true ,
5665 } ,
57- } ;
58-
59- host . writeMultipleFiles ( {
60- 'src/app/app.component.css' : `p { color: red; }` ,
6166 } ) ;
67+ const output = await run . result as BrowserBuilderOutput ;
68+ expect ( output . success ) . toBe ( true ) ;
6269
63- runTargetSpec ( host , { project : 'app' , target : 'server' } , overrides ) . pipe (
64- tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( true ) ) ,
65- tap ( ( ) => {
66- expect ( host . scopedSync ( ) . exists ( join ( outputPath , 'main.js.map' ) ) ) . toBe ( true ) ;
70+ expect ( host . scopedSync ( ) . exists ( join ( outputPath , 'main.js.map' ) ) ) . toBe ( true ) ;
6771
68- const scriptContent = virtualFs . fileBufferToString (
69- host . scopedSync ( ) . read ( join ( outputPath , 'main.js' ) ) ,
70- ) ;
71- expect ( scriptContent ) . toContain ( 'sourceMappingURL=main.js.map' ) ;
72- expect ( scriptContent ) . not . toContain ( 'sourceMappingURL=data:application/json' ) ;
73- } ) ,
74- ) . toPromise ( ) . then ( done , done . fail ) ;
75- } ) ;
72+ const scriptContent = virtualFs . fileBufferToString (
73+ host . scopedSync ( ) . read ( join ( outputPath , 'main.js' ) ) ,
74+ ) ;
75+ expect ( scriptContent ) . toContain ( 'sourceMappingURL=main.js.map' ) ;
76+ expect ( scriptContent ) . not . toContain ( 'sourceMappingURL=data:application/json' ) ;
7677
77- it ( 'supports component styles sourcemaps' , ( done ) => {
78- const overrides : Partial < BuildWebpackServerSchema > = {
78+ await run . stop ( ) ;
79+ } ) ;
80+ //
81+ it ( 'supports component styles sourcemaps' , async ( ) => {
82+ const overrides = {
7983 sourceMap : {
8084 styles : true ,
8185 scripts : true ,
@@ -86,24 +90,27 @@ describe('Server Builder', () => {
8690 'src/app/app.component.css' : `p { color: red; }` ,
8791 } ) ;
8892
89- runTargetSpec ( host , { project : 'app' , target : 'server' } , overrides ) . pipe (
90- tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( true ) ) ,
91- tap ( ( ) => {
92- expect ( host . scopedSync ( ) . exists ( join ( outputPath , 'main.js.map' ) ) ) . toBe ( true ) ;
93+ const run = await architect . scheduleTarget ( target , overrides ) ;
94+ const output = await run . result as BrowserBuilderOutput ;
95+ expect ( output . success ) . toBe ( true ) ;
9396
94- const scriptContent = virtualFs . fileBufferToString (
95- host . scopedSync ( ) . read ( join ( outputPath , 'main.js' ) ) ,
96- ) ;
97- expect ( scriptContent ) . toContain ( 'sourceMappingURL=main.js.map' ) ;
98- expect ( scriptContent ) . toContain ( 'sourceMappingURL=data:application/json' ) ;
99- } ) ,
100- ) . toPromise ( ) . then ( done , done . fail ) ;
97+ expect ( host . scopedSync ( ) . exists ( join ( outputPath , 'main.js.map' ) ) ) . toBe ( true ) ;
98+
99+ const scriptContent = virtualFs . fileBufferToString (
100+ host . scopedSync ( ) . read ( join ( outputPath , 'main.js' ) ) ,
101+ ) ;
102+ expect ( scriptContent ) . toContain ( 'sourceMappingURL=main.js.map' ) ;
103+ expect ( scriptContent ) . toContain ( 'sourceMappingURL=data:application/json' ) ;
104+
105+ await run . stop ( ) ;
101106 } ) ;
102107
103- it ( 'runs watch mode' , ( done ) => {
108+ it ( 'runs watch mode' , async ( ) => {
104109 const overrides = { watch : true } ;
105110
106- runTargetSpec ( host , { project : 'app' , target : 'server' } , overrides ) . pipe (
111+ const run = await architect . scheduleTarget ( target , overrides ) ;
112+
113+ await run . output . pipe (
107114 tap ( ( buildEvent ) => {
108115 expect ( buildEvent . success ) . toBe ( true ) ;
109116
@@ -112,6 +119,8 @@ describe('Server Builder', () => {
112119 expect ( content ) . toMatch ( / A p p S e r v e r M o d u l e N g F a c t o r y / ) ;
113120 } ) ,
114121 take ( 1 ) ,
115- ) . subscribe ( undefined , done . fail , done ) ;
122+ ) . toPromise ( ) ;
123+
124+ await run . stop ( ) ;
116125 } ) ;
117126} ) ;
0 commit comments