1- import { ProjectConfiguration , TargetConfiguration } from '@nx/devkit' ;
2- import { readJson } from '@nx/plugin/testing' ;
1+ import { TargetConfiguration } from '@nx/devkit' ;
2+ import { uniq } from '@nx/plugin/testing' ;
33
44import { DeployExecutorOptions } from '../../../packages/ngx-deploy-npm/src/executors/deploy/schema' ;
55import { npmAccess } from '../../../packages/ngx-deploy-npm/src/core' ;
6- import {
7- generateLib ,
8- initNgxDeployNPMProject ,
9- installDependencies ,
10- installNgxDeployNPMProject ,
11- } from '../utils' ;
6+ import { setup } from '../utils' ;
127
13- // TODO, migrate to SIFERS
148describe ( 'install' , ( ) => {
15- const publicLib = 'node-lib1' ;
16- let projectWorkSpacePublicLib : ProjectConfiguration ;
17-
18- const publicLib2 = 'node-lib2' ;
19- let projectWorkSpacePublicLib2 : ProjectConfiguration ;
20-
21- const restrictedLib = 'node-resctricted' ;
22- let projectWorkSpaceRestrictedLib : ProjectConfiguration ;
23-
24- const libNOTset = 'node-lib-not-set' ;
25- let projectWorkSpaceLibNOTSet : ProjectConfiguration ;
26-
27- const expectedTarget = (
28- projectName : string ,
9+ const expectedTarget = ( {
10+ projectName,
2911 isBuildable = true ,
30- access : npmAccess = npmAccess . public
31- ) : TargetConfiguration < DeployExecutorOptions > => {
12+ access = npmAccess . public ,
13+ customDistFolderPath,
14+ } : {
15+ projectName : string ;
16+ isBuildable ?: boolean ;
17+ access ?: npmAccess ;
18+ customDistFolderPath ?: string ;
19+ } ) : TargetConfiguration < DeployExecutorOptions > => {
3220 const target : TargetConfiguration < DeployExecutorOptions > = {
3321 executor : 'ngx-deploy-npm:deploy' ,
3422 options : {
35- distFolderPath : `dist/libs/${ projectName } ` ,
36- access : access ,
23+ distFolderPath : customDistFolderPath || `dist/libs/${ projectName } ` ,
24+ access,
3725 } ,
3826 } ;
3927
@@ -44,54 +32,43 @@ describe('install', () => {
4432 return target ;
4533 } ;
4634
47- initNgxDeployNPMProject ( ) ;
48- installDependencies ( '@nx/node' ) ;
49-
50- // Init libs and projects
51- generateLib ( '@nx/node' , publicLib , `--dir="libs"` ) ;
52- generateLib ( '@nx/node' , publicLib2 , `--dir="libs"` ) ;
53- generateLib ( '@nx/node' , restrictedLib , `--dir="libs"` ) ;
54- generateLib ( '@nx/node' , libNOTset , `--dir="libs"` ) ;
35+ it ( 'should modify the workspace only for the indicated libs' , async ( ) => {
36+ const [ publicLib , publicLib2 , restrictedLib , libNOTSet , smallLib ] =
37+ await setup ( [
38+ { name : uniq ( 'node-lib1' ) , generator : '@nx/node' } ,
39+ { name : uniq ( 'node-lib2' ) , generator : '@nx/node' } ,
40+ {
41+ name : uniq ( 'node-resctricted' ) ,
42+ access : npmAccess . restricted ,
43+ generator : '@nx/node' ,
44+ } ,
45+ {
46+ name : uniq ( 'node-lib-not-set' ) ,
47+ skipInstall : true ,
48+ generator : '@nx/node' ,
49+ } ,
50+ { name : uniq ( 'small-lib' ) , generator : 'minimal' } ,
51+ ] ) ;
5552
56- const buildMockDistPath = ( projectName : string ) => {
57- return `dist/libs/${ projectName } ` ;
58- } ;
59-
60- installNgxDeployNPMProject (
61- `--project ${ publicLib } --dist-folder-path="${ buildMockDistPath (
62- publicLib
63- ) } "`
64- ) ;
65- installNgxDeployNPMProject (
66- `--project ${ publicLib2 } --dist-folder-path="${ buildMockDistPath (
67- publicLib2
68- ) } "`
69- ) ;
70- installNgxDeployNPMProject (
71- `--project=${ restrictedLib } --dist-folder-path="${ buildMockDistPath (
72- restrictedLib
73- ) } " --access ${ npmAccess . restricted } `
74- ) ;
75-
76- beforeEach ( ( ) => {
77- projectWorkSpacePublicLib = readJson ( `libs/${ publicLib } /project.json` ) ;
78- projectWorkSpacePublicLib2 = readJson ( `libs/${ publicLib2 } /project.json` ) ;
79- projectWorkSpaceRestrictedLib = readJson (
80- `libs/${ restrictedLib } /project.json`
53+ expect ( publicLib . workspace . targets ?. deploy ) . toEqual (
54+ expectedTarget ( { projectName : publicLib . name } )
8155 ) ;
82- projectWorkSpaceLibNOTSet = readJson ( `libs/${ libNOTset } /project.json` ) ;
83- } ) ;
84-
85- it ( 'should modify the workspace for publishable libs' , ( ) => {
86- expect ( projectWorkSpacePublicLib . targets ?. deploy ) . toEqual (
87- expectedTarget ( publicLib )
56+ expect ( publicLib2 . workspace . targets ?. deploy ) . toEqual (
57+ expectedTarget ( { projectName : publicLib2 . name } )
8858 ) ;
89- expect ( projectWorkSpacePublicLib2 . targets ?. deploy ) . toEqual (
90- expectedTarget ( publicLib2 )
59+ expect ( restrictedLib . workspace . targets ?. deploy ) . toEqual (
60+ expectedTarget ( {
61+ projectName : restrictedLib . name ,
62+ access : npmAccess . restricted ,
63+ } )
9164 ) ;
92- expect ( projectWorkSpaceRestrictedLib . targets ?. deploy ) . toEqual (
93- expectedTarget ( restrictedLib , true , npmAccess . restricted )
65+ expect ( libNOTSet . workspace . targets ?. deploy ) . toEqual ( undefined ) ;
66+ expect ( smallLib . workspace . targets ?. deploy ) . toEqual (
67+ expectedTarget ( {
68+ projectName : smallLib . name ,
69+ customDistFolderPath : smallLib . workspace . root ,
70+ isBuildable : false ,
71+ } )
9472 ) ;
95- expect ( projectWorkSpaceLibNOTSet . targets ?. deploy ) . toEqual ( undefined ) ;
96- } ) ;
73+ } , 120000 ) ;
9774} ) ;
0 commit comments