Fix failing PHP-CS-Fixer Beautifier specs, disable some on Windows

This commit is contained in:
Glavin Wiechert 2015-06-11 22:07:56 -03:00
parent b0d8dfa6fb
commit 6b7b3d6401
3 changed files with 66 additions and 51 deletions

View File

@ -7,6 +7,11 @@ Beautifier = require "../src/beautifiers/beautifier"
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit` # To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
# or `fdescribe`). Remove the `f` to unfocus the block. # or `fdescribe`). Remove the `f` to unfocus the block.
# Check if Windows
isWindows = process.platform is 'win32' or
process.env.OSTYPE is 'cygwin' or
process.env.OSTYPE is 'msys'
describe "Atom-Beautify", -> describe "Atom-Beautify", ->
beforeEach -> beforeEach ->
@ -139,41 +144,42 @@ describe "Atom-Beautify", ->
p.then(cb, cb) p.then(cb, cb)
return p return p
it "should error with Mac/Linux-specific help description \ unless isWindows
when beautifier's program not found", -> it "should error with Mac/Linux-specific help description \
expect(beautifier).not.toBe(null) when beautifier's program not found", ->
expect(beautifier instanceof Beautifier).toBe(true) expect(beautifier).not.toBe(null)
expect(beautifier instanceof Beautifier).toBe(true)
waitsForPromise shouldReject: true, -> waitsForPromise shouldReject: true, ->
help = { help = {
link: "http://test.com" link: "http://test.com"
program: "test-program" program: "test-program"
pathOption: "Lang - Test Program Path" pathOption: "Lang - Test Program Path"
} }
# Force to be Mac/Linux (not Windows) # Force to be Mac/Linux (not Windows)
beautifier.isWindows = false beautifier.isWindows = false
terminal = "Terminal" terminal = "Terminal"
whichCmd = "which" whichCmd = "which"
# Process # Process
p = beautifier.run("program", [], help: help) p = beautifier.run("program", [], help: help)
expect(p).not.toBe(null) expect(p).not.toBe(null)
expect(p instanceof beautifier.Promise).toBe(true) expect(p instanceof beautifier.Promise).toBe(true)
cb = (v) -> cb = (v) ->
# console.log(v) # console.log(v)
expect(v).not.toBe(null) expect(v).not.toBe(null)
expect(v instanceof Error).toBe(true) expect(v instanceof Error).toBe(true)
expect(v.code).toBe("CommandNotFound") expect(v.code).toBe("CommandNotFound")
expect(v.description).not.toBe(null) expect(v.description).not.toBe(null)
expect(v.description.indexOf(help.link)).not.toBe(-1) expect(v.description.indexOf(help.link)).not.toBe(-1)
expect(v.description.indexOf(help.program)).not.toBe(-1) expect(v.description.indexOf(help.program)).not.toBe(-1)
expect(v.description expect(v.description
.indexOf(terminal)).not.toBe(-1, \ .indexOf(terminal)).not.toBe(-1, \
"Error should have a description including \ "Error should have a description including \
'#{terminal}' in message.") '#{terminal}' in message.")
expect(v.description expect(v.description
.indexOf(whichCmd)).not.toBe(-1, \ .indexOf(whichCmd)).not.toBe(-1, \
"Error should have a description including \ "Error should have a description including \
'#{whichCmd}' in message.") '#{whichCmd}' in message.")
return v return v
p.then(cb, cb) p.then(cb, cb)
return p return p

View File

@ -7,6 +7,11 @@ path = require 'path'
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit` # To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
# or `fdescribe`). Remove the `f` to unfocus the block. # or `fdescribe`). Remove the `f` to unfocus the block.
# Check if Windows
isWindows = process.platform is 'win32' or
process.env.OSTYPE is 'cygwin' or
process.env.OSTYPE is 'msys'
describe "PHP-CS-Fixer Beautifier", -> describe "PHP-CS-Fixer Beautifier", ->
beforeEach -> beforeEach ->
@ -43,11 +48,13 @@ describe "PHP-CS-Fixer Beautifier", ->
fixers: "" fixers: ""
levels: "" levels: ""
} }
# Mock PATH # Mock spawn
beautifier.getShellEnvironment = -> Promise.resolve({ beautifier.spawn = (exe, args, options) ->
PATH: '' # console.log('spawn', exe, args, options)
}) er = new Error('ENOENT')
# er.code = 'ENOENT'
return beautifier.Promise.reject(er)
# Beautify
p = beautifier.beautify(text, language, options) p = beautifier.beautify(text, language, options)
expect(p).not.toBe(null) expect(p).not.toBe(null)
expect(p instanceof beautifier.Promise).toBe(true) expect(p instanceof beautifier.Promise).toBe(true)
@ -119,13 +126,14 @@ describe "PHP-CS-Fixer Beautifier", ->
failWhichProgram('php') failWhichProgram('php')
failWhichProgram('php-cs-fixer') failWhichProgram('php-cs-fixer')
describe "Mac/Linux", -> unless isWindows
describe "Mac/Linux", ->
beforeEach -> beforeEach ->
# console.log('mac/linx') # console.log('mac/linx')
beautifier.isWindows = false beautifier.isWindows = false
do OSSpecificSpecs do OSSpecificSpecs
describe "Windows", -> describe "Windows", ->

View File

@ -10,6 +10,11 @@ JsDiff = require('diff')
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit` # To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
# or `fdescribe`). Remove the `f` to unfocus the block. # or `fdescribe`). Remove the `f` to unfocus the block.
# Check if Windows
isWindows = process.platform is 'win32' or
process.env.OSTYPE is 'cygwin' or
process.env.OSTYPE is 'msys'
describe "BeautifyLanguages", -> describe "BeautifyLanguages", ->
optionsDir = path.resolve(__dirname, "../examples") optionsDir = path.resolve(__dirname, "../examples")
@ -47,10 +52,6 @@ describe "BeautifyLanguages", ->
# Force activate package # Force activate package
pack = atom.packages.getLoadedPackage("atom-beautify") pack = atom.packages.getLoadedPackage("atom-beautify")
pack.activateNow() pack.activateNow()
# Check if Windows
isWindows = process.platform is 'win32' or
process.env.OSTYPE is 'cygwin' or
process.env.OSTYPE is 'msys'
# Need more debugging on Windows # Need more debugging on Windows
if isWindows if isWindows
# Change logger level # Change logger level