From bded6e9240680186338eef73fd6f05c3c9dd900a Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Sun, 30 Jul 2023 18:49:17 +0200 Subject: [PATCH] Add cra to compat tests --- compat-tests/fixtures/cra/cra.compat-test.ts | 42 +++++++++ .../fixtures/cra/package/package.json | 11 ++- .../fixtures/cra/package/src/index.js | 92 ------------------- .../fixtures/cra/package/src/index.tsx | 13 +++ 4 files changed, 64 insertions(+), 94 deletions(-) create mode 100644 compat-tests/fixtures/cra/cra.compat-test.ts delete mode 100644 compat-tests/fixtures/cra/package/src/index.js create mode 100644 compat-tests/fixtures/cra/package/src/index.tsx diff --git a/compat-tests/fixtures/cra/cra.compat-test.ts b/compat-tests/fixtures/cra/cra.compat-test.ts new file mode 100644 index 0000000..00b8e72 --- /dev/null +++ b/compat-tests/fixtures/cra/cra.compat-test.ts @@ -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 { + 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 { + cd(PATH_TO_PACKAGE) + + return $`BROWSER=none PORT=${port} npm run start` + } + + testServerAndPage({ + startServerOnPort, + checkServerStdoutToSeeIfItsReady: (chunk) => + chunk.includes('You can now view'), + }) + }) +}) diff --git a/compat-tests/fixtures/cra/package/package.json b/compat-tests/fixtures/cra/package/package.json index 93fe988..0d057a0 100644 --- a/compat-tests/fixtures/cra/package/package.json +++ b/compat-tests/fixtures/cra/package/package.json @@ -6,7 +6,8 @@ "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", - "eject": "react-scripts eject" + "eject": "react-scripts eject", + "serve": "serve -s build" }, "dependencies": { "@react-three/drei": ">7.2.2", @@ -16,8 +17,14 @@ "@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", - "three": ">0.132.0", + "three": "0.133.0", + "typescript": "^3.2.1", + "serve": "14.2.0", "web-vitals": "^1.0.1" }, "eslintConfig": { diff --git a/compat-tests/fixtures/cra/package/src/index.js b/compat-tests/fixtures/cra/package/src/index.js deleted file mode 100644 index 5703d55..0000000 --- a/compat-tests/fixtures/cra/package/src/index.js +++ /dev/null @@ -1,92 +0,0 @@ -import {getProject} from '@theatre/core' -import ReactDOM from 'react-dom/client' -import React from 'react' -import {Canvas} from '@react-three/fiber' -import studio from '@theatre/studio' -import {editable as e, SheetProvider} from '@theatre/r3f' -import extension from '@theatre/r3f/dist/extension' - -if (process.env.NODE_ENV === 'development' && typeof window !== 'undefined') { - studio.extend(extension) - studio.initialize({usePersistentStorage: false}) -} - -// credit: https://codesandbox.io/s/camera-pan-nsb7f - -function Plane({color, theatreKey, ...props}) { - return ( - - - - - ) -} - -function App() { - return ( - - - {/* @ts-ignore */} - - - - - - - - - - - - - ) -} - -const project = getProject('Project') -const sheet = project.sheet('Sheet') -const obj = sheet.object('Obj', {str: 'some string', num: 0}) - -const container = document.getElementById('root') -const root = ReactDOM.createRoot(container) -root.render(hi) diff --git a/compat-tests/fixtures/cra/package/src/index.tsx b/compat-tests/fixtures/cra/package/src/index.tsx new file mode 100644 index 0000000..faaa83d --- /dev/null +++ b/compat-tests/fixtures/cra/package/src/index.tsx @@ -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()