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'
|
2015-02-13 08:16:15 +03:00
|
|
|
temp = require "temp"
|
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-02-13 04:11:06 +03:00
|
|
|
describe "constructor", ->
|
|
|
|
it "tries to update repositories when a new RepositoryProvider is registered", ->
|
2015-02-17 21:09:57 +03:00
|
|
|
tmp = temp.mkdirSync('atom-project')
|
|
|
|
atom.project.setPaths([tmp])
|
2015-02-13 04:11:06 +03:00
|
|
|
expect(atom.project.getRepositories()).toEqual [null]
|
|
|
|
expect(atom.project.repositoryProviders.length).toEqual 1
|
|
|
|
|
|
|
|
# Register a new RepositoryProvider.
|
2015-02-17 21:09:57 +03:00
|
|
|
dummyRepository = destroy: ->
|
2015-02-13 04:11:06 +03:00
|
|
|
repositoryProvider =
|
|
|
|
repositoryForDirectory: (directory) -> Promise.resolve(dummyRepository)
|
|
|
|
repositoryForDirectorySync: (directory) -> dummyRepository
|
|
|
|
atom.packages.serviceHub.provide(
|
|
|
|
"atom.repository-provider", "0.1.0", repositoryProvider)
|
|
|
|
|
|
|
|
expect(atom.project.repositoryProviders.length).toBe 2
|
|
|
|
expect(atom.project.getRepositories()).toEqual [dummyRepository]
|
|
|
|
|
|
|
|
it "does not update @repositories if every path has a Repository", ->
|
|
|
|
repositories = atom.project.getRepositories()
|
|
|
|
expect(repositories.length).toEqual 1
|
|
|
|
[repository] = repositories
|
|
|
|
expect(repository).toBeTruthy()
|
|
|
|
|
|
|
|
# Register a new RepositoryProvider.
|
2015-02-17 21:09:57 +03:00
|
|
|
dummyRepository = destroy: ->
|
2015-02-13 04:11:06 +03:00
|
|
|
repositoryProvider =
|
|
|
|
repositoryForDirectory: (directory) -> Promise.resolve(dummyRepository)
|
|
|
|
repositoryForDirectorySync: (directory) -> dummyRepository
|
|
|
|
atom.packages.serviceHub.provide(
|
|
|
|
"atom.repository-provider", "0.1.0", repositoryProvider)
|
|
|
|
|
|
|
|
expect(atom.project.getRepositories()).toBe repositories
|
|
|
|
|
2013-08-29 05:37:40 +04:00
|
|
|
describe "serialization", ->
|
2013-08-30 05:24:51 +04:00
|
|
|
deserializedProject = null
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
deserializedProject?.destroy()
|
|
|
|
|
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
|
|
|
|
deserializedProject = atom.project.testSerialization()
|
|
|
|
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 ->
|
|
|
|
atom.project.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
|
|
|
|
deserializedProject = atom.project.testSerialization()
|
|
|
|
|
|
|
|
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 ->
|
|
|
|
atom.project.open(pathToOpen)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(atom.project.getBuffers().length).toBe 1
|
|
|
|
fs.mkdirSync(pathToOpen)
|
|
|
|
deserializedProject = atom.project.testSerialization()
|
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 ->
|
|
|
|
atom.project.open(pathToOpen)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(atom.project.getBuffers().length).toBe 1
|
|
|
|
fs.chmodSync(pathToOpen, '000')
|
|
|
|
deserializedProject = atom.project.testSerialization()
|
2015-01-15 22:51:11 +03:00
|
|
|
expect(deserializedProject.getBuffers().length).toBe 0
|
|
|
|
|
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 ->
|
|
|
|
atom.project.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
|
|
|
|
2015-01-09 04:10:59 +03:00
|
|
|
describe "when a watch error is thrown from the TextBuffer", ->
|
|
|
|
editor = null
|
|
|
|
beforeEach ->
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open(require.resolve('./fixtures/dir/a')).then (o) -> editor = o
|
|
|
|
|
|
|
|
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
|
|
|
|
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')
|
|
|
|
atom.project.on 'buffer-created', 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 ->
|
|
|
|
atom.project.open(absolutePath).then (o) -> editor = o
|
|
|
|
|
|
|
|
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 ->
|
|
|
|
atom.project.open(absolutePath).then (o) -> editor = o
|
|
|
|
|
|
|
|
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 ->
|
|
|
|
atom.project.open(absolutePath).then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
2013-05-15 06:23:25 +04:00
|
|
|
newBufferHandler.reset()
|
2014-04-24 03:50:25 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open(absolutePath).then ({buffer}) ->
|
|
|
|
expect(buffer).toBe editor.buffer
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open('a').then ({buffer}) ->
|
|
|
|
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 ->
|
|
|
|
atom.project.open().then (o) -> editor = o
|
|
|
|
|
|
|
|
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-08 00:47:20 +04:00
|
|
|
it "returns number of read bytes as progress indicator", ->
|
2015-01-10 01:54:54 +03:00
|
|
|
filePath = atom.project.getDirectories()[0]?.resolve 'a'
|
2013-10-08 00:47:20 +04:00
|
|
|
totalBytes = 0
|
2013-11-21 03:35:49 +04:00
|
|
|
promise = atom.project.open(filePath)
|
2013-10-08 00:47:20 +04:00
|
|
|
promise.progress (bytesRead) -> totalBytes = bytesRead
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
promise
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(totalBytes).toBe fs.statSync(filePath).size
|
|
|
|
|
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
|
|
|
|
2014-11-27 19:11:21 +03:00
|
|
|
describe ".setPaths(path)", ->
|
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", ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([require.resolve('./fixtures/dir/a')])
|
|
|
|
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'))
|
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)
|
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
describe "when path is null", ->
|
|
|
|
it "sets its path and root directory to null", ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([])
|
|
|
|
expect(atom.project.getPaths()[0]?).toBeFalsy()
|
2014-11-26 01:54:06 +03:00
|
|
|
expect(atom.project.getDirectories()[0]?).toBeFalsy()
|
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-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-02-13 08:18:18 +03:00
|
|
|
describe "when the project already has the path or one of its descendants", ->
|
|
|
|
it "doesn't add it again", ->
|
|
|
|
onDidChangePathsSpy = jasmine.createSpy('onDidChangePaths spy')
|
|
|
|
atom.project.onDidChangePaths(onDidChangePathsSpy)
|
|
|
|
|
|
|
|
[oldPath] = atom.project.getPaths()
|
|
|
|
|
|
|
|
atom.project.addPath(oldPath)
|
|
|
|
atom.project.addPath(path.join(oldPath, "some-file.txt"))
|
|
|
|
atom.project.addPath(path.join(oldPath, "a-dir"))
|
|
|
|
atom.project.addPath(path.join(oldPath, "a-dir", "oh-git"))
|
|
|
|
|
|
|
|
expect(atom.project.getPaths()).toEqual([oldPath])
|
|
|
|
expect(onDidChangePathsSpy).not.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-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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-11-27 02:24:48 +04:00
|
|
|
describe ".eachBuffer(callback)", ->
|
|
|
|
beforeEach ->
|
|
|
|
atom.project.bufferForPathSync('a')
|
|
|
|
|
|
|
|
it "invokes the callback for existing buffer", ->
|
|
|
|
count = 0
|
|
|
|
count = 0
|
|
|
|
callbackBuffer = null
|
|
|
|
callback = (buffer) ->
|
|
|
|
callbackBuffer = buffer
|
|
|
|
count++
|
|
|
|
atom.project.eachBuffer(callback)
|
|
|
|
expect(count).toBe 1
|
|
|
|
expect(callbackBuffer).toBe atom.project.getBuffers()[0]
|
|
|
|
|
|
|
|
it "invokes the callback for new buffers", ->
|
|
|
|
count = 0
|
|
|
|
callbackBuffer = null
|
|
|
|
callback = (buffer) ->
|
|
|
|
callbackBuffer = buffer
|
|
|
|
count++
|
|
|
|
|
|
|
|
atom.project.eachBuffer(callback)
|
|
|
|
count = 0
|
|
|
|
callbackBuffer = null
|
|
|
|
atom.project.bufferForPathSync(require.resolve('./fixtures/sample.txt'))
|
|
|
|
expect(count).toBe 1
|
|
|
|
expect(callbackBuffer).toBe atom.project.getBuffers()[1]
|