forked from atom/atom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialize-test-window.coffee
81 lines (64 loc) · 2.93 KB
/
initialize-test-window.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
ipcHelpers = require './ipc-helpers'
cloneObject = (object) ->
clone = {}
clone[key] = value for key, value of object
clone
module.exports = ({blobStore}) ->
startCrashReporter = require('./crash-reporter-start')
{remote} = require 'electron'
startCrashReporter() # Before anything else
exitWithStatusCode = (status) ->
remote.app.emit('will-quit')
remote.process.exit(status)
try
path = require 'path'
{ipcRenderer} = require 'electron'
{getWindowLoadSettings} = require './window-load-settings-helpers'
AtomEnvironment = require '../src/atom-environment'
ApplicationDelegate = require '../src/application-delegate'
require '../src/electron-shims'
{testRunnerPath, legacyTestRunnerPath, headless, logFile, testPaths} = getWindowLoadSettings()
unless headless
# Show window synchronously so a focusout doesn't fire on input elements
# that are focused in the very first spec run.
remote.getCurrentWindow().show()
handleKeydown = (event) ->
# Reload: cmd-r / ctrl-r
if (event.metaKey or event.ctrlKey) and event.keyCode is 82
ipcHelpers.call('window-method', 'reload')
# Toggle Dev Tools: cmd-alt-i (Mac) / ctrl-shift-i (Linux/Windows)
if event.keyCode is 73 and (
(process.platform is 'darwin' and event.metaKey and event.altKey) or
(process.platform isnt 'darwin' and event.ctrlKey and event.shiftKey))
ipcHelpers.call('window-method', 'toggleDevTools')
# Close: cmd-w / ctrl-w
if (event.metaKey or event.ctrlKey) and event.keyCode is 87
ipcHelpers.call('window-method', 'close')
# Copy: cmd-c / ctrl-c
if (event.metaKey or event.ctrlKey) and event.keyCode is 67
ipcHelpers.call('window-method', 'copy')
window.addEventListener('keydown', handleKeydown, true)
# Add 'exports' to module search path.
exportsPath = path.join(getWindowLoadSettings().resourcePath, 'exports')
require('module').globalPaths.push(exportsPath)
process.env.NODE_PATH = exportsPath # Set NODE_PATH env variable since tasks may need it.
document.title = "Spec Suite"
testRunner = require(testRunnerPath)
legacyTestRunner = require(legacyTestRunnerPath)
buildDefaultApplicationDelegate = -> new ApplicationDelegate()
buildAtomEnvironment = (params) ->
params = cloneObject(params)
params.blobStore = blobStore unless params.hasOwnProperty("blobStore")
params.onlyLoadBaseStyleSheets = true unless params.hasOwnProperty("onlyLoadBaseStyleSheets")
new AtomEnvironment(params)
promise = testRunner({
logFile, headless, testPaths, buildAtomEnvironment, buildDefaultApplicationDelegate, legacyTestRunner
})
promise.then (statusCode) ->
exitWithStatusCode(statusCode) if getWindowLoadSettings().headless
catch error
if getWindowLoadSettings().headless
console.error(error.stack ? error)
exitWithStatusCode(1)
else
throw error