22 Color ,
33 ColorComponents ,
44 ColorFormat , // It is, actually, read. I think this message is due to a @ts-expect-error.
5+ getOverridableBoolean ,
6+ NotificationRequest ,
57 nova ,
68 Process ,
79 TreeDataProvider ,
@@ -45,6 +47,7 @@ class Test implements Element {
4547 this . passed ? passedColorComponents : failedColorComponents ,
4648 ) ;
4749 item . descriptiveText = this . passed ? "Passed" : "Failed" ;
50+ item . contextValue = "test" ;
4851
4952 return item ;
5053 }
@@ -81,6 +84,8 @@ export class TestFile implements Element {
8184 : TreeItemCollapsibleState . None ;
8285 item . contextValue = "file" ;
8386 item . identifier = this . path ;
87+ item . command = "co.gwil.deno.sidebars.tests.commands.open" ;
88+
8489 return item ;
8590 }
8691}
@@ -161,15 +166,26 @@ export default class TestsDataProvider implements TreeDataProvider<Element> {
161166 // The above process is carried out instead of replacing the `this.files` property. I prefer this because it does not remove test results from the sidebar.
162167 }
163168
164- runTests ( ) {
169+ runTests ( tests ?: string [ ] ) {
165170 if ( ! nova . workspace . path ) {
166171 throw new Error ( "This function requires a workspace path." ) ;
167172 }
168173
169- const paths = this . files . map ( ( file ) => file . path ) ;
174+ const paths = tests ?? this . files . map ( ( file ) => file . path ) ;
175+ const args = [ "test" , "-A" ] ;
176+
177+ if ( getOverridableBoolean ( "co.gwil.deno.config.enableUnstable" ) ) {
178+ args . push ( "--unstable" ) ;
179+ }
180+ const potentialImportMapLocation = nova . workspace . config . get (
181+ "co.gwil.deno.config.import-map" ,
182+ ) ;
183+ if ( potentialImportMapLocation ) {
184+ args . push ( "--import-map=" + potentialImportMapLocation ) ;
185+ }
170186
171187 const options = {
172- args : [ "deno" , "test" , "-A" , ...paths ] ,
188+ args : [ "deno" , ... args , ...paths ] ,
173189 cwd : nova . workspace . path ,
174190 } ;
175191 const denoProcess = new Process ( "/usr/bin/env" , options ) ;
@@ -184,10 +200,14 @@ export default class TestsDataProvider implements TreeDataProvider<Element> {
184200 const output : TestFile [ ] = [ ] ;
185201
186202 let loggingError : UnexpectedLogError | null = null ;
187- denoProcess . onStdout ( ( line ) => {
203+ denoProcess . onStderr ( ( line ) => {
188204 // remove newline
189205 line = line . slice ( 0 , - 1 ) ;
190206 console . log ( line ) ;
207+ } ) ;
208+ denoProcess . onStdout ( ( line ) => {
209+ line = line . slice ( 0 , - 1 ) ;
210+
191211 // remove control (?) characters that make output colorful
192212 line = line . replace (
193213 CONTROL_REGEXP ,
@@ -224,13 +244,44 @@ export default class TestsDataProvider implements TreeDataProvider<Element> {
224244 }
225245 } ) ;
226246
227- const onExit = new Promise ( ( resolve , reject ) => {
247+ const onExit = new Promise < TestFile [ ] > ( ( resolve , reject ) => {
228248 denoProcess . onDidExit ( ( ) => {
229249 // TODO: explore the dangers regarding tests that take long to execute
230- this . files = output ;
231250 if ( loggingError ) {
232251 reject ( loggingError ) ;
233252 } else {
253+ for ( const file of output ) {
254+ const analogousIndex = this . files . findIndex (
255+ ( oldFile ) => oldFile . path == file . path ,
256+ ) ;
257+ if ( analogousIndex != - 1 ) {
258+ this . files [ analogousIndex ] = file ;
259+ } else {
260+ this . files . push ( file ) ;
261+ }
262+ }
263+
264+ const paths = output . map ( ( file ) => file . path ) ;
265+ const missingFiles = this . files . filter (
266+ ( file ) => ! paths . includes ( file . path ) ,
267+ ) ;
268+ for (
269+ const file of missingFiles
270+ ) {
271+ file . children = [ new Header ( "Failed to run" ) ] ;
272+ }
273+
274+ if ( missingFiles . length ) {
275+ const configurationErrorNotificationRequest =
276+ new NotificationRequest (
277+ "co.gwil.deno.notifications.unexpectedEmptiness" ,
278+ ) ;
279+ configurationErrorNotificationRequest . title = "Expecting more?" ;
280+ configurationErrorNotificationRequest . body =
281+ "Deno may be failing to run some tests. Check the extension console for logging." ;
282+ nova . notifications . add ( configurationErrorNotificationRequest ) ;
283+ }
284+
234285 resolve ( output ) ;
235286 }
236287 } ) ;
0 commit comments