mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-12-30 18:18:45 +03:00
Add integration test for starting atom w/ different arguments
This commit is contained in:
parent
ab43b08739
commit
c19d99e9e2
@ -58,6 +58,7 @@
|
||||
"scoped-property-store": "^0.16.2",
|
||||
"scrollbar-style": "^2.0.0",
|
||||
"season": "^5.1.2",
|
||||
"selenium-webdriver": "^2.44.0",
|
||||
"semver": "2.2.1",
|
||||
"serializable": "^1",
|
||||
"service-hub": "^0.2.0",
|
||||
|
36
spec/integration/helpers/atom-launcher.sh
Executable file
36
spec/integration/helpers/atom-launcher.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script wraps the `Atom` binary, allowing the `chromedriver` server to
|
||||
# execute it with positional arguments. `chromedriver` only allows 'switches'
|
||||
# to be specified when starting a browser, not positional arguments, so this
|
||||
# script accepts two special switches:
|
||||
#
|
||||
# * `atom-path` The path to the `Atom` binary
|
||||
# * `atom-args` A space-separated list of positional arguments to pass to Atom.
|
||||
#
|
||||
# Any other switches will be passed through to `Atom`.
|
||||
|
||||
atom_path=""
|
||||
atom_switches=()
|
||||
atom_args=()
|
||||
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
--atom-path=*)
|
||||
atom_path="${arg#*=}"
|
||||
;;
|
||||
|
||||
--atom-args=*)
|
||||
atom_args_string="${arg#*=}"
|
||||
for atom_arg in $atom_args_string; do
|
||||
atom_args+=($atom_arg)
|
||||
done
|
||||
;;
|
||||
|
||||
*)
|
||||
atom_switches+=($arg)
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
exec $atom_path "${atom_switches[@]}" "${atom_args[@]}"
|
85
spec/integration/startup-spec.coffee
Normal file
85
spec/integration/startup-spec.coffee
Normal file
@ -0,0 +1,85 @@
|
||||
os = require "os"
|
||||
fs = require "fs"
|
||||
path = require "path"
|
||||
remote = require "remote"
|
||||
temp = require("temp").track()
|
||||
{spawn, spawnSync} = require "child_process"
|
||||
{Builder, By} = require("selenium-webdriver")
|
||||
|
||||
AtomPath = remote.process.argv[0]
|
||||
AtomLauncherPath = path.join(__dirname, "helpers", "atom-launcher.sh")
|
||||
SocketPath = path.join(os.tmpdir(), "atom-integration-test.sock")
|
||||
ChromeDriverPort = 9515
|
||||
|
||||
describe "Starting Atom", ->
|
||||
if spawnSync("type", ["-P", "chromedriver"]).status isnt 0
|
||||
console.log "Skipping integration tests because the `chromedriver` executable was not found."
|
||||
return
|
||||
|
||||
[chromeDriver, driver, tempDirPath] = []
|
||||
|
||||
beforeEach ->
|
||||
tempDirPath = temp.mkdirSync("empty-dir")
|
||||
chromeDriver = spawn "chromedriver", ["--verbose", "--port=#{ChromeDriverPort}"]
|
||||
|
||||
# Uncomment to see chromedriver debug output
|
||||
# chromeDriver.stderr.on "data", (d) -> console.log(d.toString())
|
||||
|
||||
afterEach ->
|
||||
waitsForPromise -> driver.quit().thenFinally(-> chromeDriver.kill())
|
||||
|
||||
startAtom = (args=[]) ->
|
||||
driver = new Builder()
|
||||
.usingServer("http://localhost:#{ChromeDriverPort}")
|
||||
.withCapabilities(
|
||||
chromeOptions:
|
||||
binary: AtomLauncherPath
|
||||
args: [
|
||||
"atom-path=#{AtomPath}"
|
||||
"atom-args=#{args.join(" ")}"
|
||||
"dev"
|
||||
"safe"
|
||||
"user-data-dir=#{temp.mkdirSync('integration-spec-')}"
|
||||
"socket-path=#{SocketPath}"
|
||||
]
|
||||
)
|
||||
.forBrowser('atom')
|
||||
.build()
|
||||
|
||||
waitsForPromise ->
|
||||
driver.wait ->
|
||||
driver.getTitle().then (title) -> title.indexOf("Atom") >= 0
|
||||
|
||||
describe "when given the name of a file that doesn't exist", ->
|
||||
beforeEach ->
|
||||
startAtom([path.join(tempDirPath, "new-file")])
|
||||
|
||||
it "opens a new window with an empty text editor", ->
|
||||
waitsForPromise ->
|
||||
driver.executeScript(-> atom.workspace.getActiveTextEditor().getText()).then (text) ->
|
||||
expect(text).toBe("")
|
||||
|
||||
driver.findElement(By.tagName("atom-text-editor")).sendKeys("Hello world!")
|
||||
|
||||
driver.executeScript(-> atom.workspace.getActiveTextEditor().getText()).then (text) ->
|
||||
expect(text).toBe("Hello world!")
|
||||
|
||||
describe "when given the name of a file that exists", ->
|
||||
beforeEach ->
|
||||
existingFilePath = path.join(tempDirPath, "existing-file")
|
||||
fs.writeFileSync(existingFilePath, "This was already here.")
|
||||
startAtom([existingFilePath])
|
||||
|
||||
it "opens a new window with a text editor for the given file", ->
|
||||
waitsForPromise ->
|
||||
driver.executeScript(-> atom.workspace.getActiveTextEditor().getText()).then (text) ->
|
||||
expect(text).toBe("This was already here.")
|
||||
|
||||
describe "when given the name of a directory that exists", ->
|
||||
beforeEach ->
|
||||
startAtom([tempDirPath])
|
||||
|
||||
it "opens a new window no text editors open", ->
|
||||
waitsForPromise ->
|
||||
driver.executeScript(-> atom.workspace.getActiveTextEditor()).then (editor) ->
|
||||
expect(editor).toBeNull()
|
@ -305,13 +305,13 @@ window.waitsForPromise = (args...) ->
|
||||
window.waitsFor timeout, (moveOn) ->
|
||||
promise = fn()
|
||||
if shouldReject
|
||||
promise.catch(moveOn)
|
||||
(promise.catch ? promise.thenCatch).call(promise, moveOn)
|
||||
promise.then ->
|
||||
jasmine.getEnv().currentSpec.fail("Expected promise to be rejected, but it was resolved")
|
||||
moveOn()
|
||||
else
|
||||
promise.then(moveOn)
|
||||
promise.catch (error) ->
|
||||
(promise.catch ? promise.thenCatch).call promise, (error) ->
|
||||
jasmine.getEnv().currentSpec.fail("Expected promise to be resolved, but it was rejected with #{jasmine.pp(error)}")
|
||||
moveOn()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user