Skip to content
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

Merged
merged 4 commits into from Oct 28, 2016
Merged

Making test run on windows #256

merged 4 commits into from Oct 28, 2016

Conversation

moozzyk
Copy link
Contributor

@moozzyk moozzyk commented Oct 15, 2016

Fixes: #158

@moozzyk
Copy link
Contributor Author

moozzyk commented Oct 15, 2016

Verified on Windows 10, OS X El Capitan, Ubuntu 14.04

@coveralls
Copy link

coveralls commented Oct 15, 2016

Coverage Status

Coverage remained the same at 94.304% when pulling f5d34b4 on moozzyk:moozzyk/bug-158 into 1ceb80b on metalsmith:master.

@coveralls
Copy link

coveralls commented Oct 15, 2016

Coverage Status

Coverage remained the same at 94.304% when pulling 3d4d2f9 on moozzyk:moozzyk/bug-158 into 1ceb80b on metalsmith:master.

@@ -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(); }
Copy link
Member

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.

Copy link
Contributor Author

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...

Copy link
Member

@Ajedi32 Ajedi32 left a 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(); }
Copy link
Member

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(); }
Copy link
Member

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'));
Copy link
Member

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?

Copy link
Contributor Author

@moozzyk moozzyk Oct 18, 2016

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

@moozzyk moozzyk Oct 18, 2016

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.

Copy link
Member

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
Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my comment above.

Copy link
Member

@Ajedi32 Ajedi32 Oct 19, 2016

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
Copy link
Member

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.

@Ajedi32
Copy link
Member

Ajedi32 commented Oct 17, 2016

Note to self: add Appveyor for Windows tests.

@coveralls
Copy link

coveralls commented Oct 18, 2016

Coverage Status

Coverage remained the same at 94.304% when pulling 79f7c70 on moozzyk:moozzyk/bug-158 into 1ceb80b on metalsmith:master.

@moozzyk
Copy link
Contributor Author

moozzyk commented Oct 18, 2016

🆙📅

@Ajedi32
Copy link
Member

Ajedi32 commented Oct 19, 2016

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.

@moozzyk
Copy link
Contributor Author

moozzyk commented Oct 19, 2016

Can the conversion be actually a side effect of this: https://github.com/metalsmith/metalsmith/pull/256/files#diff-6d186b954a58d5bb740f73d84fe39073R283?

@Ajedi32
Copy link
Member

Ajedi32 commented Oct 19, 2016

@moozzyk Ah, you're right!

I actually considered that possibility previously but dismissed it since replace doesn't mutate the string or anything (strings in JS are immutable), but now that I look at it again I see that Metalsmith is assigning ret.contents = new Buffer(parsed.content); further down.

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'));
Copy link
Member

@Ajedi32 Ajedi32 Oct 19, 2016

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.

@moozzyk
Copy link
Contributor Author

moozzyk commented Oct 23, 2016

@Ajedi32 - I will try to send a PR to gray-matter to fix the crlf issue but even if this is fixed the should require plugins as an array test won't pass. This test use marked.js as a plugin fail because marked.js is using \n line ending all over the place (e.g. https://github.com/chjj/marked/blob/38f1727ffee0820975677027b8968bc1954e6637/lib/marked.js#L805). What is the course of action here?

@Ajedi32
Copy link
Member

Ajedi32 commented Oct 24, 2016

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 metalsmith-markdown, or adding a .gitattributes to the cli-plugin-array fixture to ensure that its source files use Unix-style line endings. (The later option would probably be quite a bit easier.)

You might also want to consider filing an issue with marked about supporting Windows line endings, just to document that for future reference.

@coveralls
Copy link

coveralls commented Oct 25, 2016

Coverage Status

Coverage remained the same at 94.304% when pulling d3ceba5 on moozzyk:moozzyk/bug-158 into 1ceb80b on metalsmith:master.

@coveralls
Copy link

coveralls commented Oct 25, 2016

Coverage Status

Coverage remained the same at 94.304% when pulling 030cd8c on moozzyk:moozzyk/bug-158 into e3f2e12 on metalsmith:master.

@moozzyk
Copy link
Contributor Author

moozzyk commented Oct 25, 2016

🆙📅

Copy link
Member

@Ajedi32 Ajedi32 left a 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/
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

@Ajedi32 Ajedi32 Oct 25, 2016

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?

Copy link
Contributor Author

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.

Copy link
Member

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...

@coveralls
Copy link

coveralls commented Oct 25, 2016

Coverage Status

Coverage remained the same at 94.304% when pulling 1aafad3 on moozzyk:moozzyk/bug-158 into e3f2e12 on metalsmith:master.

@coveralls
Copy link

coveralls commented Oct 25, 2016

Coverage Status

Coverage remained the same at 94.304% when pulling 7032d2e on moozzyk:moozzyk/bug-158 into e3f2e12 on metalsmith:master.

@Ajedi32
Copy link
Member

Ajedi32 commented Oct 25, 2016

Gonna test this on my machine before merging...

@Ajedi32
Copy link
Member

Ajedi32 commented Oct 26, 2016

Gah, Windows doesn't have make. 😝

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.

@moozzyk
Copy link
Contributor Author

moozzyk commented Oct 26, 2016

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). NODE_FLAGS is also not portable. To run tests I just ran:

npm install
node_modules\.bin\mocha

@woodyrew
Copy link
Member

woodyrew commented Oct 27, 2016

Gah, Windows doesn't have make. 😝

I think this is a case for using npm scripts instead. I'll create a issue for that.

@Ajedi32
Copy link
Member

Ajedi32 commented Oct 28, 2016

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 make in a future PR.

@Ajedi32 Ajedi32 merged commit 122728c into metalsmith:master Oct 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants