Skip to content

Commit

Permalink
example(react-component-tsx): update test example.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 18, 2021
1 parent d16df8d commit a1baf45
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 41 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ jobs:

- name: example @template/react-component-tsx
working-directory: example/react-component-tsx
run: npm run build:lib && npm run doc
run: |
npm run build:lib
npm run doc
npm run test:coverage
# The following changes are being made to your tsconfig.json file:
# - compilerOptions.noEmit must be true
git checkout -f ./tsconfig.json
- name: example @template/rematch
working-directory: example/rematch
Expand Down
2 changes: 1 addition & 1 deletion example/react-component-tsx/.kktrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default (conf: Configuration, env: 'development' | 'production', options:
conf = rawModules(conf, env, { ...options });
conf = scopePluginOptions(conf, env, {
...options,
allowedFiles: [path.resolve(process.cwd(), 'README.md')],
allowedFiles: [path.resolve(process.cwd(), 'README.md'), path.resolve(process.cwd(), 'src')],
});
conf = lessModules(conf, env, options);
// Get the project version.
Expand Down
1 change: 1 addition & 0 deletions example/react-component-tsx/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120,
"endOfLine": "auto",
"overrides": [
{
"files": ".prettierrc",
Expand Down
12 changes: 8 additions & 4 deletions example/react-component-tsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
"build": "npm run build:lib && npm run doc",
"build:lib": "npm run ts:build && npm run types:esm && npm run types:cjs && npm run css:build && npm run css:build:dist",
"watch": "npm run ts:watch & npm run types:watch & npm run css:watch",
"types:build": "tsbb types --sourceRoot src --target ESNEXT",
"types:build": "tsbb types --sourceRoot src --target ESNEXT --jsx --emitDeclarationOnly false",
"types:watch": "npm run types:esm -- --watch & npm run types:cjs -- --watch",
"types:esm": "npm run types:build -- --outDir ../lib/esm",
"types:cjs": "npm run types:build -- --outDir ../lib/cjs",
"css:build": "compile-less -d src -o lib/esm",
"css:watch": "compile-less -d src -o lib/esm --watch",
"css:build:dist": "compile-less -d src --combine dist/index.css --rm-global",
"css:build:dist": "compile-less -d src --combine lib/dist.css --rm-global",
"ts:watch": "tsbb watch --env-name esm:dev --env-name cjs --target react",
"ts:build": "tsbb build --target react",
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\""
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
"test": "kkt test --env=jsdom --app-src=./website",
"test:coverage": "kkt test --env=jsdom --coverage --app-src=./website"
},
"repository": {
"type": "git",
Expand All @@ -35,7 +37,7 @@
},
"lint-staged": {
"*.{js,jsx,tsx,ts,less,md,json}": [
"prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\""
"prettier --write"
]
},
"peerDependencies": {
Expand All @@ -49,6 +51,7 @@
"@kkt/scope-plugin-options": "6.10.3",
"@types/react": "17.0.11",
"@types/react-dom": "17.0.7",
"@types/react-test-renderer": "17.0.1",
"@uiw/react-github-corners": "1.4.0",
"@uiw/react-markdown-preview": "3.1.1",
"compile-less-cli": "1.8.0",
Expand All @@ -58,6 +61,7 @@
"prettier": "2.3.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-test-renderer": "17.0.2",
"tsbb": "2.2.0"
},
"eslintConfig": {
Expand Down
13 changes: 13 additions & 0 deletions example/react-component-tsx/src/__test__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable jest/no-conditional-expect */
import TestRenderer from 'react-test-renderer';
import Button from '../';

it('Should output a button', async () => {
const component = TestRenderer.create(<Button type="primary">Primary</Button>);
let tree = component.toJSON();
if (tree && !Array.isArray(tree)) {
expect(tree.type).toEqual('button');
expect(tree.props.disabled).toBeFalsy();
expect(tree.props.className).toEqual('w-btn w-btn-default w-btn-primary');
}
});
21 changes: 4 additions & 17 deletions example/react-component-tsx/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
{
"extends": "../tsconfig",
"include": ["../src"],
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"declaration": true,
"baseUrl": ".",
"jsx": "react-jsx"
},
"include": ["../src"]
"baseUrl": "."
}
}
20 changes: 12 additions & 8 deletions example/react-component-tsx/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"sourceMap": false,
"target": "esnext",
"module": "esnext",
"lib": ["esnext", "dom"],
"moduleResolution": "node",
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"declaration": true,
"baseUrl": "./website",
"jsx": "react-jsx",
"noFallthroughCasesInSwitch": true,
"noEmit": true
"noUnusedLocals": true,
"experimentalDecorators": true,
"removeComments": false,
"types": ["jest", "node"],
"forceConsistentCasingInFileNames": true
},
"include": ["website", ".kktrc.ts"]
"include": ["src", "website", ".kktrc.ts"]
}
2 changes: 1 addition & 1 deletion example/react-component-tsx/website/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react';
import MarkdownPreview from '@uiw/react-markdown-preview';
import GitHubCorners from '@uiw/react-github-corners';
import logo from './logo.svg';
import './App.css';
import Button from '../';
import MDStr from '../README.md';
import './App.css';

const App: React.FC = () => {
return (
Expand Down
1 change: 0 additions & 1 deletion example/react-component-tsx/website/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

Expand Down
3 changes: 2 additions & 1 deletion example/rematch-hash-router/src/common/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const menuData = [
];

/* eslint no-useless-escape:0 */
const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/g;
const reg =
/(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/g;
function isUrl(path) {
return reg.test(path);
}
Expand Down
4 changes: 2 additions & 2 deletions example/rematch-tsx/src/models/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export type LoginState = {
};

export default createModel<RootModel>()({
state: ({
state: {
userData: null,
token: null,
} as unknown) as LoginState,
} as unknown as LoginState,
reducers: {
updateState: (state, payload: LoginState): LoginState => ({ ...state, ...payload }),
},
Expand Down
3 changes: 2 additions & 1 deletion example/rematch-uiw/src/common/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const menuData = [
];

/* eslint no-useless-escape:0 */
const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/g;
const reg =
/(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/g;
function isUrl(path) {
return reg.test(path);
}
Expand Down
3 changes: 2 additions & 1 deletion example/rematch/src/common/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const menuData = [
];

/* eslint no-useless-escape:0 */
const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/g;
const reg =
/(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/g;
function isUrl(path) {
return reg.test(path);
}
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@
}
},
"lint-staged": {
"*.{js,jsx,tsx,ts,less,md,json}": [
"prettier --write"
]
"*.{js,jsx,tsx,ts,less,md,json}": "prettier --write"
},
"devDependencies": {
"husky": "4.3.8",
Expand Down

0 comments on commit a1baf45

Please sign in to comment.