From 9daf19cd1c6e56d025920b90bb870e101edd69c0 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Thu, 8 Nov 2018 17:58:51 +0300 Subject: [PATCH 1/5] fail tests on console output --- build/gulp/tasks/test-unit.ts | 4 +++- jest.config.js | 3 +++ package.json | 25 +------------------------ test/jest.config.common.js | 23 +++++++++++++++++++++++ test/jest.config.strict.js | 6 ++++++ test/{setup.ts => setup.common.ts} | 0 test/setup.strict.ts | 17 +++++++++++++++++ 7 files changed, 53 insertions(+), 25 deletions(-) create mode 100644 jest.config.js create mode 100644 test/jest.config.common.js create mode 100644 test/jest.config.strict.js rename test/{setup.ts => setup.common.ts} (100%) create mode 100644 test/setup.strict.ts diff --git a/build/gulp/tasks/test-unit.ts b/build/gulp/tasks/test-unit.ts index bfc2e28c3c..8b04106d74 100644 --- a/build/gulp/tasks/test-unit.ts +++ b/build/gulp/tasks/test-unit.ts @@ -9,10 +9,12 @@ import sh from '../sh' const jest = ({ watch = false } = {}) => cb => { process.env.NODE_ENV = 'test' + const jestConfigFileName = `jest.config.${argv.strict ? 'strict' : 'common'}.js` + // in watch mode jest never exits // let the gulp task complete to prevent blocking subsequent tasks const command = [ - 'jest --coverage', + `jest --config ./test/${jestConfigFileName} --coverage`, watch && '--watchAll', argv.runInBand && '--runInBand', argv.maxWorkers && `--maxWorkers=${argv.maxWorkers}`, diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000000..0725dd6398 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,3 @@ +const commonConfig = require('./test/jest.config.common') + +module.exports = commonConfig diff --git a/package.json b/package.json index 6bb1aa099a..2d8dc5b305 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "build": "gulp build", "build:docs": "gulp --series dll build:docs", "build:dist": "gulp --series dll build:dist", - "ci": "yarn lint && yarn prettier && yarn test", + "ci": "yarn lint && yarn prettier && yarn test --strict", "predeploy:docs": "cross-env NODE_ENV=production yarn build:docs", "deploy:docs": "gulp deploy:docs", "lint": "tslint -t stylish -p .", @@ -56,29 +56,6 @@ "url": "https://github.com/stardust-ui/react/issues" }, "homepage": "https://github.com/stardust-ui/react#readme", - "jest": { - "coverageDirectory": "./coverage/", - "coverageReporters": [ - "json", - "lcov" - ], - "testRegex": "/test/.*-test\\.tsx?$", - "moduleFileExtensions": [ - "ts", - "tsx", - "js", - "json" - ], - "setupTestFrameworkScriptFile": "/test/setup.ts", - "transform": { - "^.+\\.(ts|tsx)$": "ts-jest" - }, - "moduleNameMapper": { - "docs/(.*)$": "/docs/$1", - "src/(.*)$": "/src/$1", - "test/(.*)$": "/test/$1" - } - }, "dependencies": { "classnames": "^2.2.5", "faker": "^4.1.0", diff --git a/test/jest.config.common.js b/test/jest.config.common.js new file mode 100644 index 0000000000..89cfcabae1 --- /dev/null +++ b/test/jest.config.common.js @@ -0,0 +1,23 @@ +module.exports = { + coverageDirectory: "./coverage/", + coverageReporters: [ + 'json', + 'lcov' + ], + testRegex: '/test/.*-test\\.tsx?$', + moduleFileExtensions: [ + 'ts', + 'tsx', + 'js', + 'json' + ], + setupTestFrameworkScriptFile: `${__dirname}/setup.common.ts`, + transform: { + '^.+\\.(ts|tsx)$': 'ts-jest' + }, + moduleNameMapper: { + 'docs/(.*)$': `${__dirname}/../docs/$1`, + 'src/(.*)$': `${__dirname}/../src/$1`, + 'test/(.*)$': `${__dirname}/../test/$1` + } +} diff --git a/test/jest.config.strict.js b/test/jest.config.strict.js new file mode 100644 index 0000000000..e80c3d6512 --- /dev/null +++ b/test/jest.config.strict.js @@ -0,0 +1,6 @@ +const commonConfig = require('./jest.config.common') + +module.exports = Object.assign({}, + commonConfig, + { setupTestFrameworkScriptFile: `${__dirname}/setup.strict.ts` } +) diff --git a/test/setup.ts b/test/setup.common.ts similarity index 100% rename from test/setup.ts rename to test/setup.common.ts diff --git a/test/setup.strict.ts b/test/setup.strict.ts new file mode 100644 index 0000000000..734602f89f --- /dev/null +++ b/test/setup.strict.ts @@ -0,0 +1,17 @@ +/** + * Setup (Strict) + * This is the bootstrap code that is run before any tests, utils, mocks in 'strict' mode. + */ +require('./setup.common') + +jest.spyOn(console, 'log') +jest.spyOn(console, 'info') +jest.spyOn(console, 'warn') +jest.spyOn(console, 'error') + +afterAll(() => { + expect(console.log).not.toHaveBeenCalled() + expect(console.info).not.toHaveBeenCalled() + expect(console.warn).not.toHaveBeenCalled() + expect(console.error).not.toHaveBeenCalled() +}) From 8b488255bfdea85bb9d096d7b196a128886abc42 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Thu, 8 Nov 2018 18:17:29 +0300 Subject: [PATCH 2/5] add strict flag for tests on circle CI --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bb5725229a..52daa0950f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -45,7 +45,7 @@ jobs: command: yarn prettier - run: name: Unit Tests - command: yarn test --maxWorkers=4 + command: yarn test --strict --maxWorkers=4 - run: name: Report coverage command: bash <(curl -s https://codecov.io/bash) From c14500f069f36c9174789ab2ab47b618b7004e99 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 19 Nov 2018 14:25:37 +0300 Subject: [PATCH 3/5] remove `listRef` prop from List --- src/components/List/List.tsx | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/components/List/List.tsx b/src/components/List/List.tsx index 58b22c7502..55d7007a24 100644 --- a/src/components/List/List.tsx +++ b/src/components/List/List.tsx @@ -26,9 +26,6 @@ export interface ListProps extends UIComponentProps, ChildrenComponent /** Shorthand array of props for ListItem. */ items?: ShorthandValue[] - /** Ref callback with the list DOM node. */ - listRef?: (node: HTMLElement) => void - /** A selection list formats list items as possible choices. */ selection?: boolean @@ -70,7 +67,6 @@ class List extends UIComponent, ListState> { selection: PropTypes.bool, truncateContent: PropTypes.bool, truncateHeader: PropTypes.bool, - listRef: PropTypes.func, renderItem: PropTypes.func, } @@ -91,10 +87,6 @@ class List extends UIComponent, ListState> { private focusHandler: ContainerFocusHandler = null private itemRefs = [] - private handleListRef = (listNode: HTMLElement) => { - _.invoke(this.props, 'listRef', listNode) - } - actionHandlers: AccessibilityActionHandlers = { moveNext: e => { e.preventDefault() @@ -123,7 +115,6 @@ class List extends UIComponent, ListState> { {...accessibility.keyHandlers.root} {...rest} className={classes.root} - ref={this.handleListRef} > {childrenExist(children) ? children : this.renderItems()} From bbfc19bfd516f72405d43f68fd8c70a3f635bd62 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Wed, 28 Nov 2018 23:31:32 +0100 Subject: [PATCH 4/5] fix Input's logic - do not blindly pass 'styles' prop --- src/components/Input/Input.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/Input/Input.tsx b/src/components/Input/Input.tsx index f322d0feef..338a57121d 100644 --- a/src/components/Input/Input.tsx +++ b/src/components/Input/Input.tsx @@ -181,8 +181,13 @@ class Input extends AutoControlledComponent, InputState> })} ), - styles: styles.root, ...rest, + + // do not pass Stardust 'styles' prop + // in case if React Element was used to define 'wrapper' + ...(!React.isValidElement(wrapper) && { + styles: styles.root, + }), }, overrideProps: { as: (wrapper && (wrapper as any).as) || ElementType, From e68a925343ac94b83d964294b0562018701a8c25 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Thu, 29 Nov 2018 00:38:29 +0100 Subject: [PATCH 5/5] update changelog --- CHANGELOG.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b11a0f3e62..805932d460 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +### Fixes +- Prevent blind props forwarding if `Input`'s wrapper is defined as React element @kuzhelov ([#453](https://github.com/stardust-ui/react/pull/453)) + ### Features - Add all default size Teams icons processed & ready to be consumed by Stardust as needed @codepretty ([#478](https://github.com/stardust-ui/react/pull/478)) - Add `Tree` Component @priyankar205 ([#479] @@ -27,13 +30,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm [Compare changes](https://github.com/stardust-ui/react/compare/v0.12.1...v0.13.0) ### BREAKING CHANGES -- rename `Transition` component to `Animation`, and `animationName` property to `name` @mnajdova ([#505](https://github.com/stardust-ui/react/pull/505)) +- Rename `Transition` component to `Animation`, and `animationName` property to `name` @mnajdova ([#505](https://github.com/stardust-ui/react/pull/505)) ### Fixes -- do not enforce yarn 1.10 via engines @Bugaa92 ([#531](https://github.com/stardust-ui/react/pull/531)) +- Do not enforce yarn 1.10 via engines @Bugaa92 ([#531](https://github.com/stardust-ui/react/pull/531)) ### Documentation -- add `Animations` guide as part of the `Theming` docs page @mnajdova ([#505](https://github.com/stardust-ui/react/pull/505)) +- Add `Animations` guide as part of the `Theming` docs page @mnajdova ([#505](https://github.com/stardust-ui/react/pull/505)) ## [v0.12.1](https://github.com/stardust-ui/react/tree/v0.12.1) (2018-11-26)