Skip to content

Commit

Permalink
fix: app.getAppPath() returning default-app path for files or directo…
Browse files Browse the repository at this point in the history
…ries without package.json
  • Loading branch information
miniak committed Jun 13, 2019
1 parent ddec3c0 commit 2ab1416
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions default_app/main.ts
Expand Up @@ -103,6 +103,13 @@ function loadApplicationPackage (packagePath: string) {
app.name = packageJson.name
}
app._setDefaultAppPaths(packagePath)
} else {
const stats = fs.statSync(packagePath)
if (stats.isDirectory()) {
app._setDefaultAppPaths(packagePath)
} else if (stats.isFile()) {
app._setDefaultAppPaths(path.dirname(packagePath))
}
}

try {
Expand Down
20 changes: 20 additions & 0 deletions spec-main/api-app-spec.ts
Expand Up @@ -645,6 +645,26 @@ describe('app module', () => {
})
})

describe('getAppPath', () => {
it('works for directories with package.json', async () => {
const { appPath } = await runTestApp('app-path')
const expectedAppPath = path.resolve(fixturesPath, 'api/app-path')
expect(appPath).to.equal(expectedAppPath)
})

it('works for directories without package.json', async () => {
const { appPath } = await runTestApp('app-path/no-package-json')
const expectedAppPath = path.resolve(fixturesPath, 'api/app-path/no-package-json')
expect(appPath).to.equal(expectedAppPath)
})

it('works for files', async () => {
const { appPath } = await runTestApp('app-path/main.js')
const expectedAppPath = path.resolve(fixturesPath, 'api/app-path')
expect(appPath).to.equal(expectedAppPath)
})
})

describe('getPath(name)', () => {
it('returns paths that exist', () => {
const paths = [
Expand Down
10 changes: 10 additions & 0 deletions spec/fixtures/api/app-path/main.js
@@ -0,0 +1,10 @@
const { app } = require('electron')

const payload = {
appPath: app.getAppPath()
}

process.stdout.write(JSON.stringify(payload))
process.stdout.end()

process.exit()
1 change: 1 addition & 0 deletions spec/fixtures/api/app-path/no-package-json/index.js
@@ -0,0 +1 @@
require('../main')
4 changes: 4 additions & 0 deletions spec/fixtures/api/app-path/package.json
@@ -0,0 +1,4 @@
{
"name": "app-path",
"main": "main.js"
}

0 comments on commit 2ab1416

Please sign in to comment.