mirror of
https://github.com/atom/atom.git
synced 2026-01-22 13:28:01 -05:00
Create a comprehensive test for the new behavior in Project.
This commit is contained in:
@@ -24,8 +24,8 @@ describe "DefaultDirectoryProvider", ->
|
||||
it "creates a Directory for its parent dir when passed a file", ->
|
||||
provider = new DefaultDirectoryProvider()
|
||||
tmp = temp.mkdirSync()
|
||||
file = path.join(tmp, 'example.txt')
|
||||
fs.writeFileSync(file, 'data')
|
||||
file = path.join(tmp, "example.txt")
|
||||
fs.writeFileSync(file, "data")
|
||||
|
||||
directory = provider.directoryForURISync(file)
|
||||
expect(directory.getPath()).toEqual tmp
|
||||
|
||||
@@ -14,6 +14,76 @@ describe "Project", ->
|
||||
atom.project.setPaths([atom.project.getDirectories()[0]?.resolve('dir')])
|
||||
|
||||
describe "constructor", ->
|
||||
it "enables a custom DirectoryProvider to supersede the DefaultDirectoryProvider", ->
|
||||
remotePath = "ssh://foreign-directory:8080/"
|
||||
class DummyDirectory
|
||||
constructor: (@path) ->
|
||||
getPath: -> @path
|
||||
getFile: -> existsSync: -> false
|
||||
getSubdirectory: -> existsSync: -> false
|
||||
isRoot: -> true
|
||||
off: ->
|
||||
contains: (filePath) -> filePath.startsWith(remotePath)
|
||||
|
||||
directoryProvider =
|
||||
directoryForURISync: (uri) ->
|
||||
if uri.startsWith("ssh://")
|
||||
new DummyDirectory(uri)
|
||||
else
|
||||
null
|
||||
directoryForURI: (uri) -> throw new Error("This should not be called.")
|
||||
atom.packages.serviceHub.provide(
|
||||
"atom.directory-provider", "0.1.0", directoryProvider)
|
||||
|
||||
expect(atom.project.directoryProviders.length).toBe 2
|
||||
expect(atom.project.directoryProviders[0]).toBe directoryProvider
|
||||
|
||||
tmp = temp.mkdirSync()
|
||||
atom.project.setPaths([tmp, remotePath])
|
||||
directories = atom.project.getDirectories()
|
||||
expect(directories.length).toBe 2
|
||||
|
||||
localDirectory = directories[0]
|
||||
expect(localDirectory.getPath()).toBe tmp
|
||||
expect(localDirectory instanceof Directory).toBe true
|
||||
|
||||
dummyDirectory = directories[1]
|
||||
expect(dummyDirectory.getPath()).toBe remotePath
|
||||
expect(dummyDirectory instanceof DummyDirectory).toBe true
|
||||
|
||||
expect(atom.project.getPaths()).toEqual([tmp, remotePath])
|
||||
|
||||
# Make sure that DummyDirectory.contains() is honored.
|
||||
remotePathSubdirectory = remotePath + "a/subdirectory"
|
||||
atom.project.addPath(remotePathSubdirectory)
|
||||
expect(atom.project.getDirectories().length).toBe 2
|
||||
|
||||
# Make sure that a new DummyDirectory that is not contained by the first
|
||||
# DummyDirectory can be added.
|
||||
otherRemotePath = "ssh://other-foreign-directory:8080/"
|
||||
atom.project.addPath(otherRemotePath)
|
||||
newDirectories = atom.project.getDirectories()
|
||||
expect(newDirectories.length).toBe 3
|
||||
otherDummyDirectory = newDirectories[2]
|
||||
expect(otherDummyDirectory.getPath()).toBe otherRemotePath
|
||||
expect(otherDummyDirectory instanceof DummyDirectory).toBe true
|
||||
|
||||
it "a custom DirectoryProvider that returns null defaults to the DefaultDirectoryProvider", ->
|
||||
directoryProvider =
|
||||
directoryForURISync: (uri) -> null
|
||||
directoryForURI: (uri) -> throw new Error("This should not be called.")
|
||||
atom.packages.serviceHub.provide(
|
||||
"atom.directory-provider", "0.1.0", directoryProvider)
|
||||
|
||||
expect(atom.project.directoryProviders.length).toBe 2
|
||||
expect(atom.project.directoryProviders[0]).toBe directoryProvider
|
||||
|
||||
tmp = temp.mkdirSync()
|
||||
atom.project.setPaths([tmp])
|
||||
directories = atom.project.getDirectories()
|
||||
expect(directories.length).toBe 1
|
||||
expect(directories[0].getPath()).toBe tmp
|
||||
|
||||
it "tries to update repositories when a new RepositoryProvider is registered", ->
|
||||
tmp = temp.mkdirSync('atom-project')
|
||||
atom.project.setPaths([tmp])
|
||||
|
||||
@@ -167,7 +167,7 @@ class Project extends Model
|
||||
|
||||
# Public: Get an {Array} of {String}s containing the paths of the project's
|
||||
# directories.
|
||||
getPaths: -> rootDirectory.path for rootDirectory in @rootDirectories
|
||||
getPaths: -> rootDirectory.getPath() for rootDirectory in @rootDirectories
|
||||
getPath: ->
|
||||
Grim.deprecate("Use ::getPaths instead")
|
||||
@getPaths()[0]
|
||||
|
||||
Reference in New Issue
Block a user