Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Fix specs on Windows...again #99

Merged
merged 5 commits into from
Nov 20, 2015
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/notification-issue.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,22 @@ class NotificationIssue
packagePaths[packageName] = fs.realpathSync(packagePath)

getPackageName = (filePath) =>
filePath = /(\((.+?):\d+|\((.+)\)|(.+))/.exec(filePath)[1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused by the nesting of capture groups here. Does item 1 in the match array represent the entire match, because the entire thing is wrapped in parens? If so, maybe you could just remove the outer parens and use item 0?


# Stack traces may be a file URI
if /file:\/\/(\w*)\/(.*)/.test(filePath)
filePath = /file:\/\/(\w*)\/(.*)/.exec(filePath)[2]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the same regex is created and executed twice here, and the first capture group is unused. Also, sometimes when regexps have multiple / characters, it's easier to write them using the RegExp constructor than as literals. I think it'd be nice to do it like this:

# somewhere at the top of the file
FileURLRegExp = new RegExp('file://\w*/(.*)')

# ...

   if match = FileURLRegExp.exec(filePath)
     filePath = match[1]

if path.isAbsolute(filePath)
for packName, packagePath of packagePaths
continue if filePath is 'node.js'
relativePath = path.relative(packagePath, filePath)
return packName unless /^\.\./.test(relativePath)
@getPackageNameFromFilePath(filePath)

if options.detail? and packageName = getPackageName(options.detail)
return packageName
if options.detail?
packageName = getPackageName(options.detail)
return packageName if packageName?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this change? cc @maxbrunsfeld style 👀?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I forgot to fully revert it after I moved the regex out of this if. Fixing now...


if options.stack?
stack = StackTraceParser.parse(options.stack)
Expand Down
3 changes: 1 addition & 2 deletions spec/notifications-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,7 @@ describe "Notifications", ->
a + 1
catch e
# Pull the file path from the stack
# For Windows we have to ignore the starting drive letter (eg C:\)
filePath = e.stack.split('\n')[1].match(/\(((\w:\\)[^:]+|([^:]+))/)[1]
filePath = e.stack.split('\n')[1].match(/\((.+?):\d+/)[1]
window.onerror.call(window, e.toString(), filePath, 2, 3, message: e.toString(), stack: undefined)

notificationContainer = workspaceElement.querySelector('atom-notifications')
Expand Down