Skip to content

Commit

Permalink
chore: added playwright test
Browse files Browse the repository at this point in the history
chore: changed from react-scrips to vite for demo
chore: added GH workflow
chore: using tsup for building library now
chore: migrated to pnpm from yarn
fix: fixed typings and broken tsc run
  • Loading branch information
RIP21 committed Oct 1, 2022
1 parent 5db3acc commit b544f60
Show file tree
Hide file tree
Showing 32 changed files with 2,626 additions and 11,920 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Playwright Tests
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
test:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14.x'
- name: Install dependencies
run: pnpm install

- name: Install Playwright Browsers
run: npx playwright install --with-deps

- name: Run unit tests
run: pnpm test

- name: Run tsc
run: pnpm tsc

- name: Run Playwright tests
run: pnpm test:e2e

- uses: actions/upload-artifact@v2
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 5

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.idea
.idea
/test-results/
/playwright-report/
/playwright/.cache/
dist
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto-install-peers=true
107 changes: 107 additions & 0 deletions .pnpmfile.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"use strict"

/**
* When using the PNPM package manager, you can use pnpmfile.js to workaround
* dependencies that have mistakes in their package.json file. (This feature is
* functionally similar to Yarn's "resolutions".)
*
* For details, see the PNPM documentation:
* https://pnpm.js.org/docs/en/hooks.html
*
* IMPORTANT: SINCE THIS FILE CONTAINS EXECUTABLE CODE, MODIFYING IT IS LIKELY TO INVALIDATE
* ANY CACHED DEPENDENCY ANALYSIS. After any modification to pnpmfile.js, it's recommended to run
* "rush update --full" so that PNPM will recalculate all version selections.
* Or `pnpm install --fix-lockfile` for non Rush projects
*/
module.exports = {
hooks: {
readPackage,
},
}

/**
* This hook is invoked during installation before a package's dependencies
* are selected.
* The `packageJson` parameter is the deserialized package.json
* contents for the package that is about to be installed.
* The `context` parameter provides a log() function.
* The return value is the updated object.
*/

const TYPES = {
PEER: "peerDependencies",
DEPS: "dependencies",
}

const prettyType = (type) => (type === TYPES.DEPS ? "dependency" : "peerDependency")

