1
- import { afterEach , beforeEach , describe , it } from "bdd" ;
2
1
import { expect } from "expect" ;
3
- import { run } from "npm:effection@3.6.0" ;
4
- import { ensureDir } from "jsr:@std/fs" ;
5
- import { join } from "jsr:@std/path" ;
2
+ import { beforeEach , describe , it } from "../testing.ts" ;
3
+ import { createTempDir , type TempDir } from "../testing/temp-dir.ts" ;
6
4
import { analyzeCommand } from "./analyze.ts" ;
5
+ import { setupLogging } from "../testing/logging.ts" ;
7
6
8
7
describe ( "Analyze Command" , ( ) => {
9
- let testDir : string ;
8
+ let tempDir : TempDir ;
10
9
11
- beforeEach ( async ( ) => {
12
- testDir = await Deno . makeTempDir ( { prefix : "ex-publisher-analyze-test-" } ) ;
10
+ beforeEach ( function * ( ) {
11
+ yield * setupLogging ( false ) ;
12
+ tempDir = yield * createTempDir ( { prefix : "ex-publisher-analyze-test-" } ) ;
13
13
} ) ;
14
14
15
- afterEach ( async ( ) => {
16
- await Deno . remove ( testDir , { recursive : true } ) ;
15
+ describe ( "with an empty workspace" , ( ) => {
16
+ beforeEach ( function * ( ) {
17
+ yield * tempDir . withFiles ( {
18
+ "deno.json" : JSON . stringify (
19
+ {
20
+ workspace : [ ] ,
21
+ imports : { } ,
22
+ } ,
23
+ null ,
24
+ 2 ,
25
+ ) ,
26
+ } ) ;
27
+ } ) ;
28
+
29
+ it ( "should return empty array when no extensions found" , function * ( ) {
30
+ const extensions = yield * analyzeCommand ( {
31
+ verbose : false ,
32
+ workspaceRoot : tempDir . path
33
+ } ) ;
34
+ expect ( extensions ) . toHaveLength ( 0 ) ;
35
+ } ) ;
17
36
} ) ;
18
37
19
- async function createWorkspaceWithExtensions ( ) {
20
- // Create workspace deno.json
21
- await Deno . writeTextFile (
22
- join ( testDir , "deno.json" ) ,
23
- JSON . stringify (
24
- {
25
- workspace : [ "./phoenix-utils" , "./wizard-toolkit" ] ,
26
- imports : {
27
- "bdd" : "jsr:@std/testing@1/bdd" ,
28
- "expect" : "jsr:@std/expect@1" ,
38
+ describe ( "with extensions present" , ( ) => {
39
+ beforeEach ( function * ( ) {
40
+ // Create workspace deno.json
41
+ yield * tempDir . withFiles ( {
42
+ "deno.json" : JSON . stringify (
43
+ {
44
+ workspace : [ "./phoenix-utils" , "./wizard-toolkit" ] ,
45
+ imports : {
46
+ "bdd" : "jsr:@std/testing@1/bdd" ,
47
+ "expect" : "jsr:@std/expect@1" ,
48
+ } ,
29
49
} ,
30
- } ,
31
- null ,
32
- 2 ,
33
- ) ,
34
- ) ;
35
-
36
- // Create phoenix-utils extension
37
- const phoenixDir = join ( testDir , "phoenix-utils" ) ;
38
- await ensureDir ( phoenixDir ) ;
50
+ null ,
51
+ 2 ,
52
+ ) ,
53
+ } ) ;
39
54
40
- await Deno . writeTextFile (
41
- join ( phoenixDir , "ex-publisher.ts" ) ,
42
- `import { defineConfig } from 'ex-publisher';
55
+ // Create phoenix-utils extension
56
+ yield * tempDir . withWorkspace ( "phoenix-utils" , {
57
+ "ex-publisher.ts" : `import { defineConfig } from 'ex-publisher';
43
58
44
59
export default defineConfig({
45
60
name: 'phoenix-utils',
46
61
description: 'Utilities for phoenix lifecycle management',
47
62
effection: ['3', '4'],
48
63
registries: ['npm']
49
64
});` ,
50
- ) ;
51
-
52
- await Deno . writeTextFile (
53
- join ( phoenixDir , "deno.json" ) ,
54
- JSON . stringify (
55
- {
56
- name : "@effectionx/phoenix-utils" ,
57
- version : "1.2.3" ,
58
- exports : "./mod.ts" ,
59
- } ,
60
- null ,
61
- 2 ,
62
- ) ,
63
- ) ;
64
-
65
- // Create wizard-toolkit extension
66
- const wizardDir = join ( testDir , "wizard-toolkit" ) ;
67
- await ensureDir ( wizardDir ) ;
68
-
69
- await Deno . writeTextFile (
70
- join ( wizardDir , "ex-publisher.ts" ) ,
71
- `import { defineConfig } from 'ex-publisher';
65
+ "deno.json" : JSON . stringify (
66
+ {
67
+ name : "@effectionx/phoenix-utils" ,
68
+ version : "1.2.3" ,
69
+ exports : "./mod.ts" ,
70
+ } ,
71
+ null ,
72
+ 2 ,
73
+ ) ,
74
+ } ) ;
75
+
76
+ // Create wizard-toolkit extension
77
+ yield * tempDir . withWorkspace ( "wizard-toolkit" , {
78
+ "ex-publisher.ts" : `import { defineConfig } from 'ex-publisher';
72
79
73
80
export default defineConfig({
74
81
name: 'wizard-toolkit',
75
82
description: 'Advanced spellcasting utilities',
76
83
effection: ['4'],
77
84
registries: ['npm', 'jsr']
78
85
});` ,
79
- ) ;
80
-
81
- await Deno . writeTextFile (
82
- join ( wizardDir , "deno.json" ) ,
83
- JSON . stringify (
84
- {
85
- name : "@effectionx/wizard-toolkit" ,
86
- version : "0.5.2" ,
87
- exports : "./mod.ts" ,
88
- } ,
89
- null ,
90
- 2 ,
91
- ) ,
92
- ) ;
93
- }
94
-
95
- it ( "should return all discovered extensions when no specific extension requested" , async ( ) => {
96
- await createWorkspaceWithExtensions ( ) ;
97
-
98
- await run ( function * ( ) {
86
+ "deno.json" : JSON . stringify (
87
+ {
88
+ name : "@effectionx/wizard-toolkit" ,
89
+ version : "0.5.2" ,
90
+ exports : "./mod.ts" ,
91
+ } ,
92
+ null ,
93
+ 2 ,
94
+ ) ,
95
+ } ) ;
96
+ } ) ;
97
+
98
+ it ( "should return all discovered extensions when no specific extension requested" , function * ( ) {
99
99
const extensions = yield * analyzeCommand ( {
100
100
verbose : false ,
101
- workspaceRoot : testDir
101
+ workspaceRoot : tempDir . path
102
102
} ) ;
103
103
104
104
expect ( extensions ) . toHaveLength ( 2 ) ;
@@ -134,100 +134,94 @@ export default defineConfig({
134
134
} ) ;
135
135
expect ( wizardToolkit ! . version ) . toBe ( "0.5.2" ) ;
136
136
} ) ;
137
- } ) ;
138
-
139
- it ( "should return only the requested extension when extName is specified" , async ( ) => {
140
- await createWorkspaceWithExtensions ( ) ;
141
137
142
- await run ( function * ( ) {
138
+ it ( "should return only the requested extension when extName is specified" , function * ( ) {
143
139
const extensions = yield * analyzeCommand ( {
144
140
verbose : false ,
145
141
extName : "phoenix-utils" ,
146
- workspaceRoot : testDir ,
142
+ workspaceRoot : tempDir . path ,
147
143
} ) ;
148
144
149
145
expect ( extensions ) . toHaveLength ( 1 ) ;
150
146
expect ( extensions [ 0 ] . name ) . toBe ( "phoenix-utils" ) ;
151
147
expect ( extensions [ 0 ] . version ) . toBe ( "1.2.3" ) ;
152
148
} ) ;
153
- } ) ;
154
-
155
- it ( "should return empty array when no extensions found" , async ( ) => {
156
- // Create workspace with no extensions
157
- await Deno . writeTextFile (
158
- join ( testDir , "deno.json" ) ,
159
- JSON . stringify (
160
- {
161
- workspace : [ ] ,
162
- imports : { } ,
163
- } ,
164
- null ,
165
- 2 ,
166
- ) ,
167
- ) ;
168
-
169
- await run ( function * ( ) {
170
- const extensions = yield * analyzeCommand ( {
171
- verbose : false ,
172
- workspaceRoot : testDir
173
- } ) ;
174
- expect ( extensions ) . toHaveLength ( 0 ) ;
175
- } ) ;
176
- } ) ;
177
149
178
- it ( "should return empty array when requested extension not found" , async ( ) => {
179
- await createWorkspaceWithExtensions ( ) ;
180
-
181
- await run ( function * ( ) {
150
+ it ( "should return empty array when requested extension not found" , function * ( ) {
182
151
const extensions = yield * analyzeCommand ( {
183
152
verbose : false ,
184
153
extName : "nonexistent-extension" ,
185
- workspaceRoot : testDir ,
154
+ workspaceRoot : tempDir . path ,
186
155
} ) ;
187
156
expect ( extensions ) . toHaveLength ( 0 ) ;
188
157
} ) ;
189
- } ) ;
190
158
191
- it ( "should work with verbose flag enabled" , async ( ) => {
192
- await createWorkspaceWithExtensions ( ) ;
193
-
194
- await run ( function * ( ) {
159
+ it ( "should work with verbose flag enabled" , function * ( ) {
195
160
const extensions = yield * analyzeCommand ( {
196
161
verbose : true ,
197
- workspaceRoot : testDir
162
+ workspaceRoot : tempDir . path
198
163
} ) ;
199
164
expect ( extensions ) . toHaveLength ( 2 ) ;
200
165
} ) ;
201
166
} ) ;
202
167
203
- it ( "should use custom workspaceRoot when provided" , async ( ) => {
204
- await createWorkspaceWithExtensions ( ) ;
205
-
206
- // Create empty test directory outside the generator
207
- const emptyTestDir = await Deno . makeTempDir ( { prefix : "empty-test-" } ) ;
208
- await Deno . writeTextFile (
209
- join ( emptyTestDir , "deno.json" ) ,
210
- JSON . stringify ( { workspace : [ ] } , null , 2 )
211
- ) ;
212
-
213
- try {
214
- await run ( function * ( ) {
215
- // Test that it works with explicit workspaceRoot
216
- const extensions = yield * analyzeCommand ( {
217
- verbose : false ,
218
- workspaceRoot : testDir
219
- } ) ;
220
- expect ( extensions ) . toHaveLength ( 2 ) ;
221
-
222
- // Test that it would find nothing in a different directory
223
- const emptyExtensions = yield * analyzeCommand ( {
224
- verbose : false ,
225
- workspaceRoot : emptyTestDir
226
- } ) ;
227
- expect ( emptyExtensions ) . toHaveLength ( 0 ) ;
228
- } ) ;
229
- } finally {
230
- await Deno . remove ( emptyTestDir , { recursive : true } ) ;
231
- }
168
+ describe ( "with custom workspaceRoot" , ( ) => {
169
+ let emptyTempDir : TempDir ;
170
+
171
+ beforeEach ( function * ( ) {
172
+ // Set up main workspace
173
+ yield * tempDir . withFiles ( {
174
+ "deno.json" : JSON . stringify (
175
+ {
176
+ workspace : [ "./phoenix-utils" ] ,
177
+ imports : { } ,
178
+ } ,
179
+ null ,
180
+ 2 ,
181
+ ) ,
182
+ } ) ;
183
+
184
+ yield * tempDir . withWorkspace ( "phoenix-utils" , {
185
+ "ex-publisher.ts" : `import { defineConfig } from 'ex-publisher';
186
+
187
+ export default defineConfig({
188
+ name: 'phoenix-utils',
189
+ description: 'Utilities for phoenix lifecycle management',
190
+ effection: ['3', '4'],
191
+ registries: ['npm']
192
+ });` ,
193
+ "deno.json" : JSON . stringify (
194
+ {
195
+ name : "@effectionx/phoenix-utils" ,
196
+ version : "1.2.3" ,
197
+ exports : "./mod.ts" ,
198
+ } ,
199
+ null ,
200
+ 2 ,
201
+ ) ,
202
+ } ) ;
203
+
204
+ // Create empty test directory using TempDir resource
205
+ emptyTempDir = yield * createTempDir ( { prefix : "empty-test-" } ) ;
206
+ yield * emptyTempDir . withFiles ( {
207
+ "deno.json" : JSON . stringify ( { workspace : [ ] } , null , 2 )
208
+ } ) ;
209
+ } ) ;
210
+
211
+ it ( "should use custom workspaceRoot when provided" , function * ( ) {
212
+ // Test that it works with explicit workspaceRoot
213
+ const extensions = yield * analyzeCommand ( {
214
+ verbose : false ,
215
+ workspaceRoot : tempDir . path
216
+ } ) ;
217
+ expect ( extensions ) . toHaveLength ( 1 ) ;
218
+
219
+ // Test that it would find nothing in a different directory
220
+ const emptyExtensions = yield * analyzeCommand ( {
221
+ verbose : false ,
222
+ workspaceRoot : emptyTempDir . path
223
+ } ) ;
224
+ expect ( emptyExtensions ) . toHaveLength ( 0 ) ;
225
+ } ) ;
232
226
} ) ;
233
227
} ) ;
0 commit comments