Skip to content

Commit

Permalink
Apply correct line endings to expected codemod outputs during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoStaudinger committed Jan 28, 2019
1 parent 024f77e commit 240f25c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"minimist": "^1.2.0",
"npmlog": "^4.1.2",
"plop": "^2.0.0",
"prettier": "^1.14.2",
"prettier": "^1.16.1",
"prettier-eslint": "^8.8.1",
"prop-types": "^15.6.1",
"raf": "^3.4.0",
Expand Down
24 changes: 22 additions & 2 deletions packages/react-codemods/transforms/pf3-pf4.button.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import { EOL as SYSTEM_EOL } from 'os';
import prettier from 'prettier';
import { defineInlineTest } from 'jscodeshift/dist/testUtils';
import transform from './pf3-pf4';

const prettierConfig = prettier.resolveConfig.sync(process.cwd());
const pretty = src => prettier.format(src, { parser: 'babylon', ...prettierConfig });
/**
* Codemod outputs should follow the EOL pattern of the target codebase, not
* Patternfly's. Patternfly currently enforces LF as line ending, independent of
* the OS building the codebase.
*
* JSCodeShift produces OS-dependent line endings however, LF for Unix based
* systems, and CRLF for Windows based ones. This is also likely what most
* projects would like to see the codemod prduce.
*
* To make sure we both adhere to Patternfly's conventions, and compare the
* correct OS-specific line endings during the test cases' assertions, we store
* expected values with LF line endings, and convert them into the OS-specific
* ones at runtime using prettier.
*/
const PRETTIER_EOL = SYSTEM_EOL === '\r\n' ? 'crlf' : 'cr';
const prettierConfig = {
...prettier.resolveConfig.sync(process.cwd()),
parser: 'babel',
endOfLine: PRETTIER_EOL
};
const pretty = src => prettier.format(src, prettierConfig);

global.console.log = jest.fn();

Expand Down
2 changes: 1 addition & 1 deletion packages/react-codemods/transforms/pf3-pf4.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ module.exports = (file, api, options) => {

return prettier
? prettier.format(transformedSource, {
parser: 'babylon',
parser: 'babel',
...prettier.resolveConfig.sync(process.cwd())
})
: transformedSource;
Expand Down
24 changes: 22 additions & 2 deletions packages/react-codemods/transforms/pf3-pf4.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import { EOL as SYSTEM_EOL } from 'os';
import prettier from 'prettier';
import { defineInlineTest, runInlineTest } from 'jscodeshift/dist/testUtils';
import transform from './pf3-pf4';

const prettierConfig = prettier.resolveConfig.sync(process.cwd());
const pretty = src => prettier.format(src, { parser: 'babylon', ...prettierConfig });
/**
* Codemod outputs should follow the EOL pattern of the target codebase, not
* Patternfly's. Patternfly currently enforces LF as line ending, independent of
* the OS building the codebase.
*
* JSCodeShift produces OS-dependent line endings however, LF for Unix based
* systems, and CRLF for Windows based ones. This is also likely what most
* projects would like to see the codemod prduce.
*
* To make sure we both adhere to Patternfly's conventions, and compare the
* correct OS-specific line endings during the test cases' assertions, we store
* expected values with LF line endings, and convert them into the OS-specific
* ones at runtime using prettier.
*/
const PRETTIER_EOL = SYSTEM_EOL === '\r\n' ? 'crlf' : 'cr';
const prettierConfig = {
...prettier.resolveConfig.sync(process.cwd()),
parser: 'babel',
endOfLine: PRETTIER_EOL
};
const pretty = src => prettier.format(src, prettierConfig);

global.console.log = jest.fn();

Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@
integrity sha512-4CHCw4Rit6xDpVytx1z0hH4+D9iKL/VJPkQnqkNm5bsKxSHr65boPLNv9IcJJZGb0XFYbJud7+yYxYIKdAJM8A==

"@patternfly/react-core@file:packages/patternfly-4/react-core":
version "1.49.0"
version "1.49.4"
dependencies:
"@patternfly/react-icons" "^2.10.0"
"@patternfly/react-styles" "^2.3.0"
Expand Down Expand Up @@ -18519,6 +18519,11 @@ prettier@^1.14.2:
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.14.2.tgz#0ac1c6e1a90baa22a62925f41963c841983282f9"
integrity sha512-McHPg0n1pIke+A/4VcaS2en+pTNjy4xF+Uuq86u/5dyDO59/TtFZtQ708QIRkEZ3qwKz3GVkVa6mpxK/CpB8Rg==

prettier@^1.16.1:
version "1.16.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.16.1.tgz#534c2c9d7853f8845e5e078384e71973bd74089f"
integrity sha512-XXUITwIkGb3CPJ2hforHah/zTINRyie5006Jd2HKy2qz7snEJXl0KLfsJZW/wst9g6R2rFvqba3VpNYdu1hDcA==

pretty-bytes@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-4.0.2.tgz#b2bf82e7350d65c6c33aa95aaa5a4f6327f61cd9"
Expand Down

0 comments on commit 240f25c

Please sign in to comment.