@@ -5,7 +5,6 @@ import { workspaceGenerator } from './workspace';
5
5
import { createTree } from '@nrwl/devkit/testing' ;
6
6
import { Preset } from '../utils/presets' ;
7
7
import * as nxSchema from '../../../../nx/schemas/nx-schema.json' ;
8
- import * as workspaceSchema from '../../../../nx/schemas/workspace-schema.json' ;
9
8
10
9
describe ( '@nrwl/workspace:workspace' , ( ) => {
11
10
let tree : Tree ;
@@ -39,26 +38,32 @@ describe('@nrwl/workspace:workspace', () => {
39
38
defaultBase : 'main' ,
40
39
} ) ;
41
40
const nxJson = readJson < NxJsonConfiguration > ( tree , '/proj/nx.json' ) ;
42
- expect ( nxJson ) . toEqual ( {
43
- $schema : './node_modules/nx/schemas/nx-schema.json' ,
44
- npmScope : 'proj' ,
45
- affected : {
46
- defaultBase : 'main' ,
47
- } ,
48
- tasksRunnerOptions : {
49
- default : {
50
- runner : 'nx/tasks-runners/default' ,
51
- options : {
52
- cacheableOperations : [ 'build' , 'lint' , 'test' , 'e2e' ] ,
41
+ expect ( nxJson ) . toMatchInlineSnapshot ( `
42
+ Object {
43
+ "$schema": "./node_modules/nx/schemas/nx-schema.json",
44
+ "npmScope": "proj",
45
+ "targetDefaults": Object {
46
+ "build": Object {
47
+ "dependsOn": Array [
48
+ "^build",
49
+ ],
53
50
},
54
51
},
55
- } ,
56
- targetDefaults : {
57
- build : {
58
- dependsOn : [ '^build' ] ,
52
+ "tasksRunnerOptions": Object {
53
+ "default": Object {
54
+ "options": Object {
55
+ "cacheableOperations": Array [
56
+ "build",
57
+ "lint",
58
+ "test",
59
+ "e2e",
60
+ ],
61
+ },
62
+ "runner": "nx/tasks-runners/default",
63
+ },
59
64
},
60
- } ,
61
- } ) ;
65
+ }
66
+ ` ) ;
62
67
const validateNxJson = ajv . compile ( nxSchema ) ;
63
68
expect ( validateNxJson ( nxJson ) ) . toEqual ( true ) ;
64
69
} ) ;
@@ -72,32 +77,46 @@ describe('@nrwl/workspace:workspace', () => {
72
77
defaultBase : 'main' ,
73
78
} ) ;
74
79
const nxJson = readJson < NxJsonConfiguration > ( tree , '/proj/nx.json' ) ;
75
- expect ( nxJson ) . toEqual ( {
76
- $schema : './node_modules/nx/schemas/nx-schema.json' ,
77
- npmScope : 'proj' ,
78
- affected : {
79
- defaultBase : 'main' ,
80
- } ,
81
- tasksRunnerOptions : {
82
- default : {
83
- runner : 'nx/tasks-runners/default' ,
84
- options : {
85
- cacheableOperations : [ 'build' , 'lint' , 'test' , 'e2e' ] ,
80
+ expect ( nxJson ) . toMatchInlineSnapshot ( `
81
+ Object {
82
+ "$schema": "./node_modules/nx/schemas/nx-schema.json",
83
+ "namedInputs": Object {
84
+ "default": Array [
85
+ "{projectRoot}/**/*",
86
+ "sharedGlobals",
87
+ ],
88
+ "production": Array [
89
+ "default",
90
+ ],
91
+ "sharedGlobals": Array [],
92
+ },
93
+ "npmScope": "proj",
94
+ "targetDefaults": Object {
95
+ "build": Object {
96
+ "dependsOn": Array [
97
+ "^build",
98
+ ],
99
+ "inputs": Array [
100
+ "production",
101
+ "^production",
102
+ ],
86
103
},
87
104
},
88
- } ,
89
- namedInputs : {
90
- default : [ '{projectRoot}/**/*' , 'sharedGlobals' ] ,
91
- production : [ 'default' ] ,
92
- sharedGlobals : [ ] ,
93
- } ,
94
- targetDefaults : {
95
- build : {
96
- dependsOn : [ '^build' ] ,
97
- inputs : [ 'production' , '^production' ] ,
105
+ "tasksRunnerOptions": Object {
106
+ "default": Object {
107
+ "options": Object {
108
+ "cacheableOperations": Array [
109
+ "build",
110
+ "lint",
111
+ "test",
112
+ "e2e",
113
+ ],
114
+ },
115
+ "runner": "nx/tasks-runners/default",
116
+ },
98
117
},
99
- } ,
100
- } ) ;
118
+ }
119
+ ` ) ;
101
120
} ) ;
102
121
103
122
it ( 'should create a prettierrc file' , async ( ) => {
@@ -155,14 +174,14 @@ describe('@nrwl/workspace:workspace', () => {
155
174
156
175
const { scripts } = readJson ( tree , '/proj/package.json' ) ;
157
176
expect ( scripts ) . toMatchInlineSnapshot ( `
158
- Object {
159
- "build": "nx build",
160
- "ng": "nx",
161
- "postinstall": "node ./decorate-angular-cli.js",
162
- "start": "nx serve",
163
- "test": "nx test",
164
- }
165
- ` ) ;
177
+ Object {
178
+ "build": "nx build",
179
+ "ng": "nx",
180
+ "postinstall": "node ./decorate-angular-cli.js",
181
+ "start": "nx serve",
182
+ "test": "nx test",
183
+ }
184
+ `) ;
166
185
} ) ;
167
186
168
187
it ( 'should not add decorate-angular-cli when used with nx cli' , async ( ) => {
@@ -177,29 +196,94 @@ Object {
177
196
178
197
const { scripts } = readJson ( tree , '/proj/package.json' ) ;
179
198
expect ( scripts ) . toMatchInlineSnapshot ( `
180
- Object {
181
- "build": "nx build",
182
- "start": "nx serve",
183
- "test": "nx test",
184
- }
185
- ` ) ;
199
+ Object {
200
+ "build": "nx build",
201
+ "start": "nx serve",
202
+ "test": "nx test",
203
+ }
204
+ `) ;
186
205
} ) ;
187
206
188
- it ( 'should create a workspace using package layout' , async ( ) => {
207
+ it ( 'should create a workspace using NPM preset (npm package manager)' , async ( ) => {
208
+ tree . write ( '/proj/package.json' , JSON . stringify ( { } ) ) ;
189
209
await workspaceGenerator ( tree , {
190
210
name : 'proj' ,
191
211
directory : 'proj' ,
192
212
cli : 'nx' ,
193
213
preset : Preset . NPM ,
194
214
defaultBase : 'main' ,
215
+ packageManager : 'npm' ,
195
216
} ) ;
196
217
expect ( tree . exists ( '/proj/packages/.gitkeep' ) ) . toBe ( true ) ;
197
218
expect ( tree . exists ( '/proj/apps/.gitkeep' ) ) . toBe ( false ) ;
198
219
expect ( tree . exists ( '/proj/libs/.gitkeep' ) ) . toBe ( false ) ;
199
220
const nx = readJson ( tree , '/proj/nx.json' ) ;
200
- expect ( nx . extends ) . toEqual ( 'nx/presets/npm.json' ) ;
221
+ expect ( nx ) . toMatchInlineSnapshot ( `
222
+ Object {
223
+ "$schema": "./node_modules/nx/schemas/nx-schema.json",
224
+ "extends": "nx/presets/npm.json",
225
+ "tasksRunnerOptions": Object {
226
+ "default": Object {
227
+ "options": Object {
228
+ "cacheableOperations": Array [
229
+ "build",
230
+ "lint",
231
+ "test",
232
+ "e2e",
233
+ ],
234
+ },
235
+ "runner": "nx/tasks-runners/default",
236
+ },
237
+ },
238
+ }
239
+ ` ) ;
201
240
202
- const { scripts } = readJson ( tree , '/proj/package.json' ) ;
203
- expect ( scripts ) . toMatchInlineSnapshot ( `Object {}` ) ;
241
+ const packageJson = readJson ( tree , '/proj/package.json' ) ;
242
+ expect ( packageJson ) . toMatchInlineSnapshot ( `
243
+ Object {
244
+ "dependencies": Object {},
245
+ "devDependencies": Object {
246
+ "nx": "0.0.1",
247
+ "prettier": "^2.6.2",
248
+ },
249
+ "license": "MIT",
250
+ "name": "proj",
251
+ "private": true,
252
+ "scripts": Object {},
253
+ "version": "0.0.0",
254
+ "workspaces": Array [
255
+ "packages/*",
256
+ ],
257
+ }
258
+ ` ) ;
259
+ } ) ;
260
+
261
+ it ( 'should create a workspace using NPM preset (pnpm package manager)' , async ( ) => {
262
+ tree . write ( '/proj/package.json' , JSON . stringify ( { } ) ) ;
263
+ await workspaceGenerator ( tree , {
264
+ name : 'proj' ,
265
+ directory : 'proj' ,
266
+ cli : 'nx' ,
267
+ preset : Preset . NPM ,
268
+ defaultBase : 'main' ,
269
+ packageManager : 'pnpm' ,
270
+ } ) ;
271
+ const packageJson = readJson ( tree , '/proj/package.json' ) ;
272
+ expect ( packageJson ) . toMatchInlineSnapshot ( `
273
+ Object {
274
+ "dependencies": Object {},
275
+ "devDependencies": Object {
276
+ "nx": "0.0.1",
277
+ "prettier": "^2.6.2",
278
+ },
279
+ "license": "MIT",
280
+ "name": "proj",
281
+ "private": true,
282
+ "scripts": Object {},
283
+ "version": "0.0.0",
284
+ }
285
+ ` ) ;
286
+ const pnpm = tree . read ( '/proj/pnpm-workspace.yaml' ) . toString ( ) ;
287
+ expect ( pnpm ) . toContain ( 'packages/*' ) ;
204
288
} ) ;
205
289
} ) ;
0 commit comments