prettier-package-json
prettier-package-json copied to clipboard
invalid JSON test failing on main branch
Problem
invalid JSON test failing on main
Steps to recreate
- Run
yarn test
Additional notes
I wanted to make this issue because I also experienced this issue while trying to work on this library.
Originally posted by @brc-dd in https://github.com/cameronhunter/prettier-package-json/issues/44#issuecomment-893584691
@cameronhunter Actually I had linked a fix above can you check that if it's fine or not (for me it was working fine, and also working with your existing snapshot)? Also, one of your tests (invalid JSON one) is failing on your
main
branch itself. Here are the logs:➜ yarn test yarn run v1.22.5 $ jest PASS tests/script-order.test.ts PASS tests/use-tabs.test.ts PASS tests/tab-width.test.ts PASS tests/sort-contributors.test.ts PASS tests/sort-files.test.ts PASS tests/key-order.test.ts FAIL tests/command-line.test.ts (6.573 s) ● prettier-package-json --list-different tests\__fixtures__\invalid.json expect(received).toMatch(expected) Expected pattern: /tests\/__fixtures__\/invalid\.json: Unexpected token t in JSON at position 6/ Received string: "SyntaxError: tests/__fixtures__/invalid.json: Unexpected token t in JSON at position 7 at JSON.parse (<anonymous>) at Object._readFile (C:\\Users\\brc-dd\\Desktop\\prettier-package-json\\node_modules\\jsonfile\\index.js:25:16) at async check (C:\\Users\\brc-dd\\Desktop\\prettier-package-json\\bin\\prettier-package-json:91:18) at async Promise.all (index 0) " 29 | expect(result.exitCode).toBe(1); 30 | expect(result.stdout).toBe(''); > 31 | expect(result.stderr).toMatch(/tests\/__fixtures__\/invalid\.json: Unexpected token t in JSON at position 6/); | ^ 32 | }); 33 | at tests/command-line.test.ts:31:25 › 7 snapshots written. › 7 snapshots obsolete. • prettier-package-json --config tests/__fixtures__/prettier-package-json.config.js tests/__fixtures__/package-1.json 1 • prettier-package-json --list-different tests/__fixtures__/missing.json 1 • prettier-package-json --list-different tests/__fixtures__/package-*.json 1 • prettier-package-json --tab-width 8 tests/__fixtures__/package-1.json 1 • prettier-package-json --use-tabs tests/__fixtures__/package-1.json 1 • prettier-package-json tests/__fixtures__/package-*.json 1 • prettier-package-json tests/__fixtures__/package-1.json 1 Snapshot Summary › 7 snapshots written from 1 test suite. › 7 snapshots obsolete from 1 test suite. To remove them all, run `yarn test -u`. ↳ tests/command-line.test.ts • prettier-package-json --config tests/__fixtures__/prettier-package-json.config.js tests/__fixtures__/package-1.json 1 • prettier-package-json --list-different tests/__fixtures__/missing.json 1 • prettier-package-json --list-different tests/__fixtures__/package-*.json 1 • prettier-package-json --tab-width 8 tests/__fixtures__/package-1.json 1 • prettier-package-json --use-tabs tests/__fixtures__/package-1.json 1 • prettier-package-json tests/__fixtures__/package-*.json 1 • prettier-package-json tests/__fixtures__/package-1.json 1 Test Suites: 1 failed, 6 passed, 7 total Tests: 1 failed, 24 passed, 25 total Snapshots: 7 obsolete, 7 written, 17 passed, 24 total Time: 19.69 s, estimated 20 s Ran all test suites. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Actually it is an issue with line endings (CRLF counts as 2 characters, hence the position 7 instead of 6). Just tried it on a Linux environment, it works fine. Can be fixed in the repo by adding .gitattributes
file. An .editorconfig
can also be added alongside.
I've cherry-picked the .gitattributes
change and pushed it to main in 83cd69f288f3054070119938f0594fbab2c9ffe0