Skip to content

Commit

Permalink
fix: copy example with .pde main sketch file
Browse files Browse the repository at this point in the history
Closes #2377

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta authored and kittaakos committed Feb 22, 2024
1 parent 4217c00 commit aa9b10d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
6 changes: 5 additions & 1 deletion arduino-ide-extension/src/node/sketches-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,13 @@ export class SketchesServiceImpl
force: true,
});

const sourceMainSketchFilePath = FileUri.fsPath(sketch.mainFileUri);
// Can copy sketch with pde main sketch file: https://github.com/arduino/arduino-ide/issues/2377
const ext = path.extname(sourceMainSketchFilePath);

// rename the main sketch file
await fs.rename(
join(temp, `${sourceFolderBasename}.ino`),
join(temp, `${sourceFolderBasename}${ext}`),
join(temp, `${destinationFolderBasename}.ino`)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import {
DisposableCollection,
} from '@theia/core/lib/common/disposable';
import { isWindows } from '@theia/core/lib/common/os';
import { URI } from '@theia/core/lib/common/uri';
import { FileUri } from '@theia/core/lib/node/file-uri';
import { Container } from '@theia/core/shared/inversify';
import { expect } from 'chai';
import { promises as fs } from 'node:fs';
import { basename, join } from 'node:path';
import { rejects } from 'node:assert/strict';
import { promises as fs } from 'node:fs';
import path, { basename, join } from 'node:path';
import { sync as rimrafSync } from 'rimraf';
import temp from 'temp';
import { Sketch, SketchesError, SketchesService } from '../../common/protocol';
import {
isAccessibleSketchPath,
SketchesServiceImpl,
isAccessibleSketchPath,
} from '../../node/sketches-service-impl';
import { ErrnoException } from '../../node/utils/errors';
import { createBaseContainer, startDaemon } from './node-test-bindings';
Expand Down Expand Up @@ -332,6 +333,37 @@ describe('sketches-service-impl', () => {
);
});

it('should copy sketch if the main sketch file has pde extension (#2377)', async () => {
const sketchesService =
container.get<SketchesServiceImpl>(SketchesService);
let sketch = await sketchesService.createNewSketch();
toDispose.push(disposeSketch(sketch));
expect(sketch.mainFileUri.endsWith('.ino')).to.be.true;

// Create a sketch and rename the main sketch file to .pde
const mainSketchFilePathIno = FileUri.fsPath(new URI(sketch.mainFileUri));
const sketchFolderPath = path.dirname(mainSketchFilePathIno);
const mainSketchFilePathPde = path.join(
sketchFolderPath,
`${basename(sketchFolderPath)}.pde`
);
await fs.rename(mainSketchFilePathIno, mainSketchFilePathPde);

sketch = await sketchesService.loadSketch(sketch.uri);
expect(sketch.mainFileUri.endsWith('.pde')).to.be.true;

const tempDirPath = await sketchesService['createTempFolder']();
const destinationPath = join(tempDirPath, 'GH-2377');
const destinationUri = FileUri.create(destinationPath).toString();

await sketchesService.copy(sketch, {
destinationUri,
});

const copiedSketch = await sketchesService.loadSketch(destinationUri);
expect(copiedSketch.mainFileUri.endsWith('.ino')).to.be.true;
});

it('should copy sketch inside the sketch folder', async () => {
const sketchesService =
container.get<SketchesServiceImpl>(SketchesService);
Expand Down

0 comments on commit aa9b10d

Please sign in to comment.