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

Tests do not work on Windows due to CRLF issues. #467

Closed
jchv opened this issue Jan 3, 2018 · 1 comment
Closed

Tests do not work on Windows due to CRLF issues. #467

jchv opened this issue Jan 3, 2018 · 1 comment

Comments

@jchv
Copy link
Contributor

jchv commented Jan 3, 2018

Hello. Today, I tried to run Danger tests for the first time. My Git installation is very stock and has core.autocrlf set to true (as is default on Windows.)

These problems can reliably be resolved by switching off autocrlf like this:

git config core.autocrlf false
git rm --cached -r .
git reset --hard

The failures mainly seem to result from code that does not strip \r. Therefore errant \rs appear at the beginning of lines sometimes, causing diffs to mismatch.

The problem can be solved from two angles:

  1. Handling the carriage return more gracefully where possible. In this case, the bug is specifically from loading a fixture, not something that would ever come up in practice, but the test could be fixed to strip carriage returns.
  2. Forcing danger-js to always checkout as UNIX line-endings by specifying it should be so in the .gitattributes file:
    * text eol=lf
    

The latter would normalize things better across platforms, but personally seems like a bad idea.

The tests failed with the following results:

 FAIL  source\platforms\github\_tests\_github_git.test.ts
  ● the dangerfile gitDSL › sets the modified/created/deleted

    Error

      69 |   it("sets the modified/created/deleted", async () => {
      70 |     const gitJSONDSL = await github.getPlatformGitRepresentation()
    > 71 |     expect(gitJSONDSL.modified_files).toEqual([
      72 |       "CHANGELOG.md",
      73 |       "data/schema.graphql",
      74 |       "data/schema.json",
      Error: expect(received).toEqual(expected)

      Expected value to equal:
        ["CHANGELOG.md", "data/schema.graphql", "data/schema.json", "externals/metaphysics", "lib/__mocks__/react-relay.js", "lib/components/artist/about.js", "lib/components/gene/header.js", "lib/containers/__tests__/__snapshots__/gene-tests.js.snap", "lib/containers/__tests__/gene-tests.js", "lib/containers/gene.js", "tsconfig.json"]
      Received:
        ["CHANGELOG.md", "data/schema.graphql", "data/schema.json", "externals/metaphysics", "lib/__mocks__/react-relay.js", "lib/components/artist/", "lib/components/gene/biography.js", "lib/components/gene/header.js", "lib/components/related_artists/index.js", "lib/components/related_artists/related_artist.js", "lib/containers/__tests__/__snapshots__/gene-tests.js.snap", "lib/containers/__tests__/gene-tests.js", "lib/containers/gene.js", "tsconfig.json"]

      Difference:

      - Expected
      + Received

      @@ -3,11 +3,18 @@
          "data/schema.graphql",
          "data/schema.json",
          "externals/metaphysics",
          "lib/__mocks__/react-relay.js",
          "lib/components/artist/about.js",
      +   "/dev/null",
      +   "/dev/null",
      +   "lib/components/gene/about.js",
",    +   "lib/components/gene/about_gene.js
      +   "lib/components/gene/biography.js",
          "lib/components/gene/header.js",
      +   "lib/components/related_artists/index.js",
      +   "lib/components/related_artists/related_artist.js",
          "lib/containers/__tests__/__snapshots__/gene-tests.js.snap",
          "lib/containers/__tests__/gene-tests.js",
          "lib/containers/gene.js",
          "tsconfig.json",
        ]
      at Object.<anonymous> (source/platforms/github/_tests/_github_git.test.ts:71:47)
      at step (source/platforms/github/_tests/_github_git.test.ts:32:23)
      at Object.next (source/platforms/github/_tests/_github_git.test.ts:13:51)
      at fulfilled (source/platforms/github/_tests/_github_git.test.ts:4:56)

  ● the dangerfile gitDSL › textDiffForFile › returns a diff for modified files

    Error

      476 |       expect(diff.before).toEqual(before)
      477 |       expect(diff.after).toEqual(after)
    > 478 |       expect(diff.added).toEqual("+- GeneVC now shows about information, and trending artists - orta")
      479 |       expect(diff.removed).toEqual("")
      480 |       expect(diff.diff).toMatch(/GeneVC now shows about information, and trending artists/)
      481 |     })
      Error: expect(received).toEqual(expected)

      Expected value to equal:
        "+- GeneVC now shows about information, and trending artists - orta"
      Received:
"       "+- GeneVC now shows about information, and trending artists - orta
      at Object.<anonymous> (source/platforms/github/_tests/_github_git.test.ts:478:34)
      at step (source/platforms/github/_tests/_github_git.test.ts:32:23)
      at Object.next (source/platforms/github/_tests/_github_git.test.ts:13:51)
      at fulfilled (source/platforms/github/_tests/_github_git.test.ts:4:56)
Test Suites: 1 failed, 24 passed, 25 total
Tests:       2 failed, 210 passed, 212 total
Snapshots:   6 passed, 6 total
Time:        7.158s
Ran all test suites.
@orta
Copy link
Member

orta commented Jan 3, 2018

Merged - thanks @jchv

@orta orta closed this as completed Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants