@@ -3,12 +3,7 @@ import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
33import * as path from 'path' ;
44import { firstValueFrom } from 'rxjs' ;
55
6- import { DaffJson } from '@daffodil/cli/versioning' ;
7-
8- import {
9- addBuildCondition ,
10- createDaffJson ,
11- } from './daff-config' ;
6+ import { addBuildCondition } from './daff-config' ;
127import { NgAddOptions } from '../../schema' ;
138
149const collectionPath = path . join ( __dirname , '../../../collection.json' ) ;
@@ -36,135 +31,77 @@ const buildAngularJson = (projectName: string) => ({
3631 } ,
3732} ) ;
3833
39- describe ( 'createDaffJson' , ( ) => {
40- let tree : Tree ;
41- const projectName = 'test-app' ;
42-
43- beforeEach ( ( ) => {
44- tree = Tree . empty ( ) ;
45- } ) ;
46-
47- it ( 'creates daff.json with the magento version when driver is magento' , ( ) => {
48- const options : NgAddOptions = { project : projectName , driver : 'magento' , driverVersion : TEST_DRIVER_VERSION } ;
49- const rule = createDaffJson ( options , projectName ) ;
50-
51- rule ( tree , < any > { logger : { warn : ( ) => undefined } } ) ;
52-
53- expect ( tree . exists ( 'daff.json' ) ) . toBe ( true ) ;
54- const body : DaffJson = JSON . parse ( tree . read ( 'daff.json' ) ?. toString ( ) ?? '' ) ;
55- expect ( body . drivers ?. magento ) . toBe ( TEST_DRIVER_VERSION ) ;
56- } ) ;
57-
58- it ( 'creates daff.json without driver projects for the demo driver' , ( ) => {
59- const options : NgAddOptions = { project : projectName , driver : 'demo' } ;
60- const rule = createDaffJson ( options , projectName ) ;
61-
62- rule ( tree , < any > { logger : { warn : ( ) => undefined } } ) ;
63-
64- expect ( tree . exists ( 'daff.json' ) ) . toBe ( true ) ;
65- const body : DaffJson = JSON . parse ( tree . read ( 'daff.json' ) ?. toString ( ) ?? '' ) ;
66- expect ( body . drivers ) . toEqual ( { } ) ;
67- } ) ;
68-
69- it ( 'does not create daff.json for shopify or in-memory drivers' , ( ) => {
70- for ( const driver of < const > [ 'shopify' , 'in-memory' ] ) {
71- const scopedTree = Tree . empty ( ) ;
72- const options : NgAddOptions = { project : projectName , driver } ;
73- const rule = createDaffJson ( options , projectName ) ;
74-
75- rule ( scopedTree , < any > { logger : { warn : ( ) => undefined } } ) ;
76-
77- expect ( scopedTree . exists ( 'daff.json' ) ) . toBe ( false ) ;
78- }
79- } ) ;
80-
81- it ( 'leaves an existing daff.json untouched' , ( ) => {
82- const existing = '{"drivers":{"magento":"2.4.1"}}\n' ;
83- tree . create ( 'daff.json' , existing ) ;
84- const options : NgAddOptions = { project : projectName , driver : 'magento' , driverVersion : TEST_DRIVER_VERSION } ;
85- const rule = createDaffJson ( options , projectName ) ;
86-
87- rule ( tree , < any > { logger : { warn : ( ) => undefined } } ) ;
88-
89- expect ( tree . read ( 'daff.json' ) ?. toString ( ) ) . toBe ( existing ) ;
90- } ) ;
91- } ) ;
92-
9334describe ( 'addBuildCondition' , ( ) => {
9435 const projectName = 'test-app' ;
9536 let runner : SchematicTestRunner ;
9637 let tree : Tree ;
9738
98- const magentoDriverJson = JSON . stringify ( {
99- drivers : { magento : TEST_DRIVER_VERSION } ,
100- } ) ;
101-
10239 beforeEach ( ( ) => {
10340 runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
10441 tree = Tree . empty ( ) ;
10542 tree . create ( '/angular.json' , JSON . stringify ( buildAngularJson ( projectName ) , null , 2 ) ) ;
10643 } ) ;
10744
108- it ( 'adds the build conditions derived from daff.json for the magento driver' , async ( ) => {
109- tree . create ( 'daff.json' , magentoDriverJson ) ;
45+ it ( 'sets the daffodil commerce builder and driver version for the magento driver' , async ( ) => {
11046 const options : NgAddOptions = { project : projectName , driver : 'magento' , driverVersion : TEST_DRIVER_VERSION } ;
11147 const rule = addBuildCondition ( options , projectName ) ;
11248
11349 const resultTree = await firstValueFrom ( runner . callRule ( rule , tree ) ) ;
11450
11551 const angular = JSON . parse ( resultTree . read ( '/angular.json' ) ?. toString ( ) ?? '' ) ;
116- const conditions = angular . projects [ projectName ] . architect . build . options ?. conditions ;
117- expect ( conditions ) . toEqual ( [ 'order-magento-2.4.1' , 'external-router-magento-2.4.3' ] ) ;
52+ const buildOptions = angular . projects [ projectName ] . architect . build . options ;
53+ expect ( buildOptions . builder ) . toBe ( '@daffodil/commerce:application' ) ;
54+ expect ( buildOptions . drivers ) . toEqual ( { magento : TEST_DRIVER_VERSION } ) ;
11855 } ) ;
11956
120- it ( 'adds no conditions when daff.json does not exist in the tree ' , async ( ) => {
121- const options : NgAddOptions = { project : projectName , driver : 'magento' , driverVersion : TEST_DRIVER_VERSION } ;
57+ it ( 'leaves the build options untouched when no driver version is provided ' , async ( ) => {
58+ const options : NgAddOptions = { project : projectName , driver : 'magento' } ;
12259 const rule = addBuildCondition ( options , projectName ) ;
12360
12461 const resultTree = await firstValueFrom ( runner . callRule ( rule , tree ) ) ;
12562
12663 const angular = JSON . parse ( resultTree . read ( '/angular.json' ) ?. toString ( ) ?? '' ) ;
127- expect ( angular . projects [ projectName ] . architect . build . options ?. conditions ) . toBeUndefined ( ) ;
64+ expect ( angular . projects [ projectName ] . architect . build . options ?. builder ) . toBeUndefined ( ) ;
12865 } ) ;
12966
130- it ( 'adds no conditions for the demo driver' , async ( ) => {
131- tree . create ( 'daff.json' , JSON . stringify ( { projects : { } } ) ) ;
132- const options : NgAddOptions = { project : projectName , driver : 'demo' } ;
67+ it ( 'leaves the build options untouched for the demo driver' , async ( ) => {
68+ const options : NgAddOptions = { project : projectName , driver : 'demo' , driverVersion : TEST_DRIVER_VERSION } ;
13369 const rule = addBuildCondition ( options , projectName ) ;
13470
13571 const resultTree = await firstValueFrom ( runner . callRule ( rule , tree ) ) ;
13672
13773 const angular = JSON . parse ( resultTree . read ( '/angular.json' ) ?. toString ( ) ?? '' ) ;
138- expect ( angular . projects [ projectName ] . architect . build . options ?. conditions ) . toBeUndefined ( ) ;
74+ expect ( angular . projects [ projectName ] . architect . build . options ?. builder ) . toBeUndefined ( ) ;
13975 } ) ;
14076
141- it ( 'leaves conditions untouched for shopify or in-memory drivers' , async ( ) => {
77+ it ( 'leaves the build options untouched for shopify or in-memory drivers' , async ( ) => {
14278 for ( const driver of < const > [ 'shopify' , 'in-memory' ] ) {
14379 const scopedTree = Tree . empty ( ) ;
14480 scopedTree . create ( '/angular.json' , JSON . stringify ( buildAngularJson ( projectName ) , null , 2 ) ) ;
145- const options : NgAddOptions = { project : projectName , driver } ;
81+ const options : NgAddOptions = { project : projectName , driver, driverVersion : TEST_DRIVER_VERSION } ;
14682 const rule = addBuildCondition ( options , projectName ) ;
14783
14884 const resultTree = await firstValueFrom ( runner . callRule ( rule , scopedTree ) ) ;
14985
15086 const angular = JSON . parse ( resultTree . read ( '/angular.json' ) ?. toString ( ) ?? '' ) ;
151- expect ( angular . projects [ projectName ] . architect . build . options ?. conditions ) . toBeUndefined ( ) ;
87+ expect ( angular . projects [ projectName ] . architect . build . options ?. builder ) . toBeUndefined ( ) ;
15288 }
15389 } ) ;
15490
155- it ( 'overwrites existing conditions when syncing' , async ( ) => {
91+ it ( 'overwrites existing builder and driver options when syncing' , async ( ) => {
15692 const baseline = buildAngularJson ( projectName ) ;
157- ( < any > baseline . projects [ projectName ] . architect . build . options ) . conditions = [ 'stale-condition' ] ;
93+ ( < any > baseline . projects [ projectName ] . architect . build . options ) . builder = '@angular-devkit/build-angular:application' ;
94+ ( < any > baseline . projects [ projectName ] . architect . build . options ) . drivers = { magento : '2.0.0' } ;
15895 tree . overwrite ( '/angular.json' , JSON . stringify ( baseline , null , 2 ) ) ;
159- tree . create ( 'daff.json' , magentoDriverJson ) ;
16096
16197 const options : NgAddOptions = { project : projectName , driver : 'magento' , driverVersion : TEST_DRIVER_VERSION } ;
16298 const rule = addBuildCondition ( options , projectName ) ;
16399
164100 const resultTree = await firstValueFrom ( runner . callRule ( rule , tree ) ) ;
165101
166102 const angular = JSON . parse ( resultTree . read ( '/angular.json' ) ?. toString ( ) ?? '' ) ;
167- const conditions = angular . projects [ projectName ] . architect . build . options ?. conditions ;
168- expect ( conditions ) . toEqual ( [ 'order-magento-2.4.1' , 'external-router-magento-2.4.3' ] ) ;
103+ const buildOptions = angular . projects [ projectName ] . architect . build . options ;
104+ expect ( buildOptions . builder ) . toBe ( '@daffodil/commerce:application' ) ;
105+ expect ( buildOptions . drivers ) . toEqual ( { magento : TEST_DRIVER_VERSION } ) ;
169106 } ) ;
170107} ) ;
0 commit comments