New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making test run on windows #256
Conversation
Verified on Windows 10, OS X El Capitan, Ubuntu 14.04 |
@@ -247,6 +247,8 @@ describe('Metalsmith', function(){ | |||
}); | |||
|
|||
it('should traverse a symbolic link to a directory', function(done){ | |||
// symbolic links are *nix specific | |||
if (process.platform === 'win32') { return done(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, symbolic links actually do exist in NTFS, and you can create them on Windows with the mklink
command if you have Adminstrative privileges. Not sure if we want to support that though. In any case, it's definitely not something that needs to be done in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... I have never seen anyone using it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good overall, though I do have a few questions/comments...
@@ -247,6 +247,8 @@ describe('Metalsmith', function(){ | |||
}); | |||
|
|||
it('should traverse a symbolic link to a directory', function(done){ | |||
// symbolic links are *nix specific | |||
if (process.platform === 'win32') { return done(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of just automatically passing this test on Windows, I think it'd be more honest to skip()
it: https://mochajs.org#inclusive-tests (See the section on skipping at runtime)
@@ -391,6 +393,8 @@ describe('Metalsmith', function(){ | |||
}); | |||
|
|||
it('should chmod an optional mode from file metadata', function(done){ | |||
// chmod is not really working on windows https://github.com/nodejs/node-v0.x-archive/issues/4812#issue-11211650 | |||
if (process.platform === 'win32') { return done(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. Skip instead of pass.
@@ -280,7 +280,7 @@ Metalsmith.prototype.readFile = unyield(function*(file){ | |||
|
|||
if (frontmatter && utf8(buffer)) { | |||
try { | |||
parsed = matter(buffer.toString()); | |||
parsed = matter(buffer.toString().replace(/\r\n/g, '\n')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does gray-matter choke on Windows-style line endings? If so, have you looked into trying to fix this problem upstream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gray-matter fails on this line: https://github.com/jonschlinkert/gray-matter/blob/master/index.js#L98. I originally changed this line to account for \r\n which fixed the problem but the usage as described here implies that \r\n
is not something they want to support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused. Where in that doc does it state that gray-matter's maintainers are unwilling to support Windows-style line endings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I am stretching this a bit but all the usages show only \n
and the code itself does not support Windows line endings so my conclusion was that they don't really care about Windows. As you proposed, I might try to add support for Windows line endings in gray-matter and see how it goes. If there is support for \r\n
this line will be able to be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's pretty clear Windows isn't currently supported by gray-matter.
My point was that since it's gray-matter's lack of Windows support that's causing Metalsmith to fail here, it's probably best to fix that problem at the root instead of trying to work around it. Doing it that way is more in line with separation of concerns, and has the potential to benefit other projects besides Metalsmith which use gray-matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Will look into this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1 @@ | |||
*.html text=auto eol=lf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. So only the output needs Unix-style line endings? The source .md
files can have either line ending style and that doesn't affect the output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even on windows the output seems to contain just \n
. The problem is that if the line ending is set to autocrlf the baseline files will have \r\n
so the tests fails. This change forces \n
line endings for html files in the subtree fixing the line ending mismatch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I wonder where that conversion is happening... seems reasonable to me though.
@@ -0,0 +1 @@ | |||
*.html text=auto eol=lf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline at end of file.
@@ -0,0 +1 @@ | |||
*.md text=auto eol=lf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this change needed? (Sorry, don't have access to a Windows computer right now that I can test this on.) Were the line endings on the file being output by Metalsmith somehow different from the input file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So Metalsmith itself is somehow converting the newline characters to LF? That's really strange. I can understand it happening when converting from Markdown to HTML, but Metalsmith shouldn't be changing anything on its own with no plugins. I guess that's a separate issue though...
@@ -0,0 +1 @@ | |||
*.md text=auto eol=lf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, missing newline at end of file.
Note to self: add Appveyor for Windows tests. |
🆙📅 |
Looks good. I do want to check that issue with the seemingly random newline conversion by Metalsmith though before merging. That seems really strange... Also might want to talk to grey-matter's maintainer about getting Windows support upstream. |
Can the conversion be actually a side effect of this: https://github.com/metalsmith/metalsmith/pull/256/files#diff-6d186b954a58d5bb740f73d84fe39073R283? |
@moozzyk Ah, you're right! I actually considered that possibility previously but dismissed it since So yeah, that's almost certainly the problem. Good catch! |
@@ -280,7 +280,7 @@ Metalsmith.prototype.readFile = unyield(function*(file){ | |||
|
|||
if (frontmatter && utf8(buffer)) { | |||
try { | |||
parsed = matter(buffer.toString()); | |||
parsed = matter(buffer.toString().replace(/\r\n/g, '\n')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this should probably be changed since it's effectively altering the value of the contents
property on the file object further down. Good catch!
Maybe you can kill two birds with one stone here by getting Windows support added upstream in grey-matter.
@Ajedi32 - I will try to send a PR to gray-matter to fix the crlf issue but even if this is fixed the |
Hmm. Well, it would be great if marked handled Windows line endings (actually I'm rather surprised to hear it doesn't), but since marked isn't a dependency of the Metalsmith core I don't think that's something that needs to be addressed in this PR. I'd be fine with you either changing the test to remove the dependency on You might also want to consider filing an issue with marked about supporting Windows line endings, just to document that for future reference. |
🆙📅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Just a couple more minor tweaks...
@@ -1,3 +1,4 @@ | |||
node_modules | |||
test/fixtures/*/build | |||
coverage | |||
.vscode/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline at end of file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad habits. It's fixed now.
@@ -0,0 +1 @@ | |||
*.html text=auto eol=lf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So metalsmith-markdown works with Windows-style newlines after all? Or is that test still failing for you on Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The test is failing on windows because the output has \n
while the baseline file has \r\n
. I added .gitattributes to enforce \n
in the baseline file even on windows to make the test pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay. Yeah, that's totally fine. We're testing Metalsmith here, not the metalsmith-markdown
plugin. Plus I'm not sure that always outputting html files with Unix-style newlines is even a bad idea...
Gonna test this on my machine before merging... |
Gah, Windows doesn't have Hold on, might take me a bit to figure out how to get that working. The GNU Win32 version is just crashing on me... long-term we may want to just use a cross-platform tool like Grunt or something. |
I installed mingw etc. but still running things using makefile did not work due to these lines: https://github.com/metalsmith/metalsmith/blob/master/Makefile#L6-L8 (sorry don't have the error handy).
|
I think this is a case for using npm scripts instead. I'll create a issue for that. |
Yeah, tests work fine on my machine if I just run Mocha directly. Gonna merge this now and we can work on getting the build working without |
Fixes: #158