Skip to content

Commit

Permalink
feat: 添加部分react 测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
yinpeng.wyp committed May 20, 2021
1 parent bd311b0 commit 3e3ac75
Show file tree
Hide file tree
Showing 23 changed files with 14,027 additions and 16 deletions.
File renamed without changes.
12 changes: 12 additions & 0 deletions cdn-plugin-bug/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
File renamed without changes.
38 changes: 38 additions & 0 deletions cdn-plugin-bug/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "react-webpack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack serve --config webpack.dev.config.js",
"build": "webpack"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.0.1",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.2",
"eslint": "^5.5.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-html": "^4.0.5",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"html-webpack-plugin": "^5.2.0",
"webpack": "^5.24.3",
"webpack-cdn-plugin": "^3.3.1",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.1.8",
"webpack-merge": "^4.1.4"
},
"dependencies": {
"axios": "^0.21.1",
"react": "^16.5.0",
"react-dom": "^16.5.0",
"react-router-dom": "^5.2.0"
}
}
File renamed without changes.
20 changes: 20 additions & 0 deletions cdn-plugin-bug/src/PageB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
function PageB() {
const [ip, setIP] =useState('')
import('axios').then(module=>{
module.default.get('https://hanma.alibaba-inc.com/oapi/util/get_internal_ip').then(res=>{
console.log(res)
setIP(res.data.data.ip)
})
})
return (
<div className="PageB">
PageB
ip: {ip}

</div>
);
}

export default PageB;
39 changes: 39 additions & 0 deletions cdn-plugin-bug/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import ReactDOM from 'react-dom';

import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom'
import App from './App.jsx';
import PageB from './PageB'

ReactDOM.render(
<Router>
<div>
<nav>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/pageB">pageB</Link>
</li>
</ul>
</nav>

{/* A <Switch> looks through its children <Route>s and
renders the first one that matches the current URL. */}
<Switch>
<Route path="/pageB">
<PageB />
</Route>
<Route path="/">
<App />
</Route>
</Switch>
</div>
</Router>,
document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
41 changes: 41 additions & 0 deletions cdn-plugin-bug/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackCdnPlugin = require('webpack-cdn-plugin');

module.exports = {
mode:'production',
output: {
path: path.resolve(__dirname, './dist'),
filename: 'main.js',
},
module: {
rules: [
{
test: /.jsx?$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react']
}
}
}
]
},
plugins:[
new HtmlWebpackPlugin(
{
filename: 'index.html',
template: './index.html',
}
),
new WebpackCdnPlugin(
{
optimize: true,
modules: [
{ name: 'axios', var: 'axios', prodUrl: 'https://g.alicdn.com/code/lib/axios/0.21.1/axios.min.js' },
]
}
)
]
}
5 changes: 5 additions & 0 deletions cdn-plugin-bug/webpack.dev.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const merge = require('webpack-merge')
const webpackBase = require('./webpack.config')
module.exports = merge(webpackBase, {
mode: 'development',
})
1 change: 1 addition & 0 deletions node_modules/.package_versions.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions react-webpack-eslint-Jest-unitTest/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
"extends": "standard",
"plugins":["html", "react"],
"rules":{
// 解决react报错
"react/jsx-uses-react":2,
// 解决var App 报错
"react/jsx-uses-vars":2,
}
};
8 changes: 8 additions & 0 deletions react-webpack-eslint-Jest-unitTest/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {

presets: [['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-react',
// '@babel/preset-typescript',
],

};
File renamed without changes.
Loading

0 comments on commit 3e3ac75

Please sign in to comment.