From bbe7d59d6f0f1be11425a9c51e31309f47bf8dde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Allen=20Zhang=20=28=E5=BC=A0=E6=B6=9B=29?= Date: Mon, 4 Mar 2024 19:43:47 +0800 Subject: [PATCH] feat: add test --- examples/playwright-test/.gitignore | 3 + examples/playwright-test/main.js | 19 ++++++ examples/playwright-test/package.json | 15 +++++ examples/todomvc-react/.eslintrc | 13 ++++ examples/todomvc-react/.gitignore | 3 + examples/todomvc-react/babel.config.js | 3 + examples/todomvc-react/package.json | 42 ++++++++++++ examples/todomvc-react/public/index.html | 18 ++++++ examples/todomvc-react/src/index.js | 15 +++++ examples/todomvc-react/src/todo/app.css | 24 +++++++ examples/todomvc-react/src/todo/app.jsx | 20 ++++++ .../src/todo/components/footer.jsx | 43 +++++++++++++ .../src/todo/components/header.jsx | 15 +++++ .../src/todo/components/input.jsx | 49 ++++++++++++++ .../src/todo/components/item.jsx | 53 +++++++++++++++ .../src/todo/components/main.jsx | 45 +++++++++++++ examples/todomvc-react/src/todo/constants.js | 7 ++ examples/todomvc-react/src/todo/reducer.js | 64 +++++++++++++++++++ examples/todomvc-react/webpack.common.js | 43 +++++++++++++ examples/todomvc-react/webpack.dev.js | 18 ++++++ examples/todomvc-react/webpack.prod.js | 30 +++++++++ 21 files changed, 542 insertions(+) create mode 100644 examples/playwright-test/.gitignore create mode 100644 examples/playwright-test/main.js create mode 100644 examples/playwright-test/package.json create mode 100644 examples/todomvc-react/.eslintrc create mode 100644 examples/todomvc-react/.gitignore create mode 100644 examples/todomvc-react/babel.config.js create mode 100755 examples/todomvc-react/package.json create mode 100644 examples/todomvc-react/public/index.html create mode 100644 examples/todomvc-react/src/index.js create mode 100644 examples/todomvc-react/src/todo/app.css create mode 100644 examples/todomvc-react/src/todo/app.jsx create mode 100644 examples/todomvc-react/src/todo/components/footer.jsx create mode 100644 examples/todomvc-react/src/todo/components/header.jsx create mode 100644 examples/todomvc-react/src/todo/components/input.jsx create mode 100644 examples/todomvc-react/src/todo/components/item.jsx create mode 100644 examples/todomvc-react/src/todo/components/main.jsx create mode 100644 examples/todomvc-react/src/todo/constants.js create mode 100644 examples/todomvc-react/src/todo/reducer.js create mode 100644 examples/todomvc-react/webpack.common.js create mode 100644 examples/todomvc-react/webpack.dev.js create mode 100644 examples/todomvc-react/webpack.prod.js diff --git a/examples/playwright-test/.gitignore b/examples/playwright-test/.gitignore new file mode 100644 index 00000000..67f66f2e --- /dev/null +++ b/examples/playwright-test/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +/node_modules +package-lock.json diff --git a/examples/playwright-test/main.js b/examples/playwright-test/main.js new file mode 100644 index 00000000..80d50683 --- /dev/null +++ b/examples/playwright-test/main.js @@ -0,0 +1,19 @@ +const {chromium} = require('playwright'); +const main = async () => { + const browser = await chromium.launch() + const page = await browser.newPage(); + // 进入被测页面 + await page.goto('http://test.com') + // 执行测试用例 + // 用例1 + await page.click('button') + // 用例2 + await page.fill('input', 'test') + // 用例3 + await page.click('text=submit') + const coverage = await page.evaluate(`window.__coverage__`) + console.log(coverage) + browser.close() +} + +main() diff --git a/examples/playwright-test/package.json b/examples/playwright-test/package.json new file mode 100644 index 00000000..26f08bdf --- /dev/null +++ b/examples/playwright-test/package.json @@ -0,0 +1,15 @@ +{ + "name": "play-write", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "node ./main.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "playwright": "^1.42.1" + } +} diff --git a/examples/todomvc-react/.eslintrc b/examples/todomvc-react/.eslintrc new file mode 100644 index 00000000..0ce034b4 --- /dev/null +++ b/examples/todomvc-react/.eslintrc @@ -0,0 +1,13 @@ +{ + "extends": ["eslint:recommended", "plugin:react/recommended"], + "settings": { + "react": { + "version": "17.0.2" + } + }, + "rules": { + "no-extra-parens": 0, + "react/prop-types": 0, + "react/react-in-jsx-scope": 0 + } +} diff --git a/examples/todomvc-react/.gitignore b/examples/todomvc-react/.gitignore new file mode 100644 index 00000000..67f66f2e --- /dev/null +++ b/examples/todomvc-react/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +/node_modules +package-lock.json diff --git a/examples/todomvc-react/babel.config.js b/examples/todomvc-react/babel.config.js new file mode 100644 index 00000000..0d39533c --- /dev/null +++ b/examples/todomvc-react/babel.config.js @@ -0,0 +1,3 @@ +module.exports={ + plugins: ['istanbul'] +} diff --git a/examples/todomvc-react/package.json b/examples/todomvc-react/package.json new file mode 100755 index 00000000..14e8fad3 --- /dev/null +++ b/examples/todomvc-react/package.json @@ -0,0 +1,42 @@ +{ + "name": "todomvc-react", + "version": "1.0.0", + "description": "A TodoMVC written in React.", + "private": true, + "engines": { + "node": ">=18.13.0", + "npm": ">=8.19.3" + }, + "scripts": { + "build": "webpack --config webpack.prod.js", + "dev": "webpack serve --open --config webpack.dev.js", + "serve": "http-server ./dist -p 7002 -c-1 --cors", + "test": "jest" + }, + "devDependencies": { + "@babel/core": "^7.24.0", + "@babel/preset-env": "^7.24.0", + "@babel/preset-react": "^7.23.3", + "babel-loader": "^9.1.3", + "babel-plugin-istanbul": "^6.1.1", + "css-loader": "^6.10.0", + "css-minimizer-webpack-plugin": "^4.2.2", + "eslint-plugin-react": "^7.34.0", + "html-webpack-plugin": "^5.6.0", + "http-server": "^14.1.1", + "mini-css-extract-plugin": "^2.8.1", + "style-loader": "^3.3.4", + "webpack": "^5.90.3", + "webpack-cli": "^5.1.4", + "webpack-dev-server": "^4.15.1", + "webpack-merge": "^5.10.0" + }, + "dependencies": { + "classnames": "^2.5.1", + "react": "^17.0.2", + "react-dom": "^17.0.2", + "react-router-dom": "^6.22.2", + "todomvc-app-css": "^2.4.3", + "todomvc-common": "^1.0.5" + } +} diff --git a/examples/todomvc-react/public/index.html b/examples/todomvc-react/public/index.html new file mode 100644 index 00000000..ca4cc7a7 --- /dev/null +++ b/examples/todomvc-react/public/index.html @@ -0,0 +1,18 @@ + + + + + + + + TodoMVC: React + + +
+ + + diff --git a/examples/todomvc-react/src/index.js b/examples/todomvc-react/src/index.js new file mode 100644 index 00000000..9c929424 --- /dev/null +++ b/examples/todomvc-react/src/index.js @@ -0,0 +1,15 @@ +import React from "react"; +import { render } from "react-dom"; +import { HashRouter, Route, Routes } from "react-router-dom"; + +import { App } from "./todo/app"; +import "todomvc-app-css/index.css"; + +render( + + + } /> + + , + document.getElementById("root") +); diff --git a/examples/todomvc-react/src/todo/app.css b/examples/todomvc-react/src/todo/app.css new file mode 100644 index 00000000..bfa6617e --- /dev/null +++ b/examples/todomvc-react/src/todo/app.css @@ -0,0 +1,24 @@ +/* used for things that should be hidden in the ui, +but useful for people who use screen readers */ +.visually-hidden { + border: 0; + clip: rect(0 0 0 0); + clip-path: inset(50%); + height: 1px; + width: 1px; + margin: -1px; + padding: 0; + overflow: hidden; + position: absolute; + white-space: nowrap; +} + +.toggle-all { + width: 40px !important; + height: 60px !important; + right: auto !important; +} + +.toggle-all-label { + pointer-events: none; +} diff --git a/examples/todomvc-react/src/todo/app.jsx b/examples/todomvc-react/src/todo/app.jsx new file mode 100644 index 00000000..4ae2b60d --- /dev/null +++ b/examples/todomvc-react/src/todo/app.jsx @@ -0,0 +1,20 @@ +import { useReducer } from "react"; +import { Header } from "./components/header"; +import { Main } from "./components/main"; +import { Footer } from "./components/footer"; + +import { todoReducer } from "./reducer"; + +import "./app.css"; + +export function App() { + const [todos, dispatch] = useReducer(todoReducer, []); + + return ( + <> +
+
+