Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
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
26 changes: 26 additions & 0 deletions spec/apm-cli-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
path = require 'path'
temp = require 'temp'
fs = require 'fs'
apm = require '../lib/apm-cli'

Expand Down Expand Up @@ -25,6 +27,11 @@ describe 'apm command line interface', ->
callback = jasmine.createSpy('callback')
apm.run(['-v', '--no-color'], callback)

testAtomVersion = '0.0.0'
tempAtomResourcePath = temp.mkdirSync('apm-resource-dir-')
fs.writeFileSync(path.join(tempAtomResourcePath, 'package.json'), JSON.stringify(version: testAtomVersion))
process.env.ATOM_RESOURCE_PATH = tempAtomResourcePath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is reset at the end of the test, correct? If not it needs to be.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you say this, do you mean process.env.ATOM_RESOURCE_PATH?

If so, I am basing this test logic off of other -spec examples. I do not see where it is reset. Is there an example of how to reset it?

resourcePath = temp.mkdirSync('apm-resource-path-')
atomPackages =
'test-module':
metadata:
name: 'test-module'
version: '1.0.0'
fs.writeFileSync(path.join(resourcePath, 'package.json'), JSON.stringify(_atomPackages: atomPackages))
process.env.ATOM_RESOURCE_PATH = resourcePath
atomHome = temp.mkdirSync('apm-home-dir-')
process.env.ATOM_HOME = atomHome

resourcePath = temp.mkdirSync('atom-resource-path-')
process.env.ATOM_RESOURCE_PATH = resourcePath

it "logs an error when the installed location of Atom cannot be found", ->
process.env.ATOM_RESOURCE_PATH = '/tmp/atom/is/not/installed/here'

atomHome = temp.mkdirSync('apm-home-dir-')
process.env.ATOM_HOME = atomHome
process.env.ATOM_API_URL = "http://localhost:3000/api"
process.env.ATOM_RESOURCE_PATH = temp.mkdirSync('atom-resource-path-')

atomHome = temp.mkdirSync('apm-home-dir-')
process.env.ATOM_HOME = atomHome
process.env.ATOM_ELECTRON_URL = "http://localhost:3000/node"
process.env.ATOM_PACKAGES_URL = "http://localhost:3000/packages"
process.env.ATOM_ELECTRON_VERSION = 'v0.10.3'
process.env.ATOM_RESOURCE_PATH = temp.mkdirSync('atom-resource-path-')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, it is reset. You linked to it in the first code snippet.

process.env.ATOM_RESOURCE_PATH = resourcePath


waitsFor ->
callback.callCount is 1

Expand All @@ -35,6 +42,25 @@ describe 'apm command line interface', ->
expect(lines[0]).toBe "apm #{require('../package.json').version}"
expect(lines[1]).toBe "npm #{require('npm/package.json').version}"
expect(lines[2]).toBe "node #{process.versions.node} #{process.arch}"
expect(lines[3]).toBe "atom #{testAtomVersion}"

describe 'when the version flag is specified and apm is unable find package.json on the resourcePath', ->
it 'prints unknown atom version', ->
callback = jasmine.createSpy('callback')
apm.run(['-v', '--no-color'], callback)

testAtomVersion = 'unknown'
tempAtomResourcePath = temp.mkdirSync('apm-resource-dir-')
process.env.ATOM_RESOURCE_PATH = tempAtomResourcePath

waitsFor ->
callback.callCount is 1

runs ->
expect(console.error).not.toHaveBeenCalled()
expect(console.log).toHaveBeenCalled()
lines = console.log.argsForCall[0][0].split('\n')
expect(lines[3]).toBe "atom #{testAtomVersion}"

describe 'when an unrecognized command is specified', ->
it 'prints an error message and exits', ->
Expand Down
69 changes: 41 additions & 28 deletions src/apm-cli.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -100,34 +100,47 @@ printVersions = (args, callback) ->

getPythonVersion (pythonVersion) ->
git.getGitVersion (gitVersion) ->
if args.json
versions =
apm: apmVersion
npm: npmVersion
node: nodeVersion
python: pythonVersion
git: gitVersion
nodeArch: process.arch
if config.isWin32()
versions.visualStudio = config.getInstalledVisualStudioFlag()
console.log JSON.stringify(versions)
else
pythonVersion ?= ''
gitVersion ?= ''
versions = """
#{'apm'.red} #{apmVersion.red}
#{'npm'.green} #{npmVersion.green}
#{'node'.blue} #{nodeVersion.blue} #{process.arch.blue}
#{'python'.yellow} #{pythonVersion.yellow}
#{'git'.magenta} #{gitVersion.magenta}
"""

if config.isWin32()
visualStudioVersion = config.getInstalledVisualStudioFlag() ? ''
versions += "\n#{'visual studio'.cyan} #{visualStudioVersion.cyan}"

console.log versions
callback()
getAtomVersion (atomVersion) ->
if args.json
versions =
apm: apmVersion
npm: npmVersion
node: nodeVersion
atom: atomVersion
python: pythonVersion
git: gitVersion
nodeArch: process.arch
if config.isWin32()
versions.visualStudio = config.getInstalledVisualStudioFlag()
console.log JSON.stringify(versions)
else
pythonVersion ?= ''
gitVersion ?= ''
atomVersion ?= ''
versions = """
#{'apm'.red} #{apmVersion.red}
#{'npm'.green} #{npmVersion.green}
#{'node'.blue} #{nodeVersion.blue} #{process.arch.blue}
#{'atom'.cyan} #{atomVersion.cyan}
#{'python'.yellow} #{pythonVersion.yellow}
#{'git'.magenta} #{gitVersion.magenta}
"""

if config.isWin32()
visualStudioVersion = config.getInstalledVisualStudioFlag() ? ''
versions += "\n#{'visual studio'.cyan} #{visualStudioVersion.cyan}"

console.log versions
callback()

getAtomVersion = (callback) ->
config.getResourcePath (resourcePath) ->
unknownVersion = 'unknown'
try
{version} = require(path.join(resourcePath, 'package.json')) ? unknownVersion
callback(version)
catch error
callback(unknownVersion)

getPythonVersion = (callback) ->
npmOptions =
Expand Down