Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

chore(tests): fail tests on console output #453

Merged
merged 12 commits into from
Nov 28, 2018
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 ]------------------------------- -->
## [v0.12.1](https://github.com/stardust-ui/react/tree/v0.12.1) (2018-11-26)
Expand Down
4 changes: 3 additions & 1 deletion build/gulp/tasks/test-unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const commonConfig = require('./test/jest.config.common')

module.exports = commonConfig
25 changes: 1 addition & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down Expand Up @@ -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": "<rootDir>/test/setup.ts",
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
"moduleNameMapper": {
"docs/(.*)$": "<rootDir>/docs/$1",
"src/(.*)$": "<rootDir>/src/$1",
"test/(.*)$": "<rootDir>/test/$1"
}
},
"dependencies": {
"classnames": "^2.2.5",
"fela": "^6.1.7",
Expand Down
7 changes: 6 additions & 1 deletion src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,13 @@ class Input extends AutoControlledComponent<Extendable<InputProps>, 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,
Expand Down
23 changes: 23 additions & 0 deletions test/jest.config.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kuzhelov not sure how much these things are related, but is this the place where we specify how the files in test directory are compiled? ts-jest vs typescript compiler? more details in #445

Copy link
Contributor Author

@kuzhelov kuzhelov Nov 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, you are partially right, but let me provide full story behind that.

Currently ts-jest tool is responsible for transpiling jest tests before they will run - and this fact is stated by value of transform option of Jest config file. Thus, to run the tests we don't need to do any transpilation ourselves for test files as long as this tool is used for making necessary transform. Another thing to note is that ts-jest doesn't produce any (visible) transpilation artifacts - in contrast to the process that is used to compile sources.

For source files, in contrast, tsconfig.json file is in charge of defining how and which files should be transpiled.

Answering on your question - while, yes, transform option serves to suggest Jest that ts-jest should be used for making transform, there is no was to specify directly there that 'raw' TS compiler (without being wrapped as a plugin) should be used. If we would like to use raw TS compiler, we would need to make test process consisting of two steps:

  • transpile test files and store them
  • run tests for transpiled (JS) test files

To my mind this move would definitely complicate things, but let me first take a look on the issue to obtain more details on why this move might be necessary

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`
}
}
6 changes: 6 additions & 0 deletions test/jest.config.strict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const commonConfig = require('./jest.config.common')

module.exports = Object.assign({},
commonConfig,
{ setupTestFrameworkScriptFile: `${__dirname}/setup.strict.ts` }
)
File renamed without changes.
17 changes: 17 additions & 0 deletions test/setup.strict.ts
Original file line number Diff line number Diff line change
@@ -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')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 very nicely done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to confess that those changes are mine, but this is not the case :) actually, the approach of using spies for console methods was already introduced before and just have been removed from sources for a while

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()
})