Major improvement to tests: display diff of original vs expected

This commit is contained in:
Glavin Wiechert 2015-04-29 16:41:57 -03:00
parent 9d6dc8d04f
commit 5797b4bb00
2 changed files with 13 additions and 2 deletions

View File

@ -54,6 +54,7 @@
"atom-space-pen-views": "^2.0.3", "atom-space-pen-views": "^2.0.3",
"bluebird": "^2.9.25", "bluebird": "^2.9.25",
"coffee-formatter": "^0.1.1", "coffee-formatter": "^0.1.1",
"diff": "^1.3.2",
"editorconfig": "^0.11.4", "editorconfig": "^0.11.4",
"emissary": "^1.0.0", "emissary": "^1.0.0",
"expand-home-dir": "0.0.2", "expand-home-dir": "0.0.2",

View File

@ -3,6 +3,7 @@ Beautifiers = require "../src/beautifiers"
beautifier = new Beautifiers() beautifier = new Beautifiers()
fs = require "fs" fs = require "fs"
path = require "path" path = require "path"
JsDiff = require('diff')
# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs. # Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
# #
@ -135,9 +136,18 @@ describe "BeautifyLanguages", ->
if text instanceof Error if text instanceof Error
return beautifyCompleted = text # text == Error return beautifyCompleted = text # text == Error
expect(typeof text).toEqual "string" expect(typeof text).toEqual "string"
# Check for beautification errors
if text isnt expectedContents if text isnt expectedContents
console.warn(allOptions, text, expectedContents) # console.warn(allOptions, text, expectedContents)
expect(text).toEqual expectedContents fileName = originalTestPath
oldStr=text
newStr=expectedContents
oldHeader="original"
newHeader="expected"
diff = JsDiff.createPatch(fileName, oldStr, newStr, oldHeader, newHeader)
throw new Error("Beautifier output does not match expected output:\n"+diff)
#expect(text).toEqual expectedContents
# All done!
beautifyCompleted = true beautifyCompleted = true
runs -> runs ->