Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: copy example with .pde main sketch file #2381

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading