@@ -44,12 +44,9 @@ test.group('Make Preloaded File', (group) => {
44
44
preloadFile . environment = 'console,web' as any
45
45
await preloadFile . run ( )
46
46
47
- const AppProvider = await fs . get ( 'start/viewGlobals.ts' )
48
- const ProviderTemplate = await templates . get ( 'preload-file.txt' )
49
- assert . deepEqual (
50
- toNewlineArray ( AppProvider ) ,
51
- toNewlineArray ( ProviderTemplate . replace ( '{{ filename }}' , 'AppProvider' ) )
52
- )
47
+ const viewGlobals = await fs . get ( 'start/viewGlobals.ts' )
48
+ const preloadTemplate = await templates . get ( 'preload-file.txt' )
49
+ assert . deepEqual ( toNewlineArray ( viewGlobals ) , toNewlineArray ( preloadTemplate ) )
53
50
54
51
const rcRawContents = await fs . get ( '.adonisrc.json' )
55
52
assert . deepEqual ( JSON . parse ( rcRawContents ) , {
@@ -80,12 +77,9 @@ test.group('Make Preloaded File', (group) => {
80
77
preloadFile . environment = [ 'console' , 'web' ]
81
78
await preloadFile . run ( )
82
79
83
- const AppProvider = await fs . get ( 'foo/viewGlobals.ts' )
84
- const ProviderTemplate = await templates . get ( 'preload-file.txt' )
85
- assert . deepEqual (
86
- toNewlineArray ( AppProvider ) ,
87
- toNewlineArray ( ProviderTemplate . replace ( '{{ filename }}' , 'AppProvider' ) )
88
- )
80
+ const viewGlobals = await fs . get ( 'foo/viewGlobals.ts' )
81
+ const preloadTemplate = await templates . get ( 'preload-file.txt' )
82
+ assert . deepEqual ( toNewlineArray ( viewGlobals ) , toNewlineArray ( preloadTemplate ) )
89
83
90
84
const rcRawContents = await fs . get ( '.adonisrc.json' )
91
85
assert . deepEqual ( JSON . parse ( rcRawContents ) , {
@@ -98,4 +92,58 @@ test.group('Make Preloaded File', (group) => {
98
92
] ,
99
93
} )
100
94
} )
95
+
96
+ test ( 'select environment as repl' , async ( assert ) => {
97
+ await fs . add ( '.adonisrc.json' , JSON . stringify ( { } ) )
98
+
99
+ const rcContents = importFresh ( join ( fs . basePath , '.adonisrc.json' ) ) as any
100
+ const app = new Application ( fs . basePath , 'test' , rcContents )
101
+
102
+ const preloadFile = new PreloadFile ( app , new Kernel ( app ) )
103
+ preloadFile . name = 'repl'
104
+ preloadFile . environment = [ 'repl' ]
105
+ await preloadFile . run ( )
106
+
107
+ const replFile = await fs . get ( 'start/repl.ts' )
108
+ const preloadTemplate = await templates . get ( 'preload-file.txt' )
109
+ assert . deepEqual ( toNewlineArray ( replFile ) , toNewlineArray ( preloadTemplate ) )
110
+
111
+ const rcRawContents = await fs . get ( '.adonisrc.json' )
112
+ assert . deepEqual ( JSON . parse ( rcRawContents ) , {
113
+ preloads : [
114
+ {
115
+ file : './start/repl' ,
116
+ environment : [ 'repl' ] ,
117
+ } ,
118
+ ] ,
119
+ } )
120
+ } )
121
+
122
+ test ( 'prompt for environment when not explicitly defined' , async ( assert ) => {
123
+ await fs . add ( '.adonisrc.json' , JSON . stringify ( { } ) )
124
+
125
+ const rcContents = importFresh ( join ( fs . basePath , '.adonisrc.json' ) ) as any
126
+ const app = new Application ( fs . basePath , 'test' , rcContents )
127
+
128
+ const preloadFile = new PreloadFile ( app , new Kernel ( app ) )
129
+ preloadFile . prompt . on ( 'prompt' , ( question ) => {
130
+ question . select ( 1 )
131
+ } )
132
+
133
+ await preloadFile . kernel . runCommand ( preloadFile , [ 'make:prldfile' , 'repl' ] )
134
+
135
+ const replFile = await fs . get ( 'start/repl.ts' )
136
+ const preloadTemplate = await templates . get ( 'preload-file.txt' )
137
+ assert . deepEqual ( toNewlineArray ( replFile ) , toNewlineArray ( preloadTemplate ) )
138
+
139
+ const rcRawContents = await fs . get ( '.adonisrc.json' )
140
+ assert . deepEqual ( JSON . parse ( rcRawContents ) , {
141
+ preloads : [
142
+ {
143
+ file : './start/repl' ,
144
+ environment : [ 'repl' ] ,
145
+ } ,
146
+ ] ,
147
+ } )
148
+ } )
101
149
} )
0 commit comments