Skip to content

Commit

Permalink
👷 Add a few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrieseberg committed Oct 6, 2018
1 parent 09edfa1 commit 63f37c9
Show file tree
Hide file tree
Showing 21 changed files with 767 additions and 15 deletions.
11 changes: 9 additions & 2 deletions src/renderer/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ export class BinaryManager {
const zipPath = await eDownload({ version });
const extractPath = this.getDownloadPath(version);
console.log(`BinaryManager: Electron ${version} downloaded, now unpacking`);
const electronFiles = await this.unzip(zipPath, extractPath);
console.log(electronFiles);

try {
const electronFiles = await this.unzip(zipPath, extractPath);
console.log(`Unzipped ${version}`, electronFiles);
} catch (error) {
console.warn(`Failure while unzipping ${version}`, error);

// Todo: Handle this case
}

this.state[version] = 'ready';
}
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/add-version-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from 'react';
import * as semver from 'semver';

import { GitHubVersion } from '../../interfaces';
import { getElectroNameForPlatform } from '../../utils/electron-name';
import { getElectronNameForPlatform } from '../../utils/electron-name';
import { AppState } from '../state';
import { Dialog } from './dialog';

Expand Down Expand Up @@ -165,7 +165,7 @@ export class AddVersionDialog extends React.Component<AddVersionDialogProps, Add
htmlFor='custom-electron-version'
className='force-button'
>
Select the folder containing {getElectroNameForPlatform()}
Select the folder containing {getElectronNameForPlatform()}
</label>
<input
type='file'
Expand All @@ -185,8 +185,8 @@ export class AddVersionDialog extends React.Component<AddVersionDialogProps, Add
if (!file || !file.path) return null;

const info = isValidElectron
? `We found an ${getElectroNameForPlatform()} in this folder.`
: `We did not find a ${getElectroNameForPlatform()} in this folder...`;
? `We found an ${getElectronNameForPlatform()} in this folder.`
: `We did not find a ${getElectronNameForPlatform()} in this folder...`;

return (
<>
Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/publish-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class PublishButton extends React.Component<PublishButtonProps, PublishBu
const options = { includeDependencies: true, includeElectron: true };
const values = await window.ElectronFiddle.app.getValues(options);


try {
const gist = await octo.gists.create({
public: true,
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/components/settings-electron.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ export class ElectronSettings extends React.Component<ElectronSettingsProps, Ele
this.setState({ isDeletingAll: false });
}

/**
* Opens the "add local version" dialog
*/
public handleAddVersion(): void {
this.props.appState.toggleAddVersionDialog();
}
Expand Down
1 change: 0 additions & 1 deletion src/renderer/fetch-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export async function updateEditorTypeDefinitions(version: string, i: number = 0
};

// If this method is called before we're ready, we'll delay this work a bit
if (!window.ElectronFiddle) return defer();
if (!window.ElectronFiddle.app || !window.ElectronFiddle.app.monaco) return defer();

const { app } = window.ElectronFiddle;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function getElectronVersions(): Array<ElectronVersion> {
export function addLocalVersion(input: GitHubVersion): Array<GitHubVersion> {
const versions = getLocalVersions();

if (!versions.find((v) => v.url !== input.url)) {
if (!versions.find((v) => v.url === input.url)) {
versions.push(input);
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/electron-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @returns {string}
*/
export function getElectroNameForPlatform(): string {
export function getElectronNameForPlatform(): string {
if (process.platform === 'win32') {
return 'electron.exe';
} else if (process.platform === 'darwin') {
Expand Down
10 changes: 10 additions & 0 deletions tests/renderer/binary-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,15 @@ describe('binary', () => {
expect(require('electron-download')).toHaveBeenCalledTimes(0);
expect(binaryManager.state['3.0.0']).toBe('downloading');
});

it('handles an error in the zip file', async () => {
const eDownload = require('electron-download');
eDownload.mockImplementationOnce((_p: any, c: any) => c(undefined, '/fake/path'));

const mockZip = require('extract-zip');
mockZip.mockImplementationOnce((_a: any, _b: any, c: any) => c(new Error('bwap-bwap')));

await binaryManager.setup('v3.0.0');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AddVersionDialog component renders 1`] = `
<Dialog
buttons={
Array [
<button
className="button"
disabled={false}
onClick={[Function]}
>
Add
</button>,
<button
className="cancel"
onClick={[Function]}
>
Cancel
</button>,
]
}
className="add-version-dialog"
isCentered={true}
isShowing={true}
isShowingBackdrop={true}
key="add-version-dialog"
onClose={[Function]}
>
<label
className="force-button"
htmlFor="custom-electron-version"
>
Select the folder containing
Electron.app
</label>
<input
id="custom-electron-version"
name="custom-electron-version"
onChange={[Function]}
type="file"
webkitdirectory="true"
/>
</Dialog>
`;
Loading

0 comments on commit 63f37c9

Please sign in to comment.