-
Notifications
You must be signed in to change notification settings - Fork 29
User Settings: return the list of installed editors #1217
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
Open
gcsecsey
wants to merge
15
commits into
trunk
Choose a base branch
from
stu-363-user-settings-return-the-list-of-installed-editors
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+261
−41
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
afaf875
Update install path detection logic
gcsecsey 4aad06b
Merge branch 'trunk' of github.com:Automattic/studio into stu-363-use…
gcsecsey 8ecfdf4
Update test types
gcsecsey e3e41f5
Remove self-explanatory comments
gcsecsey a78fcca
Use `programfiles` env var for paths on Windows
gcsecsey 676926e
Remove unnecessary log
gcsecsey f8c1700
restore linux supported apps
gcsecsey a2e232b
use path.win32 for windows path operations
gcsecsey eb23ce3
fix mocking of process.env
gcsecsey 0c10567
Merge branch 'trunk' of github.com:Automattic/studio into stu-363-use…
gcsecsey dbc9474
tests: normalize mock paths
gcsecsey 445bf74
Return installed apps list in getInstalledApps
gcsecsey 10adeb4
Return installed apps list in getInstalledApps
gcsecsey 68a2766
Merge branch 'stu-363-user-settings-return-the-list-of-installed-edit…
gcsecsey 881a8b3
update types
gcsecsey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
import { app } from 'electron'; | ||
import fs from 'fs'; | ||
|
||
jest.mock( 'fs', () => ( { | ||
existsSync: jest.fn(), | ||
readdirSync: jest.fn(), | ||
} ) ); | ||
|
||
jest.mock( 'electron', () => ( { | ||
app: { | ||
getPath: jest.fn(), | ||
}, | ||
} ) ); | ||
|
||
describe( 'isInstalled', () => { | ||
let isInstalled: ( key: string ) => boolean; | ||
let mockPaths: string[]; | ||
|
||
// Reset mocks before each test | ||
beforeEach( () => { | ||
jest.resetAllMocks(); | ||
mockPaths = []; | ||
|
||
// Mock fs.existsSync to check against our mockPaths array | ||
( fs.existsSync as jest.Mock ).mockImplementation( ( testPath: string ) => { | ||
// Normalize both the test path and mock paths to use forward slashes | ||
const normalizedTestPath = testPath.replace( /\\/g, '/' ); | ||
const normalizedMockPaths = mockPaths.map( ( p ) => p.replace( /\\/g, '/' ) ); | ||
return normalizedMockPaths.includes( normalizedTestPath ); | ||
} ); | ||
|
||
// Mock app.getPath | ||
( app.getPath as jest.Mock ).mockImplementation( ( name: string ) => { | ||
switch ( name ) { | ||
case 'home': | ||
return '/mock/home/path'; | ||
case 'appData': | ||
return process.platform === 'win32' ? 'C:\\mock\\AppData' : '/mock/home/path/.config'; | ||
default: | ||
return ''; | ||
} | ||
} ); | ||
} ); | ||
|
||
describe( 'on macOS (darwin)', () => { | ||
beforeEach( () => { | ||
Object.defineProperty( process, 'platform', { value: 'darwin' } ); | ||
// Re-import the module to ensure platform-specific paths are set up | ||
jest.isolateModules( () => { | ||
const module = require( '../is-installed' ); | ||
isInstalled = module.isInstalled; | ||
} ); | ||
} ); | ||
|
||
it( 'detects VS Code installed in system Applications', () => { | ||
mockPaths = [ '/Applications/Visual Studio Code.app' ]; | ||
expect( isInstalled( 'vscode' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'detects VS Code installed in user Applications', () => { | ||
mockPaths = [ '/mock/home/path/Applications/Visual Studio Code.app' ]; | ||
expect( isInstalled( 'vscode' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'returns false when VS Code is not installed', () => { | ||
mockPaths = []; | ||
expect( isInstalled( 'vscode' ) ).toBe( false ); | ||
} ); | ||
|
||
it( 'detects PhpStorm installed', () => { | ||
mockPaths = [ '/Applications/PhpStorm.app' ]; | ||
expect( isInstalled( 'phpstorm' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'detects Nova installed (Mac-only)', () => { | ||
mockPaths = [ '/Applications/Nova.app' ]; | ||
expect( isInstalled( 'nova' ) ).toBe( true ); | ||
} ); | ||
} ); | ||
|
||
describe( 'on Windows (win32)', () => { | ||
beforeEach( () => { | ||
Object.defineProperty( process, 'platform', { value: 'win32' } ); | ||
process.env.ProgramFiles = 'D:\\Program Files'; | ||
// Re-import the module after setting the environment variable | ||
jest.isolateModules( () => { | ||
const module = require( '../is-installed' ); | ||
isInstalled = module.isInstalled; | ||
} ); | ||
} ); | ||
|
||
it( 'detects VS Code installed in Program Files', () => { | ||
mockPaths = [ 'D:\\Program Files\\Microsoft VS Code' ]; | ||
|
||
expect( isInstalled( 'vscode' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'detects VS Code installed in AppData', () => { | ||
mockPaths = [ 'C:\\mock\\AppData\\Local\\Programs\\Microsoft VS Code' ]; | ||
expect( isInstalled( 'vscode' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'detects PhpStorm with version-specific folder', () => { | ||
mockPaths = [ 'D:\\Program Files\\JetBrains', 'D:\\Program Files\\JetBrains\\PhpStorm' ]; | ||
|
||
( fs.readdirSync as jest.Mock ).mockReturnValue( [ 'PhpStorm 2023.1', 'WebStorm 2023.1' ] ); | ||
|
||
expect( isInstalled( 'phpstorm' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'returns false for Nova on Windows (Mac-only)', () => { | ||
mockPaths = []; | ||
expect( isInstalled( 'nova' ) ).toBe( false ); | ||
} ); | ||
|
||
it( 'falls back to default Program Files path when environment variable is not set', () => { | ||
delete process.env.ProgramFiles; | ||
|
||
// Re-import the module after setting the environment variable | ||
jest.isolateModules( () => { | ||
const module = require( '../is-installed' ); | ||
isInstalled = module.isInstalled; | ||
} ); | ||
|
||
mockPaths = [ 'C:\\Program Files\\Microsoft VS Code' ]; | ||
expect( isInstalled( 'vscode' ) ).toBe( true ); | ||
} ); | ||
} ); | ||
} ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@katinthehatsite when rebasing this PR after #1215 was merged, I found it easier to merge the list of terminals and apps into one list, and do the same path manipulations for these as the IDEs.
I only had some issues with the typing, currently I use
InstalledApps | InstalledTerminals
where we need to be able to handle both. Longer term, I think it'd make sense to maintain just one type of the possible apps/terminals we support.