diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..c10f9d15 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,37 @@ +version: 2 +jobs: + lint: + docker: + - image: circleci/node:latest + steps: + - checkout + - restore_cache: + keys: + - v1-dependencies-{{ checksum "package.json" }} + - run: npm install + - save_cache: + paths: + - node_modules + key: v1-dependencies-{{ checksum "package.json" }} + - run: npm run lint + test: + docker: + - image: circleci/node:latest + working_directory: ~/repo + steps: + - checkout + - restore_cache: + keys: + - v1-dependencies-{{ checksum "package.json" }} + - run: npm install + - save_cache: + paths: + - node_modules + key: v1-dependencies-{{ checksum "package.json" }} + - run: npm test -- --coverage && bash <(curl -s https://codecov.io/bash) +workflows: + version: 2 + build_and_test: + jobs: + - lint + - test \ No newline at end of file diff --git a/.gitignore b/.gitignore index bb6f664e..1098b56c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .storybook .doc node_modules +coverage/ \ No newline at end of file diff --git a/now.json b/now.json index 136ba0e6..5419edd9 100644 --- a/now.json +++ b/now.json @@ -5,7 +5,7 @@ { "src": "package.json", "use": "@now/static-build", - "config": { "distDir": "build" } + "config": { "distDir": ".doc" } } ] } diff --git a/package.json b/package.json index 7f8fbc62..c7ab5dbf 100644 --- a/package.json +++ b/package.json @@ -33,26 +33,10 @@ "gh-pages": "rc-tools run gh-pages", "start1": "rc-tools run storybook", "pub": "rc-tools run pub --babel-runtime", - "lint": "rc-tools run lint", - "lint:fix": "rc-tools run lint --fix", - "test": "jest", - "coverage": "jest --coverage", + "lint": "eslint src/**/*", + "test": "father test", "now-build": "npm run build" }, - "jest": { - "setupFiles": [ - "./tests/setup.js" - ], - "collectCoverageFrom": [ - "src/**/*" - ], - "snapshotSerializers": [ - "enzyme-to-json/serializer" - ], - "transform": { - "\\.jsx?$": "./node_modules/rc-tools/scripts/jestPreprocessor.js" - } - }, "peerDependencies": { "react": "*" }, @@ -62,8 +46,7 @@ "enzyme": "^3.1.0", "enzyme-adapter-react-16": "^1.0.2", "enzyme-to-json": "^3.1.4", - "father": "^2.6.2", - "jest": "^21.2.1", + "father": "^2.6.4", "react": "^16.8.6", "react-dom": "^16.8.6", "react-redux": "^4.4.10", diff --git a/src/utils/NameMap.ts b/src/utils/NameMap.ts index 85b5b02f..dc2e7484 100644 --- a/src/utils/NameMap.ts +++ b/src/utils/NameMap.ts @@ -10,7 +10,7 @@ interface KV { * NameMap like a `Map` but accepts `string[]` as key. */ class NameMap { - private list: Array> = []; + private list: KV[] = []; public clone(): NameMap { const clone = new NameMap(); @@ -61,7 +61,7 @@ class NameMap { return null; }); - return json; + return json; } } diff --git a/src/utils/asyncUtil.ts b/src/utils/asyncUtil.ts index 83cd91e5..661b705d 100644 --- a/src/utils/asyncUtil.ts +++ b/src/utils/asyncUtil.ts @@ -1,4 +1,4 @@ -export function allPromiseFinish(promiseList: Array>) { +export function allPromiseFinish(promiseList: Promise[]) { let hasError = false; let count = promiseList.length; const results: any[] = []; @@ -6,22 +6,23 @@ export function allPromiseFinish(promiseList: Array>) { return new Promise((resolve, reject) => { promiseList.forEach((promise, index) => { promise - .catch((e) => { - hasError = true; - return e; - }).then((result) => { - count -= 1; - results[index] = result; + .catch(e => { + hasError = true; + return e; + }) + .then(result => { + count -= 1; + results[index] = result; - if (count !== 0) { - return; - } + if (count !== 0) { + return; + } - if (hasError) { - reject(results); - } - resolve(results); - }); + if (hasError) { + reject(results); + } + resolve(results); + }); }); }); } diff --git a/src/utils/valueUtil.ts b/src/utils/valueUtil.ts index b83f0bf3..01f4efe2 100644 --- a/src/utils/valueUtil.ts +++ b/src/utils/valueUtil.ts @@ -10,7 +10,7 @@ import { toArray } from './typeUtil'; * 123 => [123] * ['a', 123] => ['a', 123] */ -export function getNamePath(path: NamePath | null): Array { +export function getNamePath(path: NamePath | null): (string | number)[] { return toArray(path); } diff --git a/tests/index.test.js b/tests/index.test.js new file mode 100644 index 00000000..bf995e1a --- /dev/null +++ b/tests/index.test.js @@ -0,0 +1,10 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import Form from '../src'; + +describe('Basic', () => { + it('create form', () => { + const wrapper = mount(
); + expect(wrapper.find('form')).toBeTruthy(); + }); +});