Update compat tests to use THREE.r155
This commit is contained in:
parent
4fefee863e
commit
f612108e18
70 changed files with 534 additions and 374 deletions
42
compat-tests/fixtures/r3f-cra/cra.compat-test.ts
Normal file
42
compat-tests/fixtures/r3f-cra/cra.compat-test.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
// @cspotcode/zx is zx in CommonJS
|
||||
import {$, cd, path, ProcessPromise} from '@cspotcode/zx'
|
||||
import {defer, testServerAndPage} from '../../utils/testUtils'
|
||||
|
||||
const PATH_TO_PACKAGE = path.join(__dirname, `./package`)
|
||||
|
||||
describe(`Create React App`, () => {
|
||||
test(`build succeeds`, async () => {
|
||||
cd(PATH_TO_PACKAGE)
|
||||
const {exitCode} = await $`npm run build`
|
||||
// at this point, the build should have succeeded
|
||||
expect(exitCode).toEqual(0)
|
||||
})
|
||||
|
||||
describe(`build`, () => {
|
||||
function startServerOnPort(port: number): ProcessPromise<unknown> {
|
||||
cd(PATH_TO_PACKAGE)
|
||||
|
||||
return $`npm run serve -- -p ${port}`
|
||||
}
|
||||
|
||||
testServerAndPage({
|
||||
startServerOnPort,
|
||||
checkServerStdoutToSeeIfItsReady: (chunk) =>
|
||||
chunk.includes('Accepting connections'),
|
||||
})
|
||||
})
|
||||
|
||||
describe(`dev`, () => {
|
||||
function startServerOnPort(port: number): ProcessPromise<unknown> {
|
||||
cd(PATH_TO_PACKAGE)
|
||||
|
||||
return $`BROWSER=none PORT=${port} npm run start`
|
||||
}
|
||||
|
||||
testServerAndPage({
|
||||
startServerOnPort,
|
||||
checkServerStdoutToSeeIfItsReady: (chunk) =>
|
||||
chunk.includes('You can now view'),
|
||||
})
|
||||
})
|
||||
})
|
23
compat-tests/fixtures/r3f-cra/package/.gitignore
vendored
Normal file
23
compat-tests/fixtures/r3f-cra/package/.gitignore
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
1
compat-tests/fixtures/r3f-cra/package/README.md
Normal file
1
compat-tests/fixtures/r3f-cra/package/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
Testing `@theatre/core` and `@theatre/studio` with `npm`, `create-react-app`, and `react@18`
|
42
compat-tests/fixtures/r3f-cra/package/package.json
Normal file
42
compat-tests/fixtures/r3f-cra/package/package.json
Normal file
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"name": "@compat/cra-react18",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject",
|
||||
"serve": "serve -s build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-three/drei": "^9.80.1",
|
||||
"@react-three/fiber": "^8.13.6",
|
||||
"three": "^0.155.0",
|
||||
"@testing-library/jest-dom": "^5.11.4",
|
||||
"@testing-library/react": "^11.1.0",
|
||||
"@testing-library/user-event": "^12.1.10",
|
||||
"@theatre/core": "0.0.1-COMPAT.1",
|
||||
"@theatre/r3f": "0.0.1-COMPAT.1",
|
||||
"@theatre/studio": "0.0.1-COMPAT.1",
|
||||
"@types/jest": "^29.5.3",
|
||||
"@types/node": "^20.4.5",
|
||||
"@types/react": "^18.2.17",
|
||||
"@types/react-dom": "^18.2.7",
|
||||
"react-scripts": "^5.0.1",
|
||||
"typescript": "^3.2.1",
|
||||
"serve": "14.2.0",
|
||||
"web-vitals": "^1.0.1"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": ["react-app", "react-app/jest"]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [">0.2%", "not dead", "not op_mini all"],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
37
compat-tests/fixtures/r3f-cra/package/public/index.html
Normal file
37
compat-tests/fixtures/r3f-cra/package/public/index.html
Normal file
|
@ -0,0 +1,37 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
102
compat-tests/fixtures/r3f-cra/package/src/App/App.tsx
Normal file
102
compat-tests/fixtures/r3f-cra/package/src/App/App.tsx
Normal file
|
@ -0,0 +1,102 @@
|
|||
import {getProject} from '@theatre/core'
|
||||
import React, {useEffect, useRef} from 'react'
|
||||
import {Canvas} from '@react-three/fiber'
|
||||
import {editable as e, SheetProvider, PerspectiveCamera} from '@theatre/r3f'
|
||||
import state from './state.json'
|
||||
|
||||
// credit: https://codesandbox.io/s/camera-pan-nsb7f
|
||||
|
||||
function Plane({color, theatreKey, ...props}: any) {
|
||||
return (
|
||||
<e.mesh {...props} theatreKey={theatreKey}>
|
||||
<boxGeometry />
|
||||
<meshStandardMaterial color={color} />
|
||||
</e.mesh>
|
||||
)
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const light2Ref = useRef<any>()
|
||||
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
if (!light2Ref.current) return
|
||||
|
||||
clearInterval(interval)
|
||||
|
||||
const intensityInStateJson = 3
|
||||
const currentIntensity = light2Ref.current.intensity
|
||||
if (currentIntensity !== intensityInStateJson) {
|
||||
console.error(`Test failed: light2.intensity is ${currentIntensity}`)
|
||||
} else {
|
||||
console.log(`Test passed: light2.intensity is ${intensityInStateJson}`)
|
||||
}
|
||||
}, 50)
|
||||
// see the note on <e.pointLight theatreKey="Light 2" /> below to understand why we're doing this
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<Canvas
|
||||
gl={{preserveDrawingBuffer: true}}
|
||||
linear
|
||||
frameloop="demand"
|
||||
dpr={[1.5, 2]}
|
||||
style={{position: 'absolute', top: 0, left: 0}}
|
||||
>
|
||||
<SheetProvider
|
||||
sheet={getProject('Playground - R3F', {state}).sheet('R3F-Canvas')}
|
||||
>
|
||||
{/* @ts-ignore */}
|
||||
<PerspectiveCamera makeDefault theatreKey="Camera" />
|
||||
<ambientLight intensity={0.4} />
|
||||
<e.pointLight
|
||||
position={[-10, -10, 5]}
|
||||
intensity={2}
|
||||
color="#ff20f0"
|
||||
theatreKey="Light 1"
|
||||
/>
|
||||
<e.pointLight
|
||||
position={[0, 0.5, -1]}
|
||||
distance={1}
|
||||
// the intensity is statically set to 2, but in the state.json file we'll set it to 3,
|
||||
// and we'll use that as a test to make sure the state is being loaded correctly
|
||||
intensity={2}
|
||||
color="#e4be00"
|
||||
theatreKey="Light 2"
|
||||
ref={light2Ref}
|
||||
/>
|
||||
|
||||
<group position={[0, -0.9, -3]}>
|
||||
<Plane
|
||||
color="hotpink"
|
||||
rotation-x={-Math.PI / 2}
|
||||
position-z={2}
|
||||
scale={[4, 20, 0.2]}
|
||||
theatreKey="plane1"
|
||||
/>
|
||||
<Plane
|
||||
color="#e4be00"
|
||||
rotation-x={-Math.PI / 2}
|
||||
position-y={1}
|
||||
scale={[4.2, 0.2, 4]}
|
||||
theatreKey="plane2"
|
||||
/>
|
||||
<Plane
|
||||
color="#736fbd"
|
||||
rotation-x={-Math.PI / 2}
|
||||
position={[-1.7, 1, 3.5]}
|
||||
scale={[0.5, 4, 4]}
|
||||
theatreKey="plane3"
|
||||
/>
|
||||
<Plane
|
||||
color="white"
|
||||
rotation-x={-Math.PI / 2}
|
||||
position={[0, 4.5, 3]}
|
||||
scale={[2, 0.03, 4]}
|
||||
theatreKey="plane4"
|
||||
/>
|
||||
</group>
|
||||
</SheetProvider>
|
||||
</Canvas>
|
||||
)
|
||||
}
|
19
compat-tests/fixtures/r3f-cra/package/src/App/state.json
Normal file
19
compat-tests/fixtures/r3f-cra/package/src/App/state.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"sheetsById": {
|
||||
"R3F-Canvas": {
|
||||
"staticOverrides": {
|
||||
"byObject": {
|
||||
"Light 2": {
|
||||
"intensity": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitionVersion": "0.4.0",
|
||||
"revisionHistory": [
|
||||
"jVNB3VWU34BIQK7M",
|
||||
"-NXkC2GceSVBoVqa",
|
||||
"Bw7ng1kdcWmMO5DN"
|
||||
]
|
||||
}
|
13
compat-tests/fixtures/r3f-cra/package/src/index.tsx
Normal file
13
compat-tests/fixtures/r3f-cra/package/src/index.tsx
Normal file
|
@ -0,0 +1,13 @@
|
|||
import ReactDOM from 'react-dom/client'
|
||||
import studio from '@theatre/studio'
|
||||
import extension from '@theatre/r3f/dist/extension'
|
||||
import App from './App/App.tsx'
|
||||
|
||||
if (process.env.NODE_ENV === 'development' && typeof window !== 'undefined') {
|
||||
studio.extend(extension)
|
||||
studio.initialize({usePersistentStorage: false})
|
||||
}
|
||||
|
||||
const container = document.getElementById('root')!
|
||||
const root = ReactDOM.createRoot(container)
|
||||
root.render(<App />)
|
Loading…
Add table
Add a link
Reference in a new issue