Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(deps): update jest monorepo to v23 (major) #305

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

Merged
armandabric merged 3 commits into master from renovate/major-jest-monorepo
Jan 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@commitlint/config-angular": "7.3.1",
"babel-cli": "6.26.0",
"babel-eslint": "10.0.1",
"babel-jest": "22.2.2",
"babel-jest": "23.6.0",
"babel-preset-es2015": "6.24.1",
"babel-preset-flow": "6.23.0",
"babel-preset-react": "6.24.1",
Expand All @@ -57,11 +57,11 @@
"eslint-plugin-prettier": "3.0.1",
"eslint-plugin-react": "7.12.4",
"esm": "3.1.1",
"expect": "22.3.0",
"expect": "23.6.0",
"flow-bin": "0.91.0",
"flow-copy-source": "2.0.2",
"husky": "1.3.1",
"jest": "22.3.0",
"jest": "23.6.0",
"json": "9.0.6",
"lint-staged": "8.1.0",
"mversion": "1.12.0",
Expand Down
11 changes: 10 additions & 1 deletion src/formatter/formatFunction.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import type { Options } from './../options';

function noRefCheck() {}

const defaultFunctionValue = (fn: any): any => fn.toString();
export const inlineFunction = (fn: any): string =>
fn
.toString()
.split('\n')
.map(line => line.trim())
.join('');

export const preserveFunctionLineBreak = (fn: any): string => fn.toString();

const defaultFunctionValue = inlineFunction;

export default (fn: Function, options: Options): string => {
const { functionValue = defaultFunctionValue, showFunctions } = options;
Expand Down
7 changes: 3 additions & 4 deletions src/formatter/formatFunction.spec.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ describe('formatFunction', () => {
});

it('should format a function if showFunctions is true', () => {
expect(formatFunction(hello, { showFunctions: true }))
.toEqual(`function hello() {
return 1;
}`);
expect(formatFunction(hello, { showFunctions: true })).toEqual(
'function hello() {return 1;}'
);
});

it('should format a function without name if showFunctions is true', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ const reactElementToJsxString = (
};

export default reactElementToJsxString;

export {
inlineFunction,
preserveFunctionLineBreak,
} from './formatter/formatFunction';
22 changes: 17 additions & 5 deletions src/index.spec.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import React, { Fragment, Component } from 'react';
import { createRenderer } from 'react-test-renderer/shallow';
import { mount } from 'enzyme';
import reactElementToJSXString from './index';
import reactElementToJSXString, { preserveFunctionLineBreak } from './index';
import AnonymousStatelessComponent from './AnonymousStatelessComponent';

class TestComponent extends React.Component {}
Expand Down Expand Up @@ -889,13 +889,25 @@ describe('reactElementToJSXString(ReactElement)', () => {
reactElementToJSXString(<div fn={fn} />, {
showFunctions: true,
})
).toEqual(
`<div
).toEqual(`<div fn={function fn() {return 'value';}} />`);
});

it('should expose the multiline "functionValue" formatter', () => {
/* eslint-disable arrow-body-style */
const fn = () => {
return 'value';
};

expect(
reactElementToJSXString(<div fn={fn} />, {
showFunctions: true,
functionValue: preserveFunctionLineBreak,
})
).toEqual(`<div
fn={function fn() {
return 'value';
}}
/>`
);
/>`);
});

it('reactElementToJSXString(<DisplayNamePrecedence />)', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/smoke/smoke.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const requireReactElementToJsxString = buildType => {
if (buildType === 'esm') {
return require(`./../../dist/esm`).default;
} else if (buildType === 'cjs') {
return require('./../../dist/cjs');
return require('./../../dist/cjs').default;
}

throw new Error(`Unknown build type: "${buildType}"`);
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /