🎨 project-spec.js

This commit is contained in:
Max Brunsfeld
2017-11-02 12:13:31 -07:00
parent b7ae57bdbe
commit 1a7ea3322e

View File

@@ -209,7 +209,7 @@ describe('Project', () => {
})
})
describe('when an editor is saved and the project has no path', () =>
describe('when an editor is saved and the project has no path', () => {
it("sets the project's path to the saved file's parent directory", () => {
const tempFile = temp.openSync().path
atom.project.setPaths([])
@@ -222,7 +222,7 @@ describe('Project', () => {
runs(() => expect(atom.project.getPaths()[0]).toBe(path.dirname(tempFile)))
})
)
})
describe('before and after saving a buffer', () => {
let buffer
@@ -394,7 +394,7 @@ describe('Project', () => {
atom.project.onDidAddBuffer(newBufferHandler)
})
describe("when given an absolute path that isn't currently open", () =>
describe("when given an absolute path that isn't currently open", () => {
it("returns a new edit session for the given path and emits 'buffer-created'", () => {
let editor = null
waitsForPromise(() => atom.workspace.open(absolutePath).then(o => { editor = o }))
@@ -404,9 +404,9 @@ describe('Project', () => {
expect(newBufferHandler).toHaveBeenCalledWith(editor.buffer)
})
})
)
})
describe("when given a relative path that isn't currently opened", () =>
describe("when given a relative path that isn't currently opened", () => {
it("returns a new edit session for the given path (relative to the project root) and emits 'buffer-created'", () => {
let editor = null
waitsForPromise(() => atom.workspace.open(absolutePath).then(o => { editor = o }))
@@ -416,9 +416,9 @@ describe('Project', () => {
expect(newBufferHandler).toHaveBeenCalledWith(editor.buffer)
})
})
)
})
describe('when passed the path to a buffer that is currently opened', () =>
describe('when passed the path to a buffer that is currently opened', () => {
it('returns a new edit session containing currently opened buffer', () => {
let editor = null
@@ -437,9 +437,9 @@ describe('Project', () => {
})
)
})
)
})
describe('when not passed a path', () =>
describe('when not passed a path', () => {
it("returns a new edit session and emits 'buffer-created'", () => {
let editor = null
waitsForPromise(() => atom.workspace.open().then(o => { editor = o }))
@@ -449,7 +449,7 @@ describe('Project', () => {
expect(newBufferHandler).toHaveBeenCalledWith(editor.buffer)
})
})
)
})
})
describe('.bufferForPath(path)', () => {
@@ -509,7 +509,7 @@ describe('Project', () => {
})
describe('.repositoryForDirectory(directory)', () => {
it('resolves to null when the directory does not have a repository', () =>
it('resolves to null when the directory does not have a repository', () => {
waitsForPromise(() => {
const directory = new Directory('/tmp')
return atom.project.repositoryForDirectory(directory).then((result) => {
@@ -518,9 +518,9 @@ describe('Project', () => {
expect(atom.project.repositoryPromisesByPath.size).toBe(0)
})
})
)
})
it('resolves to a GitRepository and is cached when the given directory is a Git repo', () =>
it('resolves to a GitRepository and is cached when the given directory is a Git repo', () => {
waitsForPromise(() => {
const directory = new Directory(path.join(__dirname, '..'))
const promise = atom.project.repositoryForDirectory(directory)
@@ -533,7 +533,7 @@ describe('Project', () => {
expect(atom.project.repositoryForDirectory(directory)).toBe(promise)
})
})
)
})
it('creates a new repository if a previous one with the same directory had been destroyed', () => {
let repository = null
@@ -554,14 +554,14 @@ describe('Project', () => {
})
describe('.setPaths(paths, options)', () => {
describe('when path is a file', () =>
describe('when path is a file', () => {
it("sets its path to the file's parent directory and updates the root directory", () => {
const 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))
})
)
})
describe('when path is a directory', () => {
it('assigns the directories and repositories', () => {
@@ -608,13 +608,13 @@ describe('Project', () => {
})
})
describe('when no paths are given', () =>
describe('when no paths are given', () => {
it('clears its path', () => {
atom.project.setPaths([])
expect(atom.project.getPaths()).toEqual([])
expect(atom.project.getDirectories()).toEqual([])
})
)
})
it('normalizes the path to remove consecutive slashes, ., and .. segments', () => {
atom.project.setPaths([`${require.resolve('./fixtures/dir/a')}${path.sep}b${path.sep}${path.sep}..`])
@@ -665,9 +665,9 @@ describe('Project', () => {
expect(atom.project.getPaths()).toEqual(previousPaths)
})
it('optionally throws on non-existent directories', () =>
it('optionally throws on non-existent directories', () => {
expect(() => atom.project.addPath('/this-definitely/does-not-exist', {mustExist: true})).toThrow()
)
})
})
describe('.removePath(path)', () => {
@@ -785,7 +785,7 @@ describe('Project', () => {
})
})
describe('.onDidAddBuffer()', () =>
describe('.onDidAddBuffer()', () => {
it('invokes the callback with added text buffers', () => {
const buffers = []
const added = []
@@ -810,9 +810,9 @@ describe('Project', () => {
expect(added).toEqual([buffers[1]])
})
})
)
})
describe('.observeBuffers()', () =>
describe('.observeBuffers()', () => {
it('invokes the observer with current and future text buffers', () => {
const buffers = []
const observed = []
@@ -844,7 +844,7 @@ describe('Project', () => {
expect(observed).toEqual(buffers)
})
})
)
})
describe('.relativize(path)', () => {
it('returns the path, relative to whichever root directory it is inside of', () => {
@@ -878,21 +878,21 @@ describe('Project', () => {
expect(atom.project.relativizePath(childPath)).toEqual([rootPath, path.join('some', 'child', 'directory')])
})
describe("when the given path isn't inside of any of the project's path", () =>
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', () => {
const randomPath = path.join('some', 'random', 'path')
expect(atom.project.relativizePath(randomPath)).toEqual([null, randomPath])
})
)
})
describe('when the given path is a URL', () =>
describe('when the given path is a URL', () => {
it('returns null for the root path, and the given path unchanged', () => {
const url = 'http://the-path'
expect(atom.project.relativizePath(url)).toEqual([null, url])
})
)
})
describe('when the given path is inside more than one root folder', () =>
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'))
@@ -905,10 +905,10 @@ describe('Project', () => {
path.join('somewhere', 'something.txt')
])
})
)
})
})
describe('.contains(path)', () =>
describe('.contains(path)', () => {
it('returns whether or not the given path is in one of the root directories', () => {
const rootPath = atom.project.getPaths()[0]
const childPath = path.join(rootPath, 'some', 'child', 'directory')
@@ -917,11 +917,11 @@ describe('Project', () => {
const randomPath = path.join('some', 'random', 'path')
expect(atom.project.contains(randomPath)).toBe(false)
})
)
})
describe('.resolvePath(uri)', () =>
describe('.resolvePath(uri)', () => {
it('normalizes disk drive letter in passed path on #win32', () => {
expect(atom.project.resolvePath('d:\\file.txt')).toEqual('D:\\file.txt')
})
)
})
})