2013-09-24 02:46:57 +04:00
|
|
|
temp = require 'temp'
|
|
|
|
fstream = require 'fstream'
|
2013-09-18 05:58:41 +04:00
|
|
|
Project = require '../src/project'
|
2014-02-24 05:09:05 +04:00
|
|
|
_ = require 'underscore-plus'
|
|
|
|
fs = require 'fs-plus'
|
2013-06-13 02:26:09 +04:00
|
|
|
path = require 'path'
|
2013-09-18 05:58:41 +04:00
|
|
|
BufferedProcess = require '../src/buffered-process'
|
2015-02-12 07:51:26 +03:00
|
|
|
{Directory} = require 'pathwatcher'
|
|
|
|
GitRepository = require '../src/git-repository'
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "Project", ->
|
|
|
|
beforeEach ->
|
2015-01-10 01:54:54 +03:00
|
|
|
atom.project.setPaths([atom.project.getDirectories()[0]?.resolve('dir')])
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2015-07-27 20:16:11 +03:00
|
|
|
# Wait for project's service consumers to be asynchronously added
|
|
|
|
waits(1)
|
|
|
|
|
2013-08-29 05:37:40 +04:00
|
|
|
describe "serialization", ->
|
2013-08-30 05:24:51 +04:00
|
|
|
deserializedProject = null
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
deserializedProject?.destroy()
|
|
|
|
|
2016-03-02 04:22:43 +03:00
|
|
|
it "does not deserialize paths to non directories", ->
|
|
|
|
deserializedProject = new Project({notificationManager: atom.notifications, packageManager: atom.packages, confirm: atom.confirm})
|
|
|
|
state = atom.project.serialize()
|
|
|
|
state.paths.push('/directory/that/does/not/exist')
|
|
|
|
state.paths.push(path.join(__dirname, 'fixtures', 'sample.js'))
|
|
|
|
deserializedProject.deserialize(state, atom.deserializers)
|
|
|
|
expect(deserializedProject.getPaths()).toEqual(atom.project.getPaths())
|
|
|
|
|
2014-01-04 03:23:23 +04:00
|
|
|
it "does not include unretained buffers in the serialized state", ->
|
2014-04-24 03:50:25 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.bufferForPath('a')
|
2013-11-21 04:45:26 +04:00
|
|
|
|
2014-04-24 03:50:25 +04:00
|
|
|
runs ->
|
|
|
|
expect(atom.project.getBuffers().length).toBe 1
|
2015-10-02 21:12:16 +03:00
|
|
|
|
2015-10-02 21:39:18 +03:00
|
|
|
deserializedProject = new Project({notificationManager: atom.notifications, packageManager: atom.packages, confirm: atom.confirm})
|
2016-03-07 12:52:16 +03:00
|
|
|
deserializedProject.deserialize(atom.project.serialize({isUnloading: false}))
|
2014-04-24 03:50:25 +04:00
|
|
|
expect(deserializedProject.getBuffers().length).toBe 0
|
2013-08-29 05:37:40 +04:00
|
|
|
|
2013-11-19 21:08:24 +04:00
|
|
|
it "listens for destroyed events on deserialized buffers and removes them when they are destroyed", ->
|
2014-04-24 03:50:25 +04:00
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open('a')
|
2013-11-19 21:08:24 +04:00
|
|
|
|
2014-04-24 03:50:25 +04:00
|
|
|
runs ->
|
|
|
|
expect(atom.project.getBuffers().length).toBe 1
|
2015-10-02 21:39:18 +03:00
|
|
|
deserializedProject = new Project({notificationManager: atom.notifications, packageManager: atom.packages, confirm: atom.confirm})
|
2016-03-07 12:52:16 +03:00
|
|
|
deserializedProject.deserialize(atom.project.serialize({isUnloading: false}))
|
2014-04-24 03:50:25 +04:00
|
|
|
|
|
|
|
expect(deserializedProject.getBuffers().length).toBe 1
|
|
|
|
deserializedProject.getBuffers()[0].destroy()
|
|
|
|
expect(deserializedProject.getBuffers().length).toBe 0
|
2013-11-19 21:08:24 +04:00
|
|
|
|
2015-01-15 22:51:11 +03:00
|
|
|
|
2015-01-15 22:53:39 +03:00
|
|
|
it "does not deserialize buffers when their path is a directory that exists", ->
|
2015-01-15 22:51:11 +03:00
|
|
|
pathToOpen = path.join(temp.mkdirSync(), 'file.txt')
|
|
|
|
|
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open(pathToOpen)
|
2015-01-15 22:51:11 +03:00
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(atom.project.getBuffers().length).toBe 1
|
|
|
|
fs.mkdirSync(pathToOpen)
|
2015-10-02 21:39:18 +03:00
|
|
|
deserializedProject = new Project({notificationManager: atom.notifications, packageManager: atom.packages, confirm: atom.confirm})
|
2016-03-07 12:52:16 +03:00
|
|
|
deserializedProject.deserialize(atom.project.serialize({isUnloading: false}))
|
2015-01-16 00:08:16 +03:00
|
|
|
expect(deserializedProject.getBuffers().length).toBe 0
|
|
|
|
|
|
|
|
it "does not deserialize buffers when their path is inaccessible", ->
|
|
|
|
pathToOpen = path.join(temp.mkdirSync(), 'file.txt')
|
|
|
|
fs.writeFileSync(pathToOpen, '')
|
|
|
|
|
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open(pathToOpen)
|
2015-01-16 00:08:16 +03:00
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(atom.project.getBuffers().length).toBe 1
|
|
|
|
fs.chmodSync(pathToOpen, '000')
|
2015-10-02 21:39:18 +03:00
|
|
|
deserializedProject = new Project({notificationManager: atom.notifications, packageManager: atom.packages, confirm: atom.confirm})
|
2016-03-07 12:52:16 +03:00
|
|
|
deserializedProject.deserialize(atom.project.serialize({isUnloading: false}))
|
2015-01-15 22:51:11 +03:00
|
|
|
expect(deserializedProject.getBuffers().length).toBe 0
|
|
|
|
|
2016-03-04 19:53:14 +03:00
|
|
|
it "serializes marker layers only if Atom is quitting", ->
|
2016-03-04 18:57:02 +03:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open('a')
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
bufferA = atom.project.getBuffers()[0]
|
2016-04-09 10:30:47 +03:00
|
|
|
layerA = bufferA.addMarkerLayer(persistent: true)
|
2016-03-04 18:57:02 +03:00
|
|
|
markerA = layerA.markPosition([0, 3])
|
|
|
|
|
|
|
|
notQuittingProject = new Project({notificationManager: atom.notifications, packageManager: atom.packages, confirm: atom.confirm})
|
2016-03-07 12:52:16 +03:00
|
|
|
notQuittingProject.deserialize(atom.project.serialize({isUnloading: false}))
|
2016-03-04 18:57:02 +03:00
|
|
|
expect(notQuittingProject.getBuffers()[0].getMarkerLayer(layerA.id)?.getMarker(markerA.id)).toBeUndefined()
|
|
|
|
|
|
|
|
quittingProject = new Project({notificationManager: atom.notifications, packageManager: atom.packages, confirm: atom.confirm})
|
2016-03-07 12:52:16 +03:00
|
|
|
quittingProject.deserialize(atom.project.serialize({isUnloading: true}))
|
2016-03-04 18:57:02 +03:00
|
|
|
expect(quittingProject.getBuffers()[0].getMarkerLayer(layerA.id)?.getMarker(markerA.id)).not.toBeUndefined()
|
|
|
|
|
2014-04-08 21:52:19 +04:00
|
|
|
describe "when an editor is saved and the project has no path", ->
|
2013-02-28 03:21:42 +04:00
|
|
|
it "sets the project's path to the saved file's parent directory", ->
|
2013-10-04 00:22:05 +04:00
|
|
|
tempFile = temp.openSync().path
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([])
|
|
|
|
expect(atom.project.getPaths()[0]).toBeUndefined()
|
2014-04-24 03:50:25 +04:00
|
|
|
editor = null
|
2013-02-28 03:21:42 +04:00
|
|
|
|
2014-04-24 03:50:25 +04:00
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open().then (o) -> editor = o
|
2014-02-13 04:56:00 +04:00
|
|
|
|
2014-04-24 03:50:25 +04:00
|
|
|
runs ->
|
|
|
|
editor.saveAs(tempFile)
|
2014-10-01 20:37:27 +04:00
|
|
|
expect(atom.project.getPaths()[0]).toBe path.dirname(tempFile)
|
2013-05-15 06:23:25 +04:00
|
|
|
|
2016-05-23 19:37:26 +03:00
|
|
|
describe "before and after saving a buffer", ->
|
|
|
|
[buffer] = []
|
|
|
|
beforeEach ->
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.bufferForPath(path.join(__dirname, 'fixtures', 'sample.js')).then (o) ->
|
|
|
|
buffer = o
|
|
|
|
buffer.retain()
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
buffer.release()
|
|
|
|
|
|
|
|
it "emits save events on the main process", ->
|
|
|
|
spyOn(atom.project.applicationDelegate, 'emitDidSavePath')
|
|
|
|
spyOn(atom.project.applicationDelegate, 'emitWillSavePath')
|
|
|
|
|
|
|
|
buffer.save()
|
|
|
|
|
|
|
|
expect(atom.project.applicationDelegate.emitDidSavePath.calls.length).toBe(1)
|
|
|
|
expect(atom.project.applicationDelegate.emitDidSavePath).toHaveBeenCalledWith(buffer.getPath())
|
|
|
|
expect(atom.project.applicationDelegate.emitWillSavePath.calls.length).toBe(1)
|
|
|
|
expect(atom.project.applicationDelegate.emitWillSavePath).toHaveBeenCalledWith(buffer.getPath())
|
|
|
|
|
2015-01-09 04:10:59 +03:00
|
|
|
describe "when a watch error is thrown from the TextBuffer", ->
|
|
|
|
editor = null
|
|
|
|
beforeEach ->
|
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open(require.resolve('./fixtures/dir/a')).then (o) -> editor = o
|
2015-01-09 04:10:59 +03:00
|
|
|
|
|
|
|
it "creates a warning notification", ->
|
|
|
|
atom.notifications.onDidAddNotification noteSpy = jasmine.createSpy()
|
|
|
|
|
2015-01-14 23:46:31 +03:00
|
|
|
error = new Error('SomeError')
|
|
|
|
error.eventType = 'resurrect'
|
2015-01-09 04:10:59 +03:00
|
|
|
editor.buffer.emitter.emit 'will-throw-watch-error',
|
|
|
|
handle: jasmine.createSpy()
|
2015-01-14 23:46:31 +03:00
|
|
|
error: error
|
2015-01-09 04:10:59 +03:00
|
|
|
|
|
|
|
expect(noteSpy).toHaveBeenCalled()
|
|
|
|
|
|
|
|
notification = noteSpy.mostRecentCall.args[0]
|
|
|
|
expect(notification.getType()).toBe 'warning'
|
|
|
|
expect(notification.getDetail()).toBe 'SomeError'
|
2015-01-14 23:46:31 +03:00
|
|
|
expect(notification.getMessage()).toContain '`resurrect`'
|
2015-01-15 02:17:55 +03:00
|
|
|
expect(notification.getMessage()).toContain 'fixtures/dir/a'
|
2015-01-09 04:10:59 +03:00
|
|
|
|
2015-10-09 01:11:43 +03:00
|
|
|
describe "when a custom repository-provider service is provided", ->
|
|
|
|
[fakeRepositoryProvider, fakeRepository] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
fakeRepository = {destroy: -> null}
|
|
|
|
fakeRepositoryProvider = {
|
|
|
|
repositoryForDirectory: (directory) -> Promise.resolve(fakeRepository)
|
|
|
|
repositoryForDirectorySync: (directory) -> fakeRepository
|
|
|
|
}
|
|
|
|
|
|
|
|
it "uses it to create repositories for any directories that need one", ->
|
|
|
|
projectPath = temp.mkdirSync('atom-project')
|
|
|
|
atom.project.setPaths([projectPath])
|
|
|
|
expect(atom.project.getRepositories()).toEqual [null]
|
|
|
|
|
|
|
|
atom.packages.serviceHub.provide("atom.repository-provider", "0.1.0", fakeRepositoryProvider)
|
|
|
|
waitsFor -> atom.project.repositoryProviders.length > 1
|
|
|
|
runs -> atom.project.getRepositories()[0] is fakeRepository
|
|
|
|
|
|
|
|
it "does not create any new repositories if every directory has a repository", ->
|
|
|
|
repositories = atom.project.getRepositories()
|
|
|
|
expect(repositories.length).toEqual 1
|
|
|
|
expect(repositories[0]).toBeTruthy()
|
|
|
|
|
|
|
|
atom.packages.serviceHub.provide("atom.repository-provider", "0.1.0", fakeRepositoryProvider)
|
|
|
|
waitsFor -> atom.project.repositoryProviders.length > 1
|
|
|
|
runs -> expect(atom.project.getRepositories()).toBe repositories
|
|
|
|
|
|
|
|
it "stops using it to create repositories when the service is removed", ->
|
|
|
|
atom.project.setPaths([])
|
|
|
|
|
|
|
|
disposable = atom.packages.serviceHub.provide("atom.repository-provider", "0.1.0", fakeRepositoryProvider)
|
|
|
|
waitsFor -> atom.project.repositoryProviders.length > 1
|
|
|
|
runs ->
|
|
|
|
disposable.dispose()
|
|
|
|
atom.project.addPath(temp.mkdirSync('atom-project'))
|
|
|
|
expect(atom.project.getRepositories()).toEqual [null]
|
|
|
|
|
|
|
|
describe "when a custom directory-provider service is provided", ->
|
|
|
|
class DummyDirectory
|
|
|
|
constructor: (@path) ->
|
|
|
|
getPath: -> @path
|
|
|
|
getFile: -> {existsSync: -> false}
|
|
|
|
getSubdirectory: -> {existsSync: -> false}
|
|
|
|
isRoot: -> true
|
|
|
|
existsSync: -> @path.endsWith('does-exist')
|
|
|
|
contains: (filePath) -> filePath.startsWith(@path)
|
|
|
|
|
2015-10-09 01:20:13 +03:00
|
|
|
serviceDisposable = null
|
|
|
|
|
2015-10-09 01:11:43 +03:00
|
|
|
beforeEach ->
|
2015-10-09 01:20:13 +03:00
|
|
|
serviceDisposable = atom.packages.serviceHub.provide("atom.directory-provider", "0.1.0", {
|
2015-10-09 01:11:43 +03:00
|
|
|
directoryForURISync: (uri) ->
|
|
|
|
if uri.startsWith("ssh://")
|
|
|
|
new DummyDirectory(uri)
|
|
|
|
else
|
|
|
|
null
|
|
|
|
})
|
|
|
|
|
|
|
|
waitsFor ->
|
|
|
|
atom.project.directoryProviders.length > 0
|
|
|
|
|
|
|
|
it "uses the provider's custom directories for any paths that it handles", ->
|
|
|
|
localPath = temp.mkdirSync('local-path')
|
|
|
|
remotePath = "ssh://foreign-directory:8080/does-exist"
|
|
|
|
|
|
|
|
atom.project.setPaths([localPath, remotePath])
|
|
|
|
|
|
|
|
directories = atom.project.getDirectories()
|
|
|
|
expect(directories[0].getPath()).toBe localPath
|
|
|
|
expect(directories[0] instanceof Directory).toBe true
|
|
|
|
expect(directories[1].getPath()).toBe remotePath
|
|
|
|
expect(directories[1] instanceof DummyDirectory).toBe true
|
|
|
|
|
|
|
|
# It does not add new remote paths if their directories do not exist
|
|
|
|
# and they are contained by existing remote paths.
|
|
|
|
childRemotePath = remotePath + "/subdirectory/that/does-not-exist"
|
|
|
|
atom.project.addPath(childRemotePath)
|
|
|
|
expect(atom.project.getDirectories().length).toBe 2
|
|
|
|
|
|
|
|
# It does add new remote paths if their directories exist.
|
|
|
|
childRemotePath = remotePath + "/subdirectory/that/does-exist"
|
|
|
|
atom.project.addPath(childRemotePath)
|
|
|
|
directories = atom.project.getDirectories()
|
|
|
|
expect(directories[2].getPath()).toBe childRemotePath
|
|
|
|
expect(directories[2] instanceof DummyDirectory).toBe true
|
|
|
|
|
|
|
|
# It does add new remote paths to be added if they are not contained by
|
|
|
|
# previous remote paths.
|
|
|
|
otherRemotePath = "ssh://other-foreign-directory:8080/"
|
|
|
|
atom.project.addPath(otherRemotePath)
|
|
|
|
directories = atom.project.getDirectories()
|
|
|
|
expect(directories[3].getPath()).toBe otherRemotePath
|
|
|
|
expect(directories[3] instanceof DummyDirectory).toBe true
|
|
|
|
|
2015-10-09 01:20:13 +03:00
|
|
|
it "stops using the provider when the service is removed", ->
|
|
|
|
serviceDisposable.dispose()
|
|
|
|
atom.project.setPaths(["ssh://foreign-directory:8080/does-exist"])
|
|
|
|
expect(atom.project.getDirectories()[0] instanceof Directory).toBe true
|
|
|
|
|
2014-02-13 04:56:00 +04:00
|
|
|
describe ".open(path)", ->
|
2014-04-08 21:52:19 +04:00
|
|
|
[absolutePath, newBufferHandler] = []
|
2014-02-13 04:56:00 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
absolutePath = require.resolve('./fixtures/dir/a')
|
|
|
|
newBufferHandler = jasmine.createSpy('newBufferHandler')
|
2015-04-07 02:21:09 +03:00
|
|
|
atom.project.onDidAddBuffer(newBufferHandler)
|
2013-05-15 06:23:25 +04:00
|
|
|
|
2014-02-13 04:56:00 +04:00
|
|
|
describe "when given an absolute path that isn't currently open", ->
|
2014-04-08 21:52:19 +04:00
|
|
|
it "returns a new edit session for the given path and emits 'buffer-created'", ->
|
2014-02-13 04:56:00 +04:00
|
|
|
editor = null
|
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open(absolutePath).then (o) -> editor = o
|
2014-02-13 04:56:00 +04:00
|
|
|
|
|
|
|
runs ->
|
2013-11-20 03:22:47 +04:00
|
|
|
expect(editor.buffer.getPath()).toBe absolutePath
|
|
|
|
expect(newBufferHandler).toHaveBeenCalledWith editor.buffer
|
2013-05-15 06:23:25 +04:00
|
|
|
|
2014-02-13 04:56:00 +04:00
|
|
|
describe "when given a relative path that isn't currently opened", ->
|
2014-04-08 21:52:19 +04:00
|
|
|
it "returns a new edit session for the given path (relative to the project root) and emits 'buffer-created'", ->
|
2014-02-13 04:56:00 +04:00
|
|
|
editor = null
|
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open(absolutePath).then (o) -> editor = o
|
2014-02-13 04:56:00 +04:00
|
|
|
|
|
|
|
runs ->
|
2013-11-20 03:22:47 +04:00
|
|
|
expect(editor.buffer.getPath()).toBe absolutePath
|
|
|
|
expect(newBufferHandler).toHaveBeenCalledWith editor.buffer
|
2013-05-15 06:23:25 +04:00
|
|
|
|
2014-02-13 04:56:00 +04:00
|
|
|
describe "when passed the path to a buffer that is currently opened", ->
|
2014-04-08 21:52:19 +04:00
|
|
|
it "returns a new edit session containing currently opened buffer", ->
|
2014-02-13 04:56:00 +04:00
|
|
|
editor = null
|
2014-04-24 03:50:25 +04:00
|
|
|
|
2014-02-13 04:56:00 +04:00
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open(absolutePath).then (o) -> editor = o
|
2014-02-13 04:56:00 +04:00
|
|
|
|
|
|
|
runs ->
|
2013-05-15 06:23:25 +04:00
|
|
|
newBufferHandler.reset()
|
2014-04-24 03:50:25 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open(absolutePath).then ({buffer}) ->
|
2014-04-24 03:50:25 +04:00
|
|
|
expect(buffer).toBe editor.buffer
|
|
|
|
|
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open('a').then ({buffer}) ->
|
2014-04-24 03:50:25 +04:00
|
|
|
expect(buffer).toBe editor.buffer
|
|
|
|
expect(newBufferHandler).not.toHaveBeenCalled()
|
2013-05-15 06:23:25 +04:00
|
|
|
|
2014-02-13 04:56:00 +04:00
|
|
|
describe "when not passed a path", ->
|
2014-04-08 21:52:19 +04:00
|
|
|
it "returns a new edit session and emits 'buffer-created'", ->
|
2014-02-13 04:56:00 +04:00
|
|
|
editor = null
|
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open().then (o) -> editor = o
|
2014-02-13 04:56:00 +04:00
|
|
|
|
|
|
|
runs ->
|
2013-11-20 03:22:47 +04:00
|
|
|
expect(editor.buffer.getPath()).toBeUndefined()
|
|
|
|
expect(newBufferHandler).toHaveBeenCalledWith(editor.buffer)
|
2013-05-15 06:23:25 +04:00
|
|
|
|
2013-10-15 21:58:33 +04:00
|
|
|
describe ".bufferForPath(path)", ->
|
2013-10-03 03:17:49 +04:00
|
|
|
[buffer] = []
|
|
|
|
beforeEach ->
|
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.bufferForPath("a").then (o) ->
|
2013-10-03 03:17:49 +04:00
|
|
|
buffer = o
|
|
|
|
buffer.retain()
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
buffer.release()
|
|
|
|
|
|
|
|
describe "when opening a previously opened path", ->
|
|
|
|
it "does not create a new buffer", ->
|
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.bufferForPath("a").then (anotherBuffer) ->
|
2013-10-03 03:17:49 +04:00
|
|
|
expect(anotherBuffer).toBe buffer
|
|
|
|
|
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.bufferForPath("b").then (anotherBuffer) ->
|
2013-10-03 03:17:49 +04:00
|
|
|
expect(anotherBuffer).not.toBe buffer
|
|
|
|
|
|
|
|
it "creates a new buffer if the previous buffer was destroyed", ->
|
|
|
|
buffer.release()
|
|
|
|
|
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.bufferForPath("b").then (anotherBuffer) ->
|
2013-10-03 03:17:49 +04:00
|
|
|
expect(anotherBuffer).not.toBe buffer
|
|
|
|
|
2015-02-12 07:51:26 +03:00
|
|
|
describe ".repositoryForDirectory(directory)", ->
|
2015-02-12 20:28:26 +03:00
|
|
|
it "resolves to null when the directory does not have a repository", ->
|
2015-02-12 07:51:26 +03:00
|
|
|
waitsForPromise ->
|
|
|
|
directory = new Directory("/tmp")
|
2015-02-12 20:47:11 +03:00
|
|
|
atom.project.repositoryForDirectory(directory).then (result) ->
|
|
|
|
expect(result).toBeNull()
|
|
|
|
expect(atom.project.repositoryProviders.length).toBeGreaterThan 0
|
|
|
|
expect(atom.project.repositoryPromisesByPath.size).toBe 0
|
2015-02-12 07:51:26 +03:00
|
|
|
|
2015-02-12 20:28:26 +03:00
|
|
|
it "resolves to a GitRepository and is cached when the given directory is a Git repo", ->
|
2015-02-12 07:51:26 +03:00
|
|
|
waitsForPromise ->
|
2015-02-12 20:47:11 +03:00
|
|
|
directory = new Directory(path.join(__dirname, '..'))
|
2015-02-12 20:52:48 +03:00
|
|
|
promise = atom.project.repositoryForDirectory(directory)
|
|
|
|
promise.then (result) ->
|
2015-02-12 20:47:11 +03:00
|
|
|
expect(result).toBeInstanceOf GitRepository
|
|
|
|
dirPath = directory.getRealPathSync()
|
|
|
|
expect(result.getPath()).toBe path.join(dirPath, '.git')
|
|
|
|
|
|
|
|
# Verify that the result is cached.
|
2015-02-12 20:52:48 +03:00
|
|
|
expect(atom.project.repositoryForDirectory(directory)).toBe(promise)
|
2015-02-12 07:51:26 +03:00
|
|
|
|
2016-06-20 18:06:50 +03:00
|
|
|
it "creates a new repository if a previous one with the same directory had been destroyed", ->
|
|
|
|
repository = null
|
|
|
|
directory = new Directory(path.join(__dirname, '..'))
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.repositoryForDirectory(directory).then (repo) -> repository = repo
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(repository.isDestroyed()).toBe(false)
|
|
|
|
repository.destroy()
|
|
|
|
expect(repository.isDestroyed()).toBe(true)
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.repositoryForDirectory(directory).then (repo) -> repository = repo
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(repository.isDestroyed()).toBe(false)
|
|
|
|
|
2015-08-26 23:51:07 +03:00
|
|
|
describe ".setPaths(paths)", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
describe "when path is a file", ->
|
|
|
|
it "sets its path to the files parent directory and updates the root directory", ->
|
2015-08-26 23:51:07 +03:00
|
|
|
filePath = require.resolve('./fixtures/dir/a')
|
|
|
|
atom.project.setPaths([filePath])
|
|
|
|
expect(atom.project.getPaths()[0]).toEqual path.dirname(filePath)
|
|
|
|
expect(atom.project.getDirectories()[0].path).toEqual path.dirname(filePath)
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "when path is a directory", ->
|
2015-02-13 08:16:15 +03:00
|
|
|
it "assigns the directories and repositories", ->
|
|
|
|
directory1 = temp.mkdirSync("non-git-repo")
|
|
|
|
directory2 = temp.mkdirSync("git-repo1")
|
|
|
|
directory3 = temp.mkdirSync("git-repo2")
|
|
|
|
|
2015-02-13 09:14:02 +03:00
|
|
|
gitDirPath = fs.absolute(path.join(__dirname, 'fixtures', 'git', 'master.git'))
|
|
|
|
fs.copySync(gitDirPath, path.join(directory2, ".git"))
|
|
|
|
fs.copySync(gitDirPath, path.join(directory3, ".git"))
|
2015-02-13 08:16:15 +03:00
|
|
|
|
2015-02-13 09:14:02 +03:00
|
|
|
atom.project.setPaths([directory1, directory2, directory3])
|
2015-02-13 08:16:15 +03:00
|
|
|
|
2015-02-13 09:14:02 +03:00
|
|
|
[repo1, repo2, repo3] = atom.project.getRepositories()
|
|
|
|
expect(repo1).toBeNull()
|
|
|
|
expect(repo2.getShortHead()).toBe "master"
|
|
|
|
expect(repo2.getPath()).toBe fs.realpathSync(path.join(directory2, ".git"))
|
|
|
|
expect(repo3.getShortHead()).toBe "master"
|
|
|
|
expect(repo3.getPath()).toBe fs.realpathSync(path.join(directory3, ".git"))
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2015-02-10 22:53:50 +03:00
|
|
|
it "calls callbacks registered with ::onDidChangePaths", ->
|
|
|
|
onDidChangePathsSpy = jasmine.createSpy('onDidChangePaths spy')
|
|
|
|
atom.project.onDidChangePaths(onDidChangePathsSpy)
|
|
|
|
|
|
|
|
paths = [ temp.mkdirSync("dir1"), temp.mkdirSync("dir2") ]
|
|
|
|
atom.project.setPaths(paths)
|
|
|
|
|
|
|
|
expect(onDidChangePathsSpy.callCount).toBe 1
|
|
|
|
expect(onDidChangePathsSpy.mostRecentCall.args[0]).toEqual(paths)
|
|
|
|
|
2015-08-26 23:51:07 +03:00
|
|
|
describe "when no paths are given", ->
|
|
|
|
it "clears its path", ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([])
|
2015-08-26 23:51:07 +03:00
|
|
|
expect(atom.project.getPaths()).toEqual []
|
|
|
|
expect(atom.project.getDirectories()).toEqual []
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2014-09-02 21:47:05 +04:00
|
|
|
it "normalizes the path to remove consecutive slashes, ., and .. segments", ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths(["#{require.resolve('./fixtures/dir/a')}#{path.sep}b#{path.sep}#{path.sep}.."])
|
|
|
|
expect(atom.project.getPaths()[0]).toEqual path.dirname(require.resolve('./fixtures/dir/a'))
|
2014-11-26 01:54:06 +03:00
|
|
|
expect(atom.project.getDirectories()[0].path).toEqual path.dirname(require.resolve('./fixtures/dir/a'))
|
2014-09-02 21:47:05 +04:00
|
|
|
|
2015-08-26 23:51:07 +03:00
|
|
|
it "only normalizes the directory path if it isn't on the local filesystem", ->
|
|
|
|
nonLocalFsDirectory = "custom_proto://abc/def"
|
|
|
|
atom.project.setPaths([nonLocalFsDirectory])
|
|
|
|
directories = atom.project.getDirectories()
|
|
|
|
expect(directories.length).toBe 1
|
|
|
|
expect(directories[0].getPath()).toBe path.normalize(nonLocalFsDirectory)
|
|
|
|
|
2015-02-10 22:53:50 +03:00
|
|
|
describe ".addPath(path)", ->
|
|
|
|
it "calls callbacks registered with ::onDidChangePaths", ->
|
|
|
|
onDidChangePathsSpy = jasmine.createSpy('onDidChangePaths spy')
|
|
|
|
atom.project.onDidChangePaths(onDidChangePathsSpy)
|
|
|
|
|
|
|
|
[oldPath] = atom.project.getPaths()
|
|
|
|
|
|
|
|
newPath = temp.mkdirSync("dir")
|
|
|
|
atom.project.addPath(newPath)
|
|
|
|
|
|
|
|
expect(onDidChangePathsSpy.callCount).toBe 1
|
|
|
|
expect(onDidChangePathsSpy.mostRecentCall.args[0]).toEqual([oldPath, newPath])
|
|
|
|
|
2015-08-26 23:51:07 +03:00
|
|
|
it "doesn't add redundant paths", ->
|
|
|
|
onDidChangePathsSpy = jasmine.createSpy('onDidChangePaths spy')
|
|
|
|
atom.project.onDidChangePaths(onDidChangePathsSpy)
|
|
|
|
[oldPath] = atom.project.getPaths()
|
2015-02-13 08:18:18 +03:00
|
|
|
|
2015-08-26 23:51:07 +03:00
|
|
|
# Doesn't re-add an existing root directory
|
|
|
|
atom.project.addPath(oldPath)
|
|
|
|
expect(atom.project.getPaths()).toEqual([oldPath])
|
|
|
|
expect(onDidChangePathsSpy).not.toHaveBeenCalled()
|
2015-02-13 08:18:18 +03:00
|
|
|
|
2015-08-26 23:51:07 +03:00
|
|
|
# Doesn't add an entry for a file-path within an existing root directory
|
|
|
|
atom.project.addPath(path.join(oldPath, 'some-file.txt'))
|
|
|
|
expect(atom.project.getPaths()).toEqual([oldPath])
|
|
|
|
expect(onDidChangePathsSpy).not.toHaveBeenCalled()
|
2015-02-13 08:18:18 +03:00
|
|
|
|
2015-08-26 23:51:07 +03:00
|
|
|
# Does add an entry for a directory within an existing directory
|
|
|
|
newPath = path.join(oldPath, "a-dir")
|
|
|
|
atom.project.addPath(newPath)
|
|
|
|
expect(atom.project.getPaths()).toEqual([oldPath, newPath])
|
|
|
|
expect(onDidChangePathsSpy).toHaveBeenCalled()
|
2015-02-19 21:02:37 +03:00
|
|
|
|
|
|
|
describe ".removePath(path)", ->
|
|
|
|
onDidChangePathsSpy = null
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
onDidChangePathsSpy = jasmine.createSpy('onDidChangePaths listener')
|
|
|
|
atom.project.onDidChangePaths(onDidChangePathsSpy)
|
|
|
|
|
|
|
|
it "removes the directory and repository for the path", ->
|
|
|
|
result = atom.project.removePath(atom.project.getPaths()[0])
|
|
|
|
expect(atom.project.getDirectories()).toEqual([])
|
|
|
|
expect(atom.project.getRepositories()).toEqual([])
|
|
|
|
expect(atom.project.getPaths()).toEqual([])
|
|
|
|
expect(result).toBe true
|
|
|
|
expect(onDidChangePathsSpy).toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "does nothing if the path is not one of the project's root paths", ->
|
|
|
|
originalPaths = atom.project.getPaths()
|
|
|
|
result = atom.project.removePath(originalPaths[0] + "xyz")
|
|
|
|
expect(result).toBe false
|
|
|
|
expect(atom.project.getPaths()).toEqual(originalPaths)
|
|
|
|
expect(onDidChangePathsSpy).not.toHaveBeenCalled()
|
2015-02-13 08:18:18 +03:00
|
|
|
|
2015-02-19 21:28:54 +03:00
|
|
|
it "doesn't destroy the repository if it is shared by another root directory", ->
|
|
|
|
atom.project.setPaths([__dirname, path.join(__dirname, "..", "src")])
|
|
|
|
atom.project.removePath(__dirname)
|
|
|
|
expect(atom.project.getPaths()).toEqual([path.join(__dirname, "..", "src")])
|
|
|
|
expect(atom.project.getRepositories()[0].isSubmodule("src")).toBe false
|
|
|
|
|
2015-03-04 03:48:58 +03:00
|
|
|
it "removes a path that is represented as a URI", ->
|
2015-08-26 23:51:07 +03:00
|
|
|
atom.packages.serviceHub.provide("atom.directory-provider", "0.1.0", {
|
2015-03-04 03:48:58 +03:00
|
|
|
directoryForURISync: (uri) ->
|
2015-08-26 23:51:07 +03:00
|
|
|
{
|
|
|
|
getPath: -> uri
|
|
|
|
getSubdirectory: -> {}
|
|
|
|
isRoot: -> true
|
|
|
|
existsSync: -> true
|
|
|
|
off: ->
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
ftpURI = "ftp://example.com/some/folder"
|
|
|
|
|
2015-03-04 03:48:58 +03:00
|
|
|
atom.project.setPaths([ftpURI])
|
|
|
|
expect(atom.project.getPaths()).toEqual [ftpURI]
|
2015-08-26 23:51:07 +03:00
|
|
|
|
2015-03-04 03:48:58 +03:00
|
|
|
atom.project.removePath(ftpURI)
|
|
|
|
expect(atom.project.getPaths()).toEqual []
|
|
|
|
|
2015-02-13 08:16:15 +03:00
|
|
|
describe ".relativize(path)", ->
|
|
|
|
it "returns the path, relative to whichever root directory it is inside of", ->
|
2015-02-19 03:47:21 +03:00
|
|
|
atom.project.addPath(temp.mkdirSync("another-path"))
|
|
|
|
|
2015-02-13 08:16:15 +03:00
|
|
|
rootPath = atom.project.getPaths()[0]
|
|
|
|
childPath = path.join(rootPath, "some", "child", "directory")
|
|
|
|
expect(atom.project.relativize(childPath)).toBe path.join("some", "child", "directory")
|
|
|
|
|
2015-02-19 03:47:21 +03:00
|
|
|
rootPath = atom.project.getPaths()[1]
|
|
|
|
childPath = path.join(rootPath, "some", "child", "directory")
|
|
|
|
expect(atom.project.relativize(childPath)).toBe path.join("some", "child", "directory")
|
|
|
|
|
2015-02-13 08:16:15 +03:00
|
|
|
it "returns the given path if it is not in any of the root directories", ->
|
|
|
|
randomPath = path.join("some", "random", "path")
|
|
|
|
expect(atom.project.relativize(randomPath)).toBe randomPath
|
|
|
|
|
2015-02-26 19:46:00 +03:00
|
|
|
describe ".relativizePath(path)", ->
|
2015-02-26 03:49:30 +03:00
|
|
|
it "returns the root path that contains the given path, and the path relativized to that root path", ->
|
|
|
|
atom.project.addPath(temp.mkdirSync("another-path"))
|
|
|
|
|
|
|
|
rootPath = atom.project.getPaths()[0]
|
|
|
|
childPath = path.join(rootPath, "some", "child", "directory")
|
2015-02-26 19:46:00 +03:00
|
|
|
expect(atom.project.relativizePath(childPath)).toEqual [rootPath, path.join("some", "child", "directory")]
|
2015-02-26 03:49:30 +03:00
|
|
|
|
|
|
|
rootPath = atom.project.getPaths()[1]
|
|
|
|
childPath = path.join(rootPath, "some", "child", "directory")
|
2015-02-26 19:46:00 +03:00
|
|
|
expect(atom.project.relativizePath(childPath)).toEqual [rootPath, path.join("some", "child", "directory")]
|
2015-02-26 03:49:30 +03:00
|
|
|
|
|
|
|
describe "when the given path isn't inside of any of the project's path", ->
|
|
|
|
it "returns null for the root path, and the given path unchanged", ->
|
|
|
|
randomPath = path.join("some", "random", "path")
|
2015-02-26 19:46:00 +03:00
|
|
|
expect(atom.project.relativizePath(randomPath)).toEqual [null, randomPath]
|
2015-02-26 03:49:30 +03:00
|
|
|
|
2015-03-14 01:07:44 +03:00
|
|
|
describe "when the given path is a URL", ->
|
|
|
|
it "returns null for the root path, and the given path unchanged", ->
|
|
|
|
url = "http://the-path"
|
|
|
|
expect(atom.project.relativizePath(url)).toEqual [null, url]
|
|
|
|
|
2015-08-26 23:51:07 +03:00
|
|
|
describe "when the given path is inside more than one root folder", ->
|
|
|
|
it "uses the root folder that is closest to the given path", ->
|
|
|
|
atom.project.addPath(path.join(atom.project.getPaths()[0], 'a-dir'))
|
|
|
|
|
|
|
|
inputPath = path.join(atom.project.getPaths()[1], 'somewhere/something.txt')
|
|
|
|
|
|
|
|
expect(atom.project.getDirectories()[0].contains(inputPath)).toBe true
|
|
|
|
expect(atom.project.getDirectories()[1].contains(inputPath)).toBe true
|
|
|
|
expect(atom.project.relativizePath(inputPath)).toEqual [
|
|
|
|
atom.project.getPaths()[1],
|
2016-04-15 21:25:05 +03:00
|
|
|
path.join('somewhere', 'something.txt')
|
2015-08-26 23:51:07 +03:00
|
|
|
]
|
|
|
|
|
2015-02-13 08:16:15 +03:00
|
|
|
describe ".contains(path)", ->
|
|
|
|
it "returns whether or not the given path is in one of the root directories", ->
|
|
|
|
rootPath = atom.project.getPaths()[0]
|
|
|
|
childPath = path.join(rootPath, "some", "child", "directory")
|
|
|
|
expect(atom.project.contains(childPath)).toBe true
|
|
|
|
|
|
|
|
randomPath = path.join("some", "random", "path")
|
|
|
|
expect(atom.project.contains(randomPath)).toBe false
|