Added Example Component and testing framework

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2020-03-31 11:14:25 +02:00
parent 31692dfbd4
commit f5cdda822c
No known key found for this signature in database
GPG Key ID: B143FF27EF555D16
8 changed files with 94 additions and 30 deletions

View File

@ -5,3 +5,4 @@ out
next-env.d.ts
*.js
__tests__

View File

@ -0,0 +1,14 @@
import React from 'react'
import renderer from 'react-test-renderer'
import HelloWorld from '../../components/HelloWorld'
/**
* Example Test
*
* on first run it will generate a .snap file and after will compare result with it
*/
it('render a h1', () => {
const tree = renderer.create((<HelloWorld>Test</HelloWorld>)).toJSON()
expect(tree).toMatchSnapshot()
})

View File

@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`render a h1 1`] = `
<h1
className="jsx-3954099876"
>
Test
</h1>
`;

View File

20
components/HelloWorld.tsx Normal file
View File

@ -0,0 +1,20 @@
import React from 'react'
interface Props {
children: React.ReactNode
}
export default class HelloWorld extends React.Component<Props> {
public render() {
return (
<>
<h1>{this.props.children}</h1>
<style jsx>{`
h1
font-weight 700
`}</style>
</>
)
}
}

18
jest.config.js Normal file
View File

@ -0,0 +1,18 @@
module.exports = {
collectCoverageFrom: [
'**/*.{js,jsx,ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**',
],
testPathIgnorePatterns: ['/node_modules/', '/.next/'],
transform: {
'^.+\\.(js|jsx|ts|tsx)$': '<rootDir>/node_modules/babel-jest'
},
transformIgnorePatterns: [
'/node_modules/',
'^.+\\.module\\.(css|sass|scss)$',
],
moduleNameMapper: {
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
},
}

View File

@ -10,7 +10,8 @@
"serve": "serve out",
"prod:server": "yarn build && yarn server",
"prod:static": "yarn build && yarn export && yarn serve",
"lint": "eslint . --ext .ts,.tsx"
"lint": "eslint . --ext .ts,.tsx",
"test": "jest --config jext.config.js"
},
"dependencies": {
"@zeit/next-stylus": "^1.0.1",

View File

@ -1,31 +1,32 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"exclude": [
"node_modules",
"out"
],
"include": [
"next-env.d.ts",
"styl/stylus.d.ts",
"**/*.ts",
"**/*.tsx"
]
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"exclude": [
"node_modules",
"out",
"__tests__"
],
"include": [
"next-env.d.ts",
"styl/stylus.d.ts",
"**/*.ts",
"**/*.tsx"
]
}