2013-02-20 23:44:39 +04:00
|
|
|
require 'window'
|
|
|
|
window.setUpEnvironment()
|
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
nakedLoad 'jasmine-jquery'
|
|
|
|
$ = require 'jquery'
|
2013-03-12 21:38:05 +04:00
|
|
|
_ = require 'underscore'
|
2012-08-28 02:36:36 +04:00
|
|
|
Keymap = require 'keymap'
|
2012-12-13 03:58:50 +04:00
|
|
|
Config = require 'config'
|
2012-08-28 02:36:36 +04:00
|
|
|
Point = require 'point'
|
|
|
|
Project = require 'project'
|
|
|
|
Directory = require 'directory'
|
|
|
|
File = require 'file'
|
2012-11-15 00:13:57 +04:00
|
|
|
Editor = require 'editor'
|
2012-11-21 19:22:13 +04:00
|
|
|
TokenizedBuffer = require 'tokenized-buffer'
|
2013-03-12 21:38:05 +04:00
|
|
|
fs = require 'fs-utils'
|
2013-02-19 05:08:18 +04:00
|
|
|
RootView = require 'root-view'
|
2013-02-28 05:50:37 +04:00
|
|
|
Git = require 'git'
|
2013-03-26 08:15:32 +04:00
|
|
|
requireStylesheet "jasmine"
|
2013-03-12 21:38:05 +04:00
|
|
|
fixturePackagesPath = fs.resolveOnLoadPath('fixtures/packages')
|
2013-02-20 00:12:29 +04:00
|
|
|
keymap.loadBundledKeymaps()
|
2013-01-04 02:10:11 +04:00
|
|
|
[bindingSetsToRestore, bindingSetsByFirstKeystrokeToRestore] = []
|
2012-12-19 06:47:20 +04:00
|
|
|
|
2013-02-20 23:44:50 +04:00
|
|
|
$(window).on 'core:close', -> window.close()
|
|
|
|
$(window).on 'toggle-dev-tools', (e) -> atom.toggleDevTools()
|
|
|
|
$('html,body').css('overflow', 'auto')
|
|
|
|
|
|
|
|
jasmine.getEnv().addEqualityTester(_.isEqual) # Use underscore's definition of equality for toEqual assertions
|
2013-02-21 04:28:05 +04:00
|
|
|
jasmine.getEnv().defaultTimeoutInterval = 5000
|
2013-02-20 23:44:50 +04:00
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
beforeEach ->
|
2013-02-14 05:12:22 +04:00
|
|
|
jQuery.fx.off = true
|
2013-03-13 00:32:42 +04:00
|
|
|
window.project = new Project(fs.resolveOnLoadPath('fixtures'))
|
2013-03-06 00:04:14 +04:00
|
|
|
window.git = Git.open(project.getPath())
|
2013-02-28 05:50:37 +04:00
|
|
|
window.project.on 'path-changed', ->
|
|
|
|
window.git?.destroy()
|
|
|
|
window.git = Git.open(window.project.getPath())
|
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
window.resetTimeouts()
|
2013-03-25 20:57:58 +04:00
|
|
|
atom.packageStates = {}
|
2013-03-22 04:23:37 +04:00
|
|
|
spyOn(atom, 'saveWindowState')
|
2013-03-22 04:51:32 +04:00
|
|
|
spyOn(atom, 'getSavedWindowState').andReturn(null)
|
2013-03-22 04:23:37 +04:00
|
|
|
$native.setWindowState('')
|
2013-03-22 02:54:49 +04:00
|
|
|
syntax.clearGrammarOverrides()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2013-01-04 02:10:11 +04:00
|
|
|
# used to reset keymap after each spec
|
|
|
|
bindingSetsToRestore = _.clone(keymap.bindingSets)
|
|
|
|
bindingSetsByFirstKeystrokeToRestore = _.clone(keymap.bindingSetsByFirstKeystroke)
|
|
|
|
|
|
|
|
# reset config before each spec; don't load or save from/to `config.json`
|
2012-12-13 03:58:50 +04:00
|
|
|
window.config = new Config()
|
2012-12-12 23:40:09 +04:00
|
|
|
spyOn(config, 'load')
|
2012-12-13 03:46:30 +04:00
|
|
|
spyOn(config, 'save')
|
2013-03-05 04:40:02 +04:00
|
|
|
config.set "editor.fontFamily", "Courier"
|
2012-12-18 07:56:28 +04:00
|
|
|
config.set "editor.fontSize", 16
|
2013-01-10 21:41:33 +04:00
|
|
|
config.set "editor.autoIndent", false
|
2013-01-27 23:12:39 +04:00
|
|
|
config.set "core.disabledPackages", ["package-that-throws-an-exception"]
|
2012-12-13 03:23:36 +04:00
|
|
|
|
2012-11-15 00:13:57 +04:00
|
|
|
# make editor display updates synchronous
|
|
|
|
spyOn(Editor.prototype, 'requestDisplayUpdate').andCallFake -> @updateDisplay()
|
2013-02-22 05:22:55 +04:00
|
|
|
spyOn(RootView.prototype, 'setTitle').andCallFake (@title) ->
|
2012-11-17 04:13:08 +04:00
|
|
|
spyOn(window, "setTimeout").andCallFake window.fakeSetTimeout
|
|
|
|
spyOn(window, "clearTimeout").andCallFake window.fakeClearTimeout
|
2012-11-20 00:15:35 +04:00
|
|
|
spyOn(File.prototype, "detectResurrectionAfterDelay").andCallFake -> @detectResurrection()
|
2012-11-15 00:13:57 +04:00
|
|
|
|
2012-11-21 19:22:13 +04:00
|
|
|
# make tokenization synchronous
|
|
|
|
TokenizedBuffer.prototype.chunkSize = Infinity
|
|
|
|
spyOn(TokenizedBuffer.prototype, "tokenizeInBackground").andCallFake -> @tokenizeNextChunk()
|
|
|
|
|
2013-01-10 22:56:55 +04:00
|
|
|
pasteboardContent = 'initial pasteboard content'
|
|
|
|
spyOn($native, 'writeToPasteboard').andCallFake (text) -> pasteboardContent = text
|
|
|
|
spyOn($native, 'readFromPasteboard').andCallFake -> pasteboardContent
|
|
|
|
|
2013-03-07 23:04:17 +04:00
|
|
|
addCustomMatchers(this)
|
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
afterEach ->
|
2013-01-04 02:10:11 +04:00
|
|
|
keymap.bindingSets = bindingSetsToRestore
|
|
|
|
keymap.bindingSetsByFirstKeystrokeToRestore = bindingSetsByFirstKeystrokeToRestore
|
2013-03-26 01:37:11 +04:00
|
|
|
atom.deactivatePackages()
|
2013-02-20 04:18:25 +04:00
|
|
|
if rootView?
|
2013-03-26 01:37:11 +04:00
|
|
|
rootView.remove?()
|
2013-02-20 04:18:25 +04:00
|
|
|
window.rootView = null
|
2013-02-20 23:30:39 +04:00
|
|
|
if project?
|
|
|
|
project.destroy()
|
|
|
|
window.project = null
|
2013-02-28 05:50:37 +04:00
|
|
|
if git?
|
|
|
|
git.destroy()
|
|
|
|
window.git = null
|
2012-08-28 02:36:36 +04:00
|
|
|
$('#jasmine-content').empty()
|
2012-11-29 04:16:15 +04:00
|
|
|
ensureNoPathSubscriptions()
|
2013-03-02 02:52:21 +04:00
|
|
|
atom.pendingModals = [[]]
|
|
|
|
atom.presentingModal = false
|
2013-03-22 05:36:50 +04:00
|
|
|
syntax.off()
|
2012-11-29 04:16:15 +04:00
|
|
|
waits(0) # yield to ui thread to make screen update more frequently
|
2012-11-29 00:40:37 +04:00
|
|
|
|
2013-02-14 04:29:51 +04:00
|
|
|
# Specs rely on TextMate bundles (but not atom packages)
|
|
|
|
window.loadTextMatePackages = ->
|
|
|
|
TextMatePackage = require 'text-mate-package'
|
|
|
|
config.packageDirPaths.unshift(fixturePackagesPath)
|
|
|
|
window.textMatePackages = []
|
|
|
|
for path in atom.getPackagePaths() when TextMatePackage.testName(path)
|
2013-03-25 19:41:23 +04:00
|
|
|
window.textMatePackages.push atom.activatePackage(path, sync: true)
|
2013-02-14 04:29:51 +04:00
|
|
|
|
|
|
|
window.loadTextMatePackages()
|
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
ensureNoPathSubscriptions = ->
|
2012-11-29 04:16:15 +04:00
|
|
|
watchedPaths = $native.getWatchedPaths()
|
2012-11-30 03:31:05 +04:00
|
|
|
$native.unwatchAllPaths()
|
2012-11-29 04:16:15 +04:00
|
|
|
if watchedPaths.length > 0
|
|
|
|
throw new Error("Leaking subscriptions for paths: " + watchedPaths.join(", "))
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
emitObject = jasmine.StringPrettyPrinter.prototype.emitObject
|
|
|
|
jasmine.StringPrettyPrinter.prototype.emitObject = (obj) ->
|
|
|
|
if obj.inspect
|
|
|
|
@append obj.inspect()
|
|
|
|
else
|
|
|
|
emitObject.call(this, obj)
|
|
|
|
|
2012-11-17 04:12:04 +04:00
|
|
|
jasmine.unspy = (object, methodName) ->
|
|
|
|
throw new Error("Not a spy") unless object[methodName].originalValue?
|
|
|
|
object[methodName] = object[methodName].originalValue
|
|
|
|
|
2013-03-07 23:04:17 +04:00
|
|
|
addCustomMatchers = (spec) ->
|
|
|
|
spec.addMatchers
|
|
|
|
toBeInstanceOf: (expected) ->
|
|
|
|
notText = if @isNot then " not" else ""
|
|
|
|
this.message = => "Expected #{jasmine.pp(@actual)} to#{notText} be instance of #{expected.name} class"
|
|
|
|
@actual instanceof expected
|
|
|
|
|
|
|
|
toHaveLength: (expected) ->
|
|
|
|
notText = if @isNot then " not" else ""
|
|
|
|
this.message = => "Expected object with length #{@actual.length} to#{notText} have length #{expected}"
|
|
|
|
@actual.length == expected
|
|
|
|
|
2013-03-13 03:55:28 +04:00
|
|
|
toExistOnDisk: (expected) ->
|
|
|
|
notText = this.isNot and " not" or ""
|
|
|
|
@message = -> return "Expected path '" + @actual + "'" + notText + " to exist."
|
|
|
|
fs.exists(@actual)
|
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
window.keyIdentifierForKey = (key) ->
|
|
|
|
if key.length > 1 # named key
|
|
|
|
key
|
|
|
|
else
|
|
|
|
charCode = key.toUpperCase().charCodeAt(0)
|
|
|
|
"U+00" + charCode.toString(16)
|
|
|
|
|
|
|
|
window.keydownEvent = (key, properties={}) ->
|
2013-02-09 02:56:55 +04:00
|
|
|
properties = $.extend({originalEvent: { keyIdentifier: keyIdentifierForKey(key) }}, properties)
|
|
|
|
$.Event("keydown", properties)
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
window.mouseEvent = (type, properties) ->
|
|
|
|
if properties.point
|
|
|
|
{point, editor} = properties
|
|
|
|
{top, left} = @pagePixelPositionForPoint(editor, point)
|
|
|
|
properties.pageX = left + 1
|
|
|
|
properties.pageY = top + 1
|
|
|
|
properties.originalEvent ?= {detail: 1}
|
|
|
|
$.Event type, properties
|
|
|
|
|
|
|
|
window.clickEvent = (properties={}) ->
|
|
|
|
window.mouseEvent("click", properties)
|
|
|
|
|
|
|
|
window.mousedownEvent = (properties={}) ->
|
|
|
|
window.mouseEvent('mousedown', properties)
|
|
|
|
|
|
|
|
window.mousemoveEvent = (properties={}) ->
|
|
|
|
window.mouseEvent('mousemove', properties)
|
|
|
|
|
|
|
|
window.waitsForPromise = (args...) ->
|
|
|
|
if args.length > 1
|
|
|
|
{ shouldReject } = args[0]
|
|
|
|
else
|
|
|
|
shouldReject = false
|
|
|
|
fn = _.last(args)
|
|
|
|
|
|
|
|
window.waitsFor (moveOn) ->
|
|
|
|
promise = fn()
|
|
|
|
if shouldReject
|
|
|
|
promise.fail(moveOn)
|
|
|
|
promise.done ->
|
|
|
|
jasmine.getEnv().currentSpec.fail("Expected promise to be rejected, but it was resolved")
|
|
|
|
moveOn()
|
|
|
|
else
|
|
|
|
promise.done(moveOn)
|
|
|
|
promise.fail (error) ->
|
|
|
|
jasmine.getEnv().currentSpec.fail("Expected promise to be resolved, but it was rejected with #{jasmine.pp(error)}")
|
|
|
|
moveOn()
|
|
|
|
|
|
|
|
window.resetTimeouts = ->
|
|
|
|
window.now = 0
|
|
|
|
window.timeoutCount = 0
|
|
|
|
window.timeouts = []
|
|
|
|
|
2012-11-17 04:13:08 +04:00
|
|
|
window.fakeSetTimeout = (callback, ms) ->
|
2012-08-28 02:36:36 +04:00
|
|
|
id = ++window.timeoutCount
|
|
|
|
window.timeouts.push([id, window.now + ms, callback])
|
|
|
|
id
|
|
|
|
|
2012-11-17 04:13:08 +04:00
|
|
|
window.fakeClearTimeout = (idToClear) ->
|
2012-08-28 02:36:36 +04:00
|
|
|
window.timeouts = window.timeouts.filter ([id]) -> id != idToClear
|
|
|
|
|
|
|
|
window.advanceClock = (delta=1) ->
|
|
|
|
window.now += delta
|
2012-11-20 03:50:07 +04:00
|
|
|
callbacks = []
|
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
window.timeouts = window.timeouts.filter ([id, strikeTime, callback]) ->
|
|
|
|
if strikeTime <= window.now
|
2012-11-20 03:50:07 +04:00
|
|
|
callbacks.push(callback)
|
2012-08-28 02:36:36 +04:00
|
|
|
false
|
|
|
|
else
|
|
|
|
true
|
|
|
|
|
2012-11-20 03:50:07 +04:00
|
|
|
callback() for callback in callbacks
|
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
window.pagePixelPositionForPoint = (editor, point) ->
|
|
|
|
point = Point.fromObject point
|
|
|
|
top = editor.renderedLines.offset().top + point.row * editor.lineHeight
|
|
|
|
left = editor.renderedLines.offset().left + point.column * editor.charWidth - editor.renderedLines.scrollLeft()
|
|
|
|
{ top, left }
|
|
|
|
|
|
|
|
window.tokensText = (tokens) ->
|
|
|
|
_.pluck(tokens, 'value').join('')
|
|
|
|
|
|
|
|
window.setEditorWidthInChars = (editor, widthInChars, charWidth=editor.charWidth) ->
|
2012-09-25 23:27:46 +04:00
|
|
|
editor.width(charWidth * widthInChars + editor.gutter.outerWidth())
|
2012-08-28 02:36:36 +04:00
|
|
|
$(window).trigger 'resize' # update width of editor's on-screen lines
|
|
|
|
|
|
|
|
window.setEditorHeightInLines = (editor, heightInChars, charHeight=editor.lineHeight) ->
|
|
|
|
editor.height(charHeight * heightInChars + editor.renderedLines.position().top)
|
|
|
|
$(window).trigger 'resize' # update editor's on-screen lines
|
|
|
|
|
|
|
|
$.fn.resultOfTrigger = (type) ->
|
|
|
|
event = $.Event(type)
|
|
|
|
this.trigger(event)
|
|
|
|
event.result
|
|
|
|
|
|
|
|
$.fn.enableKeymap = ->
|
|
|
|
@on 'keydown', (e) => window.keymap.handleKeyEvent(e)
|
|
|
|
|
|
|
|
$.fn.attachToDom = ->
|
|
|
|
$('#jasmine-content').append(this)
|
|
|
|
|
|
|
|
$.fn.simulateDomAttachment = ->
|
|
|
|
$('<html>').append(this)
|
|
|
|
|
|
|
|
$.fn.textInput = (data) ->
|
|
|
|
this.each ->
|
|
|
|
event = document.createEvent('TextEvent')
|
|
|
|
event.initTextEvent('textInput', true, true, window, data)
|
|
|
|
event = jQuery.event.fix(event)
|
|
|
|
$(this).trigger(event)
|
|
|
|
|
|
|
|
unless fs.md5ForPath(require.resolve('fixtures/sample.js')) == "dd38087d0d7e3e4802a6d3f9b9745f2b"
|
|
|
|
throw "Sample.js is modified"
|