Skip to content

Commit

Permalink
Merge branch 'testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
bgonp committed Apr 8, 2021
2 parents d60ca57 + ad79a2f commit c88404e
Show file tree
Hide file tree
Showing 48 changed files with 8,026 additions and 6,600 deletions.
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": ["@babel/preset-env"],
"plugins": [
"babel-plugin-transform-vite-meta-env",
["module-resolver", { "root": ["./src"] }],
["inline-dotenv", { "path": ".env.test", "unsafe": true }]
]
}
42 changes: 42 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"env": {
"browser": true,
"es2021": true,
"jest": true
},
"extends": [
"plugin:react/recommended",
"standard"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"react",
"react-hooks",
"jest"
],
"rules": {
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "never"
}],
"max-len": ["error", { "code": 90 }],
"no-console": ["warn", { "allow": ["error"] }],
"react/react-in-jsx-scope": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
},
"settings": {
"react": {
"version": "detect"
}
}
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.vscode
*.local
.env.*
dist
dist-ssr
node_modules
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm test
65 changes: 65 additions & 0 deletions __tests__/utils/randomNumbers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { getRandomNumbersFactory } from 'utils/randomNumbers'

describe('getRandomNumbersFactory', () => {
test('should return a numbers factory', () => {
const getNumbers = getRandomNumbersFactory()
expect(typeof getNumbers).toBe('function')
})

test('should return an array of one number', () => {
const getNumbers = getRandomNumbersFactory()
const numbers = getNumbers()
expect(Array.isArray(numbers)).toBe(true)
})

test('should return a single random number', () => {
const getNumbers = getRandomNumbersFactory()
const numbers = getNumbers()
expect(numbers.length).toBe(1)
expect(numbers[0]).toBeGreaterThanOrEqual(0)
expect(numbers[0]).toBeLessThanOrEqual(1000)
})

test('should return array with exact length', () => {
const getNumbers = getRandomNumbersFactory(10, 10)
const numbers = getNumbers()
expect(numbers).toHaveLength(10)
})

test('should return array of different numbers', () => {
const getNumbers = getRandomNumbersFactory(100, 100)
const numbers = getNumbers()
const withoutRepeated = numbers.reduce(
(acc, number) => acc.includes(number) ? acc : acc.concat(number),
[]
)
expect(numbers.length).toBeGreaterThanOrEqual(withoutRepeated.length)
})

test('should return numbers between bounds', () => {
const getNumbers = getRandomNumbersFactory(1000, 1000, [[10, 100]])
const numbers = getNumbers()
expect(numbers.filter(number => number < 10 || number > 100)).toHaveLength(0)
})

test('should return numbers between several bounds', () => {
const getNumbers = getRandomNumbersFactory(1000, 1000, [[10, 10], [100, 100]])
const numbers = getNumbers()
expect(numbers.includes(10)).toBe(true)
expect(numbers.includes(100)).toBe(true)
})

test('should return different numbers each time', () => {
const getNumbers = getRandomNumbersFactory(1, 1, [[1, 1000]])
const numbers1 = getNumbers()
const numbers2 = getNumbers()
expect(numbers1[0]).not.toBe(numbers2[0])
})

test('should return arrays with different length each time', () => {
const getNumbers = getRandomNumbersFactory(1, 1000, [[10, 100]])
const numbers1 = getNumbers()
const numbers2 = getNumbers()
expect(numbers1.length).not.toBe(numbers2.length)
})
})
15 changes: 15 additions & 0 deletions __tests__/utils/twoDigits.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { twoDigits } from 'utils/twoDigits'

describe('twoDigits', () => {
test('should return same number as string', () => {
expect(twoDigits(10)).toBe('10')
})

test('should return number with left 0', () => {
expect(twoDigits(5)).toBe('05')
})

test('should return last two digits', () => {
expect(twoDigits(123)).toBe('23')
})
})
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
transform: {
'^.+\\.jsx?$': 'babel-jest',
},
}
5 changes: 5 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"baseUrl": "src",
}
}
Loading

1 comment on commit c88404e

@vercel
Copy link

@vercel vercel bot commented on c88404e Apr 8, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.