@@ -3,18 +3,19 @@ import {
33 DisposableCollection ,
44} from '@theia/core/lib/common/disposable' ;
55import { isWindows } from '@theia/core/lib/common/os' ;
6+ import { URI } from '@theia/core/lib/common/uri' ;
67import { FileUri } from '@theia/core/lib/node/file-uri' ;
78import { Container } from '@theia/core/shared/inversify' ;
89import { expect } from 'chai' ;
9- import { promises as fs } from 'node:fs' ;
10- import { basename , join } from 'node:path' ;
1110import { rejects } from 'node:assert/strict' ;
11+ import { promises as fs } from 'node:fs' ;
12+ import path , { basename , join } from 'node:path' ;
1213import { sync as rimrafSync } from 'rimraf' ;
1314import temp from 'temp' ;
1415import { Sketch , SketchesError , SketchesService } from '../../common/protocol' ;
1516import {
16- isAccessibleSketchPath ,
1717 SketchesServiceImpl ,
18+ isAccessibleSketchPath ,
1819} from '../../node/sketches-service-impl' ;
1920import { ErrnoException } from '../../node/utils/errors' ;
2021import { createBaseContainer , startDaemon } from './node-test-bindings' ;
@@ -332,6 +333,37 @@ describe('sketches-service-impl', () => {
332333 ) ;
333334 } ) ;
334335
336+ it ( 'should copy sketch if the main sketch file has pde extension (#2377)' , async ( ) => {
337+ const sketchesService =
338+ container . get < SketchesServiceImpl > ( SketchesService ) ;
339+ let sketch = await sketchesService . createNewSketch ( ) ;
340+ toDispose . push ( disposeSketch ( sketch ) ) ;
341+ expect ( sketch . mainFileUri . endsWith ( '.ino' ) ) . to . be . true ;
342+
343+ // Create a sketch and rename the main sketch file to .pde
344+ const mainSketchFilePathIno = FileUri . fsPath ( new URI ( sketch . mainFileUri ) ) ;
345+ const sketchFolderPath = path . dirname ( mainSketchFilePathIno ) ;
346+ const mainSketchFilePathPde = path . join (
347+ sketchFolderPath ,
348+ `${ basename ( sketchFolderPath ) } .pde`
349+ ) ;
350+ await fs . rename ( mainSketchFilePathIno , mainSketchFilePathPde ) ;
351+
352+ sketch = await sketchesService . loadSketch ( sketch . uri ) ;
353+ expect ( sketch . mainFileUri . endsWith ( '.pde' ) ) . to . be . true ;
354+
355+ const tempDirPath = await sketchesService [ 'createTempFolder' ] ( ) ;
356+ const destinationPath = join ( tempDirPath , 'GH-2377' ) ;
357+ const destinationUri = FileUri . create ( destinationPath ) . toString ( ) ;
358+
359+ await sketchesService . copy ( sketch , {
360+ destinationUri,
361+ } ) ;
362+
363+ const copiedSketch = await sketchesService . loadSketch ( destinationUri ) ;
364+ expect ( copiedSketch . mainFileUri . endsWith ( '.ino' ) ) . to . be . true ;
365+ } ) ;
366+
335367 it ( 'should copy sketch inside the sketch folder' , async ( ) => {
336368 const sketchesService =
337369 container . get < SketchesServiceImpl > ( SketchesService ) ;
0 commit comments