@@ -12,6 +12,7 @@ describe('@nx/rspack', () => {
12
12
let createNodesFunction = createNodesV2 [ 1 ] ;
13
13
let context : CreateNodesContext ;
14
14
let tempFs : TempFs ;
15
+ let originalCacheProjectGraph = process . env . NX_CACHE_PROJECT_GRAPH ;
15
16
16
17
beforeEach ( ( ) => {
17
18
( isUsingTsSolutionSetup as jest . Mock ) . mockReturnValue ( false ) ;
@@ -26,22 +27,120 @@ describe('@nx/rspack', () => {
26
27
} ,
27
28
workspaceRoot : tempFs . tempDir ,
28
29
} ;
30
+ process . env . NX_CACHE_PROJECT_GRAPH = 'false' ;
29
31
30
32
tempFs . createFileSync (
31
33
'my-app/project.json' ,
32
34
JSON . stringify ( { name : 'my-app' } )
33
35
) ;
34
36
tempFs . createFileSync ( 'my-app/rspack.config.ts' , `export default {};` ) ;
37
+ tempFs . createFileSync ( 'package-lock.json' , `{}` ) ;
35
38
} ) ;
36
39
37
40
afterEach ( ( ) => {
38
41
jest . resetModules ( ) ;
39
42
tempFs . cleanup ( ) ;
43
+ if ( originalCacheProjectGraph !== undefined ) {
44
+ process . env . NX_CACHE_PROJECT_GRAPH = originalCacheProjectGraph ;
45
+ } else {
46
+ delete process . env . NX_CACHE_PROJECT_GRAPH ;
47
+ }
40
48
} ) ;
41
49
42
50
it ( 'should handle missing lock file' , async ( ) => {
51
+ tempFs . removeFileSync ( 'package-lock.json' ) ;
52
+
43
53
await expect (
44
54
createNodesFunction ( [ 'my-app/rspack.config.ts' ] , { } , context )
45
55
) . resolves . not . toThrow ( ) ;
46
56
} ) ;
57
+
58
+ it ( 'should infer tasks' , async ( ) => {
59
+ await expect ( createNodesFunction ( [ 'my-app/rspack.config.ts' ] , { } , context ) )
60
+ . resolves . toMatchInlineSnapshot ( `
61
+ [
62
+ [
63
+ "my-app/rspack.config.ts",
64
+ {
65
+ "projects": {
66
+ "my-app": {
67
+ "metadata": {},
68
+ "root": "my-app",
69
+ "targets": {
70
+ "build": {
71
+ "cache": true,
72
+ "command": "rspack build",
73
+ "dependsOn": [
74
+ "^build",
75
+ ],
76
+ "inputs": [
77
+ "production",
78
+ "^production",
79
+ {
80
+ "externalDependencies": [
81
+ "@rspack/cli",
82
+ ],
83
+ },
84
+ ],
85
+ "options": {
86
+ "args": [
87
+ "--node-env=production",
88
+ ],
89
+ "cwd": "my-app",
90
+ "env": {
91
+ "TS_NODE_COMPILER_OPTIONS": "{"moduleResolution":"Node10","module":"CommonJS"}",
92
+ },
93
+ },
94
+ "outputs": [],
95
+ },
96
+ "build-deps": {
97
+ "dependsOn": [
98
+ "^build",
99
+ ],
100
+ },
101
+ "preview": {
102
+ "command": "rspack serve",
103
+ "options": {
104
+ "args": [
105
+ "--node-env=production",
106
+ ],
107
+ "cwd": "my-app",
108
+ "env": {
109
+ "TS_NODE_COMPILER_OPTIONS": "{"moduleResolution":"Node10","module":"CommonJS"}",
110
+ },
111
+ },
112
+ },
113
+ "serve": {
114
+ "command": "rspack serve",
115
+ "options": {
116
+ "args": [
117
+ "--node-env=development",
118
+ ],
119
+ "cwd": "my-app",
120
+ "env": {
121
+ "TS_NODE_COMPILER_OPTIONS": "{"moduleResolution":"Node10","module":"CommonJS"}",
122
+ },
123
+ },
124
+ },
125
+ "serve-static": {
126
+ "executor": "@nx/web:file-server",
127
+ "options": {
128
+ "buildTarget": "build",
129
+ "spa": true,
130
+ },
131
+ },
132
+ "watch-deps": {
133
+ "command": "npx nx watch --projects my-app --includeDependentProjects -- npx nx build-deps my-app",
134
+ "dependsOn": [
135
+ "build-deps",
136
+ ],
137
+ },
138
+ },
139
+ },
140
+ },
141
+ },
142
+ ],
143
+ ]
144
+ ` ) ;
145
+ } ) ;
47
146
} ) ;
0 commit comments