neutrinojs / neutrino

Create and build modern JavaScript projects with zero initial configuration.
https://neutrinojs.org
Mozilla Public License 2.0
3.95k stars 213 forks source link

Tests fail because of CRLF-LF #1628

Closed constgen closed 4 years ago

constgen commented 4 years ago

Bug

Here is the output from the CLI

image

CRLF - is code generated from migrate LF - is code generated from packages\migrate\test\fixtures\.neutrinorc.js.txt

The full output from the CLI

  1 test failed

  migrate » test » migrate_test » performs valid transformation

  C:\Projects\Projects_GitHub\neutrino-dev\packages\migrate\test\migrate_test.js:18

   17:
   18:   t.is(output, snapshot);
   19: });

  Difference:

    `const eslint = require('@neutrinojs/eslint');␊
    const airbnbBase = require('@neutrinojs/airbnb-base');␊
    const node = require('@neutrinojs/node');␊
    const jest = require('@neutrinojs/jest');␊
    const fakePreset = require('fake-preset');␊
    ␊
  - module.exports = {␍␊
  -   options: {␍␊
  -     root: __dirname,␍␊
  -   },␍␊
  -   use: [␍␊
  -     (neutrino) => {␍␊
  -       neutrino.use(fakePreset());␍␊
  -     },␍␊
  -     process.env.NODE_ENV === 'development' && eslint(),␍␊
  -     airbnbBase({␍␊
  -       eslint: {␍␊
  -         baseConfig: {␍␊
  -           rules: {␍␊
  -             semi: 'off',␍␊
  -           },␍␊
  -         },␍␊
  -       },␍␊
  -     }),␍␊
  -     node(),␍␊
  -     process.env.NODE_ENV === 'test' && jest({␍␊
  -       testRegex: '(/__tests__/.*|(\\\\.|/)(test|spec))\\\\.(jsx?|tsx?)$',␍␊
  -     }),␍␊
  -     (neutrino) => {␍␊
  -       neutrino.config.externals(/^[a-z\\-0-9]+$/);␍␊
  -       neutrino.use(fakePreset({ alpha: 'beta' }));␍␊
  -     },␍␊
  -   ],␍␊
  + module.exports = {␊
  +   options: {␊
  +     root: __dirname,␊
  +   },␊
  +   use: [␊
  +     (neutrino) => {␊
  +       neutrino.use(fakePreset());␊
  +     },␊
  +     process.env.NODE_ENV === 'development' && eslint(),␊
  +     airbnbBase({␊
  +       eslint: {␊
  +         baseConfig: {␊
  +           rules: {␊
  +             semi: 'off',␊
  +           },␊
  +         },␊
  +       },␊
  +     }),␊
  +     node(),␊
  +     process.env.NODE_ENV === 'test' && jest({␊
  +       testRegex: '(/__tests__/.*|(\\\\.|/)(test|spec))\\\\.(jsx?|tsx?)$',␊
  +     }),␊
  +     (neutrino) => {␊
  +       neutrino.config.externals(/^[a-z\\-0-9]+$/);␊
  +       neutrino.use(fakePreset({ alpha: 'beta' }));␊
  +     },␊
  +   ],␊
    };`

  `--fail-fast` is on. 5 test files were skipped.

error Command failed with exit code 1.

I believe this happens due to Git auto conversion of line endings (Git client feature) during cloning and commit. But I may be wrong. Any ideas how to fix this?

edmorley commented 4 years ago

https://stackoverflow.com/questions/2517190/how-do-i-force-git-to-use-lf-instead-of-crlf-under-windows

constgen commented 4 years ago

May be (I am not sure) it will fix it in my personal environment. But it will not save other developers from this issue. The good practice is to keep everything always in LF. But I have no idea where CRLF are generated from. What is also interesting that the half of the generated file is LF and the another half is CRLF

Another option: do you think we can apply local Git configs and commit them to the repository?

edmorley commented 4 years ago

Yeah the SO link has suggestions for how to set up a .gitattributes file, which gets committed to the repo and tells git to ignore the global settings the user might have and check out the code with the desired line endings.

constgen commented 4 years ago

Turned out the issue comes from absolutely another side https://github.com/facebook/jscodeshift/issues/195 . Recast (the nested dependency) automatically chooses OS end of line for code generation.

I tried --printOptions='{"lineTerminator":"\n"}' in the test. And the problem is that even with the flag the generated output is not affected. Actually no of known printOptions affect anything. Seems like they are not applied at all. They say they resolved this issue but I can still reproduce ignoring of printOptions in CLI

Have no idea how to make it work. The only options are to redesign the test or disable testing on commit as they block. PRs will be still tested on CI