Skip to content

Commit

Permalink
feat: update project to typescript
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Update the entire project to Typescript
  • Loading branch information
jonyw4 committed Aug 17, 2020
1 parent 543ff7e commit 093bc1f
Show file tree
Hide file tree
Showing 51 changed files with 2,262 additions and 3,507 deletions.
10 changes: 0 additions & 10 deletions .babelrc

This file was deleted.

22 changes: 0 additions & 22 deletions .eslintrc.js

This file was deleted.

30 changes: 30 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
parser: '@typescript-eslint/parser'
env:
browser: true
node: true
es6: true
'jest/globals': true
parserOptions:
ecmaVersion: 2020
sourceType: "module"
ecmaFeatures:
jsx: true
settings:
react:
version: "detect"
extends:
- 'eslint:recommended'
- 'plugin:@typescript-eslint/recommended'
- 'prettier/@typescript-eslint'
- 'plugin:prettier/recommended'
- 'plugin:jest/recommended'
- 'plugin:react/recommended'
- 'plugin:react-hooks/recommended'
plugins:
- '@typescript-eslint'
- 'prettier'
- 'jest'
- 'react'
- 'react-hooks'
rules:
"react/no-children-prop": "off"
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"trailingComma": "none",
"printWidth": 80,
"singleQuote": true,
"tabWidth": 2
}
11 changes: 9 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
module.exports = {
coverageDirectory: 'coverage',
moduleFileExtensions: ['js', 'json', 'ts', 'tsx'],
preset: 'ts-jest',
rootDir: __dirname,
transform: {
'^.+\\.(t|j)s$': 'ts-jest'
},
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/__tests__/.eslintrc.js',
'<rootDir>/__tests__/.eslintrc.js'
],
testEnvironmentOptions: { resources: 'usable' },
testEnvironmentOptions: { resources: 'usable' }
};
63 changes: 30 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,42 @@
"author": "Jonathan Célio",
"license": "ISC",
"scripts": {
"lint": "eslint 'src/*'",
"lint": "eslint '*/**/*.{js,ts,tsx}' --quiet --fix",
"test:unit": "jest --collectCoverage",
"test": "jest --collectCoverage | codecov",
"build": "babel src -d dist"
},
"jest": {
"transform": {
"^.+\\.jsx?$": "babel-jest"
}
},
"dependencies": {
"colorthief": "^2.3.0",
"prop-types": "^15.7.2",
"react": "^16.12.0",
"react-dom": "^16.12.0"

"colorthief": "2.3.0",
"prop-types": "15.7.2",
"react": "16.12.0",
"react-dom": "16.12.0",
"use-current-effect": "^2.1.0"
},
"devDependencies": {
"codecov": "3.7.2",
"husky": "4.2.5",
"semantic-release": "17.1.1",
"@babel/cli": "7.10.5",
"@babel/core": "7.10.5",
"@babel/preset-env": "7.10.4",
"@babel/preset-react": "7.10.4",
"@commitlint/cli": "9.1.1",
"@commitlint/config-conventional": "9.1.1",
"@testing-library/react": "10.4.7",
"babel-eslint": "10.1.0",
"babel-jest": "26.1.0",
"@types/jest": "^26.0.10",
"@types/react": "^16.9.46",
"@types/react-dom": "^16.9.8",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"canvas": "2.6.1",
"codecov": "3.7.2",
"coveralls": "3.1.0",
"eslint": "7.5.0",
"eslint-config-airbnb": "18.2.0",
"eslint-plugin-import": "2.22.0",
"eslint-plugin-jest": "23.19.0",
"eslint-plugin-jsx-a11y": "6.3.1",
"eslint-plugin-react": "7.20.4",
"eslint-plugin-react-hooks": "4.0.8",
"jest": "26.1.0"
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-jest": "^23.20.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-hooks": "^4.0.8",
"husky": "4.2.5",
"jest": "26.1.0",
"prettier": "^2.0.5",
"semantic-release": "17.1.1",
"ts-jest": "^26.2.0",
"typescript": "^3.9.7"
},
"keywords": [
"color-thief-react",
Expand All @@ -57,17 +53,18 @@
],
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.{js,ts,tsx}": [
"eslint --fix"
]
},
"release": {
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"master",
{
"name": "beta",
"prerelease": true
}
"master"
]
},
"commitlint": {
Expand Down
144 changes: 144 additions & 0 deletions src/Color/Color.component.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import React from 'react';
import { render, act, waitFor } from '@testing-library/react';
import Color from './Color.component';

describe('Color', () => {
const src = 'https://homepages.cae.wisc.edu/~ece533/images/airplane.png';
const timeout = 15000;

test(
'should be a children with default format',
async () => {
const children = jest.fn(() => null);

await act(async () => {
render(<Color src={src} children={children} crossOrigin="Anonymous" />);
});

expect(children).toHaveBeenCalledWith({
loading: true,
error: undefined,
data: undefined
});

await waitFor(() => expect(children).toHaveBeenCalledTimes(2), {
timeout
});

expect(children).toHaveBeenCalledWith({
loading: false,
error: undefined,
data: 'rgb(199, 203, 205)'
});
},
timeout
);

test(
'should be a children with rgb array',
async () => {
const format = 'rgbArray';
const children = jest.fn(() => null);

await act(async () => {
render(
<Color
src={src}
format={format}
children={children}
crossOrigin="Anonymous"
/>
);
});

expect(children).toHaveBeenCalledWith({
loading: true,
error: undefined,
data: undefined
});

await waitFor(() => expect(children).toHaveBeenCalledTimes(2), {
timeout
});

expect(children).toHaveBeenCalledWith({
loading: false,
error: undefined,
data: [199, 203, 205]
});
},
timeout
);

test(
'should be a children with rgb string',
async () => {
const format = 'rgbString';
const children = jest.fn(() => null);

await act(async () => {
render(
<Color
src={src}
format={format}
children={children}
crossOrigin="Anonymous"
/>
);
});

expect(children).toHaveBeenCalledWith({
loading: true,
error: undefined,
data: undefined
});

await waitFor(() => expect(children).toHaveBeenCalledTimes(2), {
timeout
});

expect(children).toHaveBeenCalledWith({
loading: false,
error: undefined,
data: 'rgb(199, 203, 205)'
});
},
timeout
);

test(
'should be a children with hex',
async () => {
const format = 'hex';
const children = jest.fn(() => null);

await act(async () => {
render(
<Color
src={src}
format={format}
children={children}
crossOrigin="Anonymous"
/>
);
});

expect(children).toHaveBeenCalledWith({
loading: true,
error: undefined,
data: undefined
});

await waitFor(() => expect(children).toHaveBeenCalledTimes(2), {
timeout
});

expect(children).toHaveBeenCalledWith({
loading: false,
error: undefined,
data: '#c7cbcd'
});
},
timeout
);
});
37 changes: 37 additions & 0 deletions src/Color/Color.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import { ColorFormats } from 'types';
import useColor, { UseColorState } from './useColor';

function Color({
src,
format = 'rgbString',
crossOrigin = undefined,
quality = 10,
children
}: ColorProps): JSX.Element {
const state = useColor(src, format, { crossOrigin, quality });

return <>{children(state)}</>;
}

export type ColorProps = {
/**
* Link of the image
*/
src: string;
/**
* Format of the response.
*/
format?: ColorFormats;
/**
* Tag cross-origin for image
*/
crossOrigin?: string;
/**
* Quality determines how many pixels are skipped before the nex one is sampled.We rarely need to sample every single pixel in the image to get good results. The bigger the number, the faster a value will be returned. Read more in https://lokeshdhakar.com/projects/color-thief/
*/
quality?: number;
children: (state: UseColorState) => React.ReactNode;
};

export default Color;
26 changes: 0 additions & 26 deletions src/Color/getColor.js

This file was deleted.

Loading

0 comments on commit 093bc1f

Please sign in to comment.