Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment and Build tests #108

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/react-to-web-component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
description: "The version segment to increment: major, minor, patch, or prerelease."
required: true
preId:
description: "Appended to the prerelease segment. (default: \"\")"
description: 'Appended to the prerelease segment. (default: "")'

jobs:
verify:
Expand Down
3 changes: 1 addition & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion packages/legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"depcheck": "depcheck .",
"dev": "vite",
"test": "vitest",
"test:ci": "vitest run",
"test:react18": "chmod +x ./test && ./test",
"test:ci": "npm run test:react18",
"test:coverage": "vitest run --coverage",
"clean": "rm -rf tsconfig.tsbuildinfo dist",
"build": "vite build"
Expand Down
6 changes: 6 additions & 0 deletions packages/legacy/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cd ../../tests/environments/react18
node copyTest.js react-to-webcomponent legacy
npm ci
npm run test:ci
7 changes: 3 additions & 4 deletions packages/react-to-web-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"prettier": "prettier --check vite.config.ts src",
"depcheck": "depcheck .",
"dev": "vite",
"test": "vitest",
"test:ci": "vitest run",
"test": "cd ../../tests && npm run test",
"test:ci": "cd ../../tests && npm run test:ci",
"test:coverage": "vitest run --coverage",
"clean": "rm -rf tsconfig.tsbuildinfo dist",
"build": "vite build"
Expand All @@ -46,8 +46,7 @@
},
"devDependencies": {
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"prop-types": "^15.8.1"
"@types/react-dom": "^18.0.0"
},
"peerDependencies": {
"react": "^18.0.0",
Expand Down
1 change: 0 additions & 1 deletion tests/builds/builds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { test, expect, describe } from "vitest"
import AppWCVite from "./vite/dist/index.js"
import AppWCViteSwc from "./vite/dist-swc/index.js"
import AppWebpack from "./webpack/build/index.js"
import { CustomElementConstructor } from "../../types.js"

function flushPromises() {
return new Promise((resolve) => setImmediate(resolve))
Expand Down
59 changes: 33 additions & 26 deletions tests/builds/vite/package-lock.json

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

4 changes: 2 additions & 2 deletions tests/builds/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"preview": "vite preview"
},
"dependencies": {
"@r2wc/react-to-web-component": "^2.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-to-webcomponent": "file:../../../.."
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.28",
Expand Down
2 changes: 1 addition & 1 deletion tests/builds/vite/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import r2wc from "react-to-webcomponent"
import r2wc from "@r2wc/react-to-web-component"
import App from "./App"

const AppWC = r2wc(App, { props: ["text"] })
Expand Down
57 changes: 32 additions & 25 deletions tests/builds/webpack/package-lock.json

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

2 changes: 1 addition & 1 deletion tests/builds/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@r2wc/react-to-web-component": "^2.0.2",
"@types/node": "^16.18.23",
"@types/react": "^18.0.37",
"@types/react-dom": "^18.0.11",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"react-to-webcomponent": "file:../../../..",
"typescript": "^4.9.5"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion tests/builds/webpack/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import r2wc from "react-to-webcomponent"
import r2wc from "@r2wc/react-to-web-component"
import App from "./App"

const AppWC = r2wc(App, { props: ["text"] })
Expand Down
36 changes: 15 additions & 21 deletions tests/buildtests
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
#!/bin/bash

cd src/tests/environments/react16
cd environments/react16
node copyTest.js
npm i
npm install --install-links ../../../..
cd ../../../../
npm ci
cd ../../

cd src/tests/environments/react17
cd environments/react17
node copyTest.js
npm i
npm install --install-links ../../../..
cd ../../../../
npm ci
cd ../../

cd src/tests/environments/react18
node copyTest.js
npm i
npm install --install-links ../../../..
cd ../../../../
cd environments/react18
node copyTest.js @r2wc/react-to-web-component
npm ci
cd ../../

# cd src/tests/environments/preact10
# npm i
Expand All @@ -25,15 +22,12 @@ cd ../../../../


# builds
cd src/tests/builds/vite
npm i
npm install --install-links ../../../..
cd builds/vite
npm ci
npm run build
node swcBuild.js
cd ../../../../
cd ../../

cd src/tests/builds/webpack
npm i
npm install --install-links ../../../..
cd builds/webpack
npm ci
npm run build
cd ../../../../
12 changes: 7 additions & 5 deletions tests/environments/react16/copyTest.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require("fs")

const TEST_PATH = "../../react-to-webcomponent.test.jsx"
const REACT16_TEST_PATH = "./react-to-webcomponent.test.jsx"
const TEST_PATH = "../../react-to-web-component.tsx"
const REACT16_TEST_PATH = "./react-to-web-component.test.tsx"

// copy test file from tests folder to react16 folder
fs.copyFileSync(TEST_PATH, REACT16_TEST_PATH)

// edit react-to-webcomponent test file's reactToWebComponent and components imports
// read test file
const data = fs.readFileSync(REACT16_TEST_PATH, "utf8")
const result = data.replace(/..\/legacy\/react-to-webcomponent/g, "react-to-webcomponent/render")
const result2 = result.replace(/.\/components/g, "../../components.tsx")
// add react-to-web-component import to top of file
const result = `import r2wc from '@r2wc/react-to-web-component';\n${data}`
// remove r2wc mock from test file
const result2 = result.replace("const r2wc = vi.fn()", "")
fs.writeFileSync(REACT16_TEST_PATH, result2, "utf8")
Loading