Skip to content

Commit

Permalink
environment tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zerico007 committed May 22, 2023
1 parent e580dba commit f742a09
Show file tree
Hide file tree
Showing 15 changed files with 5,885 additions and 646 deletions.
5 changes: 3 additions & 2 deletions packages/react-to-web-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
"prettier": "prettier --check vite.config.ts src",
"depcheck": "depcheck .",
"dev": "vite",
"test": "vitest",
"test:ci": "vitest run",
"test": "npm run test-environments",
"test-environments": "cd ../../tests && npm run test-environments",
"test:ci": "npm run test-environments",
"test:coverage": "vitest run --coverage",
"clean": "rm -rf tsconfig.tsbuildinfo dist",
"build": "vite build"
Expand Down
43 changes: 20 additions & 23 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
cd environments/react18
node copyTest.js
npm i
npm install --install-links ../../../..
cd ../../../../
npm ci
cd ../../

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


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

cd src/tests/builds/webpack
npm i
npm install --install-links ../../../..
npm run build
cd ../../../../
# cd src/tests/builds/webpack
# npm i
# npm install --install-links ../../../..
# 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.test.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

0 comments on commit f742a09

Please sign in to comment.