mirror of
https://github.com/atom/atom.git
synced 2026-02-19 02:44:29 -05:00
Use fs.resolveOnLoadPath() instead of require.resolve()
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
RootView = require 'root-view'
|
||||
{$$} = require 'space-pen'
|
||||
fs = require 'fs-utils'
|
||||
|
||||
describe "the `atom` global", ->
|
||||
beforeEach ->
|
||||
@@ -10,7 +11,7 @@ describe "the `atom` global", ->
|
||||
|
||||
beforeEach ->
|
||||
extension = require "package-with-module"
|
||||
stylesheetPath = require.resolve("fixtures/packages/package-with-module/stylesheets/styles.css")
|
||||
stylesheetPath = fs.resolveOnLoadPath("fixtures/packages/package-with-module/stylesheets/styles.css")
|
||||
|
||||
afterEach ->
|
||||
removeStylesheet(stylesheetPath)
|
||||
@@ -57,7 +58,7 @@ describe "the `atom` global", ->
|
||||
expect(keymap.bindingsForElement(element3)['ctrl-y']).toBeUndefined()
|
||||
|
||||
it "loads stylesheets associated with the package", ->
|
||||
stylesheetPath = require.resolve("fixtures/packages/package-with-module/stylesheets/styles.css")
|
||||
stylesheetPath = fs.resolveOnLoadPath("fixtures/packages/package-with-module/stylesheets/styles.css")
|
||||
expect(stylesheetElementForId(stylesheetPath).length).toBe 0
|
||||
window.loadPackage("package-with-module")
|
||||
expect(stylesheetElementForId(stylesheetPath).length).toBe 1
|
||||
|
||||
@@ -5,7 +5,7 @@ describe "Directory", ->
|
||||
directory = null
|
||||
|
||||
beforeEach ->
|
||||
directory = new Directory(require.resolve('fixtures'))
|
||||
directory = new Directory(fs.resolveOnLoadPath('fixtures'))
|
||||
|
||||
afterEach ->
|
||||
directory.off()
|
||||
@@ -14,7 +14,7 @@ describe "Directory", ->
|
||||
temporaryFilePath = null
|
||||
|
||||
beforeEach ->
|
||||
temporaryFilePath = fs.join(require.resolve('fixtures'), 'temporary')
|
||||
temporaryFilePath = fs.join(fs.resolveOnLoadPath('fixtures'), 'temporary')
|
||||
fs.remove(temporaryFilePath) if fs.exists(temporaryFilePath)
|
||||
|
||||
afterEach ->
|
||||
@@ -64,4 +64,3 @@ describe "Directory", ->
|
||||
runs -> fs.remove(temporaryFilePath)
|
||||
waits 20
|
||||
runs -> expect(changeHandler.callCount).toBe 0
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ describe 'File', ->
|
||||
[path, file] = []
|
||||
|
||||
beforeEach ->
|
||||
path = fs.join(require.resolve('fixtures'), "atom-file-test.txt") # Don't put in /tmp because /tmp symlinks to /private/tmp and screws up the rename test
|
||||
path = fs.join(fs.resolveOnLoadPath('fixtures'), "atom-file-test.txt") # Don't put in /tmp because /tmp symlinks to /private/tmp and screws up the rename test
|
||||
fs.remove(path) if fs.exists(path)
|
||||
fs.write(path, "this is old!")
|
||||
file = new File(path)
|
||||
|
||||
@@ -21,39 +21,39 @@ describe "Git", ->
|
||||
|
||||
describe ".getPath()", ->
|
||||
it "returns the repository path for a .git directory path", ->
|
||||
repo = new Git(require.resolve('fixtures/git/master.git/HEAD'))
|
||||
expect(repo.getPath()).toBe require.resolve('fixtures/git/master.git')
|
||||
repo = new Git(fs.resolveOnLoadPath('fixtures/git/master.git/HEAD'))
|
||||
expect(repo.getPath()).toBe fs.resolveOnLoadPath('fixtures/git/master.git')
|
||||
|
||||
it "returns the repository path for a repository path", ->
|
||||
repo = new Git(require.resolve('fixtures/git/master.git'))
|
||||
expect(repo.getPath()).toBe require.resolve('fixtures/git/master.git')
|
||||
repo = new Git(fs.resolveOnLoadPath('fixtures/git/master.git'))
|
||||
expect(repo.getPath()).toBe fs.resolveOnLoadPath('fixtures/git/master.git')
|
||||
|
||||
describe ".getHead()", ->
|
||||
it "returns a branch name for a non-empty repository", ->
|
||||
repo = new Git(require.resolve('fixtures/git/master.git'))
|
||||
repo = new Git(fs.resolveOnLoadPath('fixtures/git/master.git'))
|
||||
expect(repo.getHead()).toBe 'refs/heads/master'
|
||||
|
||||
describe ".getShortHead()", ->
|
||||
it "returns a branch name for a non-empty repository", ->
|
||||
repo = new Git(require.resolve('fixtures/git/master.git'))
|
||||
repo = new Git(fs.resolveOnLoadPath('fixtures/git/master.git'))
|
||||
expect(repo.getShortHead()).toBe 'master'
|
||||
|
||||
describe ".isPathIgnored(path)", ->
|
||||
it "returns true for an ignored path", ->
|
||||
repo = new Git(require.resolve('fixtures/git/ignore.git'))
|
||||
repo = new Git(fs.resolveOnLoadPath('fixtures/git/ignore.git'))
|
||||
expect(repo.isPathIgnored('a.txt')).toBeTruthy()
|
||||
|
||||
it "returns false for a non-ignored path", ->
|
||||
repo = new Git(require.resolve('fixtures/git/ignore.git'))
|
||||
repo = new Git(fs.resolveOnLoadPath('fixtures/git/ignore.git'))
|
||||
expect(repo.isPathIgnored('b.txt')).toBeFalsy()
|
||||
|
||||
describe ".isPathModified(path)", ->
|
||||
[repo, path, newPath, originalPathText] = []
|
||||
|
||||
beforeEach ->
|
||||
repo = new Git(require.resolve('fixtures/git/working-dir'))
|
||||
path = require.resolve('fixtures/git/working-dir/file.txt')
|
||||
newPath = fs.join(require.resolve('fixtures/git/working-dir'), 'new-path.txt')
|
||||
repo = new Git(fs.resolveOnLoadPath('fixtures/git/working-dir'))
|
||||
path = fs.resolveOnLoadPath('fixtures/git/working-dir/file.txt')
|
||||
newPath = fs.join(fs.resolveOnLoadPath('fixtures/git/working-dir'), 'new-path.txt')
|
||||
originalPathText = fs.read(path)
|
||||
|
||||
afterEach ->
|
||||
@@ -79,9 +79,9 @@ describe "Git", ->
|
||||
[path, newPath] = []
|
||||
|
||||
beforeEach ->
|
||||
repo = new Git(require.resolve('fixtures/git/working-dir'))
|
||||
path = require.resolve('fixtures/git/working-dir/file.txt')
|
||||
newPath = fs.join(require.resolve('fixtures/git/working-dir'), 'new-path.txt')
|
||||
repo = new Git(fs.resolveOnLoadPath('fixtures/git/working-dir'))
|
||||
path = fs.resolveOnLoadPath('fixtures/git/working-dir/file.txt')
|
||||
newPath = fs.join(fs.resolveOnLoadPath('fixtures/git/working-dir'), 'new-path.txt')
|
||||
fs.write(newPath, "i'm new here")
|
||||
|
||||
afterEach ->
|
||||
@@ -98,10 +98,10 @@ describe "Git", ->
|
||||
[path1, path2, originalPath1Text, originalPath2Text] = []
|
||||
|
||||
beforeEach ->
|
||||
repo = new Git(require.resolve('fixtures/git/working-dir'))
|
||||
path1 = require.resolve('fixtures/git/working-dir/file.txt')
|
||||
repo = new Git(fs.resolveOnLoadPath('fixtures/git/working-dir'))
|
||||
path1 = fs.resolveOnLoadPath('fixtures/git/working-dir/file.txt')
|
||||
originalPath1Text = fs.read(path1)
|
||||
path2 = require.resolve('fixtures/git/working-dir/other.txt')
|
||||
path2 = fs.resolveOnLoadPath('fixtures/git/working-dir/other.txt')
|
||||
originalPath2Text = fs.read(path2)
|
||||
|
||||
afterEach ->
|
||||
@@ -141,7 +141,7 @@ describe "Git", ->
|
||||
|
||||
describe ".destroy()", ->
|
||||
it "throws an exception when any method is called after it is called", ->
|
||||
repo = new Git(require.resolve('fixtures/git/master.git/HEAD'))
|
||||
repo = new Git(fs.resolveOnLoadPath('fixtures/git/master.git/HEAD'))
|
||||
repo.destroy()
|
||||
expect(-> repo.getHead()).toThrow()
|
||||
|
||||
@@ -149,8 +149,8 @@ describe "Git", ->
|
||||
[path, originalPathText] = []
|
||||
|
||||
beforeEach ->
|
||||
repo = new Git(require.resolve('fixtures/git/working-dir'))
|
||||
path = require.resolve('fixtures/git/working-dir/file.txt')
|
||||
repo = new Git(fs.resolveOnLoadPath('fixtures/git/working-dir'))
|
||||
path = fs.resolveOnLoadPath('fixtures/git/working-dir/file.txt')
|
||||
originalPathText = fs.read(path)
|
||||
|
||||
afterEach ->
|
||||
@@ -165,8 +165,8 @@ describe "Git", ->
|
||||
[path, originalPathText] = []
|
||||
|
||||
beforeEach ->
|
||||
repo = new Git(require.resolve('fixtures/git/working-dir'))
|
||||
path = require.resolve('fixtures/git/working-dir/file.txt')
|
||||
repo = new Git(fs.resolveOnLoadPath('fixtures/git/working-dir'))
|
||||
path = fs.resolveOnLoadPath('fixtures/git/working-dir/file.txt')
|
||||
originalPathText = fs.read(path)
|
||||
|
||||
afterEach ->
|
||||
@@ -188,7 +188,7 @@ describe "Git", ->
|
||||
[newPath, modifiedPath, cleanPath, originalModifiedPathText] = []
|
||||
|
||||
beforeEach ->
|
||||
repo = new Git(require.resolve('fixtures/git/working-dir'))
|
||||
repo = new Git(fs.resolveOnLoadPath('fixtures/git/working-dir'))
|
||||
modifiedPath = project.resolve('git/working-dir/file.txt')
|
||||
originalModifiedPathText = fs.read(modifiedPath)
|
||||
newPath = project.resolve('git/working-dir/untracked.txt')
|
||||
|
||||
@@ -34,7 +34,7 @@ describe "Project", ->
|
||||
describe ".buildEditSession(path)", ->
|
||||
[absolutePath, newBufferHandler, newEditSessionHandler] = []
|
||||
beforeEach ->
|
||||
absolutePath = require.resolve('fixtures/dir/a')
|
||||
absolutePath = fs.resolveOnLoadPath('fixtures/dir/a')
|
||||
newBufferHandler = jasmine.createSpy('newBufferHandler')
|
||||
project.on 'buffer-created', newBufferHandler
|
||||
newEditSessionHandler = jasmine.createSpy('newEditSessionHandler')
|
||||
@@ -86,14 +86,14 @@ describe "Project", ->
|
||||
|
||||
describe ".resolve(path)", ->
|
||||
it "returns an absolute path based on the project's root", ->
|
||||
absolutePath = require.resolve('fixtures/dir/a')
|
||||
absolutePath = fs.resolveOnLoadPath('fixtures/dir/a')
|
||||
expect(project.resolve('a')).toBe absolutePath
|
||||
expect(project.resolve(absolutePath + '/../a')).toBe absolutePath
|
||||
expect(project.resolve('a/../a')).toBe absolutePath
|
||||
|
||||
describe ".relativize(path)", ->
|
||||
it "returns an relative path based on the project's root", ->
|
||||
absolutePath = require.resolve('fixtures/dir')
|
||||
absolutePath = fs.resolveOnLoadPath('fixtures/dir')
|
||||
expect(project.relativize(fs.join(absolutePath, "b"))).toBe "b"
|
||||
expect(project.relativize(fs.join(absolutePath, "b/file.coffee"))).toBe "b/file.coffee"
|
||||
expect(project.relativize(fs.join(absolutePath, "file.coffee"))).toBe "file.coffee"
|
||||
@@ -101,15 +101,15 @@ describe "Project", ->
|
||||
describe ".setPath(path)", ->
|
||||
describe "when path is a file", ->
|
||||
it "sets its path to the files parent directory and updates the root directory", ->
|
||||
project.setPath(require.resolve('fixtures/dir/a'))
|
||||
expect(project.getPath()).toEqual require.resolve('fixtures/dir')
|
||||
expect(project.getRootDirectory().path).toEqual require.resolve('fixtures/dir')
|
||||
project.setPath(fs.resolveOnLoadPath('fixtures/dir/a'))
|
||||
expect(project.getPath()).toEqual fs.resolveOnLoadPath('fixtures/dir')
|
||||
expect(project.getRootDirectory().path).toEqual fs.resolveOnLoadPath('fixtures/dir')
|
||||
|
||||
describe "when path is a directory", ->
|
||||
it "sets its path to the directory and updates the root directory", ->
|
||||
project.setPath(require.resolve('fixtures/dir/a-dir'))
|
||||
expect(project.getPath()).toEqual require.resolve('fixtures/dir/a-dir')
|
||||
expect(project.getRootDirectory().path).toEqual require.resolve('fixtures/dir/a-dir')
|
||||
project.setPath(fs.resolveOnLoadPath('fixtures/dir/a-dir'))
|
||||
expect(project.getPath()).toEqual fs.resolveOnLoadPath('fixtures/dir/a-dir')
|
||||
expect(project.getRootDirectory().path).toEqual fs.resolveOnLoadPath('fixtures/dir/a-dir')
|
||||
|
||||
describe "when path is null", ->
|
||||
it "sets its path and root directory to null", ->
|
||||
@@ -140,19 +140,19 @@ describe "Project", ->
|
||||
describe "when config.core.hideGitIgnoredFiles is true", ->
|
||||
it "ignores files that are present in .gitignore if the project is a git repo", ->
|
||||
config.set "core.hideGitIgnoredFiles", true
|
||||
project.setPath(require.resolve('fixtures/git/working-dir'))
|
||||
project.setPath(fs.resolveOnLoadPath('fixtures/git/working-dir'))
|
||||
paths = null
|
||||
waitsForPromise ->
|
||||
project.getFilePaths().done (foundPaths) -> paths = foundPaths
|
||||
|
||||
runs ->
|
||||
runs ->
|
||||
expect(paths).not.toContain('ignored.txt')
|
||||
|
||||
describe "ignored file name", ->
|
||||
ignoredFile = null
|
||||
|
||||
beforeEach ->
|
||||
ignoredFile = fs.join(require.resolve('fixtures/dir'), 'ignored.txt')
|
||||
ignoredFile = fs.join(fs.resolveOnLoadPath('fixtures/dir'), 'ignored.txt')
|
||||
fs.write(ignoredFile, "")
|
||||
|
||||
afterEach ->
|
||||
@@ -172,7 +172,7 @@ describe "Project", ->
|
||||
ignoredFile = null
|
||||
|
||||
beforeEach ->
|
||||
ignoredFile = fs.join(require.resolve('fixtures/dir'), 'ignored/ignored.txt')
|
||||
ignoredFile = fs.join(fs.resolveOnLoadPath('fixtures/dir'), 'ignored/ignored.txt')
|
||||
fs.write(ignoredFile, "")
|
||||
|
||||
afterEach ->
|
||||
@@ -222,7 +222,7 @@ describe "Project", ->
|
||||
range: [[2, 6], [2, 11]]
|
||||
|
||||
it "works on evil filenames", ->
|
||||
project.setPath(require.resolve('fixtures/evil-files'))
|
||||
project.setPath(fs.resolveOnLoadPath('fixtures/evil-files'))
|
||||
paths = []
|
||||
matches = []
|
||||
waitsForPromise ->
|
||||
@@ -246,7 +246,7 @@ describe "Project", ->
|
||||
project.scan /a+/, iterator
|
||||
|
||||
stdout = BufferedProcess.prototype.bufferStream.argsForCall[0][1]
|
||||
stdout ":#{require.resolve('fixtures/dir/a')}\n"
|
||||
stdout ":#{fs.resolveOnLoadPath('fixtures/dir/a')}\n"
|
||||
stdout "1;0 3:aaa bbb\n2;3 2:cc aa cc\n"
|
||||
|
||||
expect(iterator.argsForCall[0][0]).toEqual
|
||||
|
||||
@@ -223,7 +223,7 @@ describe "RootView", ->
|
||||
it "creates an edit session for the given path as an item on a new pane, and focuses the pane", ->
|
||||
editSession = rootView.open('b')
|
||||
expect(rootView.getActivePane().activeItem).toBe editSession
|
||||
expect(editSession.getPath()).toBe require.resolve('fixtures/dir/b')
|
||||
expect(editSession.getPath()).toBe fs.resolveOnLoadPath('fixtures/dir/b')
|
||||
expect(rootView.getActivePane().focus).toHaveBeenCalled()
|
||||
|
||||
describe "when the changeFocus option is false", ->
|
||||
|
||||
@@ -46,7 +46,7 @@ describe 'Buffer', ->
|
||||
[path, newPath, bufferToChange, eventHandler] = []
|
||||
|
||||
beforeEach ->
|
||||
path = fs.join(require.resolve("fixtures/"), "atom-manipulate-me")
|
||||
path = fs.join(fs.resolveOnLoadPath("fixtures"), "atom-manipulate-me")
|
||||
newPath = "#{path}-i-moved"
|
||||
fs.write(path, "")
|
||||
bufferToChange = new Buffer(path)
|
||||
|
||||
@@ -7,7 +7,7 @@ describe "TextMateTheme", ->
|
||||
[theme, themePath] = []
|
||||
|
||||
beforeEach ->
|
||||
themePath = require.resolve(fs.join('fixtures', 'test.tmTheme'))
|
||||
themePath = fs.resolveOnLoadPath(fs.join('fixtures', 'test.tmTheme'))
|
||||
theme = Theme.load(themePath)
|
||||
|
||||
afterEach ->
|
||||
|
||||
@@ -15,7 +15,7 @@ describe "@load(name)", ->
|
||||
it "applies the theme's stylesheet to the current window", ->
|
||||
expect($(".editor").css("background-color")).not.toBe("rgb(20, 20, 20)")
|
||||
|
||||
themePath = require.resolve(fs.join('fixtures', 'test.tmTheme'))
|
||||
themePath = fs.resolveOnLoadPath(fs.join('fixtures', 'test.tmTheme'))
|
||||
theme = Theme.load(themePath)
|
||||
expect($(".editor").css("background-color")).toBe("rgb(20, 20, 20)")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user