function readPackage(packageJson, context) {
function removeGlobal(type, name, noLog) {
if (packageJson[type] && packageJson[type][name]) {
!noLog &&
context.log(`Removed "${name}" ${prettyType(type)} for ${packageJson.name}`)
delete packageJson[type][name]
}
}

function changeGlobal(type, name, ver, noLog) {
if (packageJson[type] && packageJson[type][name]) {
const originalVersion = packageJson[type][name]
if (originalVersion !== ver) {
!noLog &&
context.log(
`Changed "${name}" ${prettyType(
type,
)} from ${originalVersion} to ${ver} for ${packageJson.name}`,
)
packageJson[type][name] = ver
}
}
}

function add(type, forPackage, dep, ver, noLog) {
if (packageJson.name === forPackage) {
if (!packageJson[type]) {
packageJson[type] = {}
}
!noLog && context.log(`Added "${dep}" ${prettyType(type)} for ${packageJson.name}`)
packageJson[type][dep] = ver
}
}

function remove(type, forPackage, dep, noLog) {
if (packageJson.name === forPackage && !packageJson?.[type]?.[dep]) {
context.log(
`No ${type} "${dep}" in the package ${forPackage} to remove it. You sure about it?`,
)
} else if (packageJson.name === forPackage) {
!noLog && context.log(`Removed "${dep}" dependency for "${packageJson.name}"`)
delete packageJson[type][dep]
}
}

function change(type, forPackage, dep, ver, noLog) {
if (packageJson.name === forPackage && packageJson[type]) {
if (!packageJson[type][dep]) {
context.log(
`No such ${type} in the package ${forPackage} to change it. You sure about it?`,
)
} else if (packageJson.name === forPackage) {
const originalVersion = packageJson[type][dep]
if (originalVersion !== ver) {
!noLog &&
context.log(
`Changed "${dep}" ${prettyType(
type,
)} from ${originalVersion} to ${ver} for ${packageJson.name}`,
)
packageJson[type][dep] = ver
}
}
}
}

change(TYPES.PEER, "vitest-dom", "vitest", "<1", true)

return packageJson
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ Here is how you do it. It requires mock of certain browser pieces to work, but t
```tsx
import { act, render, screen } from "@testing-library/react";
import { useState } from "react";
import { SimpleMdeReact } from "SimpleMdeReact";
import { SimpleMdeReact } from "react-simplemde-editor";
import userEvent from "@testing-library/user-event";

// @ts-ignore
Expand Down
File renamed without changes.
30 changes: 0 additions & 30 deletions imports.d.ts

This file was deleted.

5 changes: 3 additions & 2 deletions public/index.html → index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<link rel="shortcut icon" href="/favicon.ico">
<title>react-simplemde-editor demo</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-7s5uDGW3AHqw6xtJmNNtr+OBRJUlgkNJEo78P4b0yRw= sha512-nNo+yCHEyn0smMxSswnf/OnX6/KwJuZTlNZBjauKhTK0c+zT+q5JOCx0UFhXQ6rJR9jg6Es8gPuD2uZcYDLqSw==" crossorigin="anonymous">

Expand All @@ -35,6 +35,7 @@
<span id="forkongithub"><a href="https://github.com/RIP21/react-simplemde-editor">View the code</a></span>
<div class='container'>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</div>
</body>
</html>
</html>
86 changes: 31 additions & 55 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,75 +12,51 @@
}
],
"license": "MIT",
"main": "lib/index.js",
"typings": "typings/SimpleMdeReact.d.ts",
"main": "dist/SimpleMdeReact.js",
"module": "dist/SimpleMdeReact.mjs",
"typings": "dist/SimpleMdeReact.d.ts",
"files": [
"lib",
"typings",
"src"
],
"scripts": {
"build:lib": "tsup ./src/SimpleMdeReact.tsx",
"prepare": "pnpm build:lib",
"demo": "vite",
"build:demo": "vite build",
"test": "vitest",
"test:e2e": "playwright test",
"test:e2e:debug": "playwright test --debug",
"tsc": "tsc"
},
"dependencies": {
"@types/codemirror": "^5.60.5"
"@types/codemirror": "~5.60.5"
},
"peerDependencies": {
"easymde": ">= 2.0.0 < 3.0.0",
"react": ">=16.8.2",
"react-dom": ">=16.8.2"
},
"devDependencies": {
"@babel/cli": "^7.13.16",
"@babel/preset-typescript": "^7.13.0",
"@babel/runtime": "^7.14.0",
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/react": "^11.2.6",
"@testing-library/user-event": "^13.1.8",
"@types/codemirror": "^5.60.5",
"@types/jest": "^26.0.23",
"@types/node": "^12.20.11",
"@types/react": "^17.0.4",
"@types/react-dom": "^17.0.3",
"easymde": "^2.0.0",
"prettier": "^2.2.1",
"@playwright-testing-library/test": "~4.5.0",
"@playwright/test": "~1.26.1",
"@testing-library/react": "~12.1.5",
"@testing-library/user-event": "~14.4.3",
"@types/codemirror": "~5.60.5",
"@types/node": "~16.11.62",
"@types/react": "~17.0.50",
"@types/react-dom": "~17.0.11",
"easymde": "~2.18.0",
"happy-dom": "~6.0.4",
"jsdom": "~20.0.0",
"prettier": "~2.7.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-scripts": "^4.0.3",
"typescript": "^4.2.4"
},
"scripts": {
"prebuild:lib": "tsc -p tsconfig.lib.json",
"build:lib": "NODE_ENV=production babel src/SimpleMdeReact.tsx --out-file lib/index.js --source-maps --extensions \".js\",\".jsx\",\".ts\",\".tsx\"",
"prepare": "yarn build:lib",
"demo": "react-scripts start",
"build:demo": "react-scripts build",
"test": "react-scripts test"
},
"eslintConfig": {
"extends": [
"react-app"
]
},
"babel": {
"presets": [
[
"babel-preset-react-app",
{
"useESModules": false,
"absoluteRuntime": false,
"typescript": true
}
]
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
"tsup": "~6.2.3",
"typescript": "~4.8.4",
"vite": "~3.1.4",
"vitest": "0.23.4",
"vitest-dom": "~0.0.4"
}
}
Loading

0 comments on commit b544f60

Please sign in to comment.