-
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
Merged
gcsecsey
merged 18 commits into
trunk
from
stu-363-user-settings-return-the-list-of-installed-editors
Apr 22, 2025
Merged
Changes from 6 commits
Commits
Show all changes
18 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 437253c
Remove self-explanatory comments
gcsecsey a8cb722
Remove Nova, Sublime, and Atom from the list of editors
gcsecsey eee7089
Remove Nova, Sublime, and Atom from the list of editors
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 hidden or 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 hidden or 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,182 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
import { app } from 'electron'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
jest.mock( 'fs', () => ( { | ||
existsSync: jest.fn(), | ||
readdirSync: jest.fn(), | ||
} ) ); | ||
|
||
jest.mock( 'electron', () => ( { | ||
app: { | ||
getPath: jest.fn(), | ||
}, | ||
} ) ); | ||
|
||
// Mock process.env for ProgramFiles | ||
const originalEnv = process.env; | ||
beforeAll( () => { | ||
process.env = { ...originalEnv }; | ||
} ); | ||
|
||
afterAll( () => { | ||
process.env = originalEnv; | ||
} ); | ||
|
||
describe( 'isInstalled', () => { | ||
let isInstalled: ( key: string ) => boolean; | ||
let mockPaths: string[]; | ||
let getProgramFilesPath: () => string; | ||
|
||
// Reset mocks before each test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's clean up the comments as they seem to be pretty self explanatory unless it is something that is not evident |
||
beforeEach( () => { | ||
jest.resetAllMocks(); | ||
mockPaths = []; | ||
|
||
// Mock fs.existsSync to check against our mockPaths array | ||
( fs.existsSync as jest.Mock ).mockImplementation( ( testPath: string ) => { | ||
return mockPaths.includes( testPath ); | ||
} ); | ||
|
||
// 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; | ||
getProgramFilesPath = module.getProgramFilesPath; | ||
} ); | ||
} ); | ||
|
||
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' } ); | ||
// Re-import the module to ensure platform-specific paths are set up | ||
jest.isolateModules( () => { | ||
const module = require( '../is-installed' ); | ||
isInstalled = module.isInstalled; | ||
getProgramFilesPath = module.getProgramFilesPath; | ||
} ); | ||
} ); | ||
|
||
it( 'detects VS Code installed in Program Files', () => { | ||
// Set ProgramFiles environment variable | ||
process.env.ProgramFiles = 'D:\\Program Files'; | ||
|
||
mockPaths = [ 'D:\\Program Files\\Microsoft VS Code' ]; | ||
expect( isInstalled( 'vscode' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'detects VS Code installed in AppData', () => { | ||
mockPaths = [ path.join( 'C:\\mock\\AppData', 'Local\\Programs\\Microsoft VS Code' ) ]; | ||
expect( isInstalled( 'vscode' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'detects PhpStorm with version-specific folder', () => { | ||
// Set ProgramFiles environment variable | ||
process.env.ProgramFiles = 'E:\\Program Files'; | ||
|
||
const jetbrainsDir = 'E:\\Program Files\\JetBrains'; | ||
const versionSpecificPath = path.join( jetbrainsDir, 'PhpStorm 2023.1' ); | ||
|
||
mockPaths = [ jetbrainsDir, versionSpecificPath, 'E:\\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', () => { | ||
// Clear ProgramFiles environment variable | ||
delete process.env.ProgramFiles; | ||
|
||
mockPaths = [ 'C:\\Program Files\\Microsoft VS Code' ]; | ||
expect( isInstalled( 'vscode' ) ).toBe( true ); | ||
} ); | ||
} ); | ||
|
||
describe( 'on Linux', () => { | ||
beforeEach( () => { | ||
Object.defineProperty( process, 'platform', { value: 'linux' } ); | ||
// Re-import the module to ensure platform-specific paths are set up | ||
jest.isolateModules( () => { | ||
const module = require( '../is-installed' ); | ||
isInstalled = module.isInstalled; | ||
getProgramFilesPath = module.getProgramFilesPath; | ||
} ); | ||
} ); | ||
|
||
it( 'detects VS Code installed in /usr/share/code', () => { | ||
mockPaths = [ '/usr/share/code' ]; | ||
expect( isInstalled( 'vscode' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'detects VS Code installed in user directory', () => { | ||
mockPaths = [ path.join( '/mock/home/path', '.local/share/code' ) ]; | ||
expect( isInstalled( 'vscode' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'detects VS Code installed via snap', () => { | ||
mockPaths = [ '/snap/code' ]; | ||
expect( isInstalled( 'vscode' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'detects VS Code installed as executable', () => { | ||
mockPaths = [ '/usr/bin/vscode' ]; | ||
expect( isInstalled( 'vscode' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'returns false for Nova on Linux (Mac-only)', () => { | ||
mockPaths = []; | ||
expect( isInstalled( 'nova' ) ).toBe( false ); | ||
} ); | ||
} ); | ||
} ); |
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.
Couple of notes regarding this list: