Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Tests fail because of CRLF-LF #1628

Closed
constgen opened this issue Sep 30, 2020 · 4 comments · Fixed by #1629
Closed

Tests fail because of CRLF-LF #1628

constgen opened this issue Sep 30, 2020 · 4 comments · Fixed by #1629

Comments

@constgen
Copy link
Contributor

Bug

  • Nutrino 9
  • Yarn v1
  • Node v12.14.1
  • Windows 10
  • Clone, Install and run test on the repository
  • Expected: all test should pass as the only stable code is commited
  • Actual: tests fail

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?

@constgen
Copy link
Contributor Author

constgen commented Sep 30, 2020

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

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
Copy link
Contributor Author

constgen commented Oct 1, 2020

Turned out the issue comes from absolutely another side facebook/jscodeshift#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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
2 participants