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

feat: add e2e and unit test #307

Open
wants to merge 1 commit 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pnpm-lock.yaml
.nyc_output
tmp
.idea
/node_modules
node_modules
/packages/*/node_modules
/packages/*/types
/packages/*/doc
Expand All @@ -25,3 +25,5 @@ stats.html
tsconfig.tsbuildinfo
oasis-npm
api
playwright-report
test-results
1 change: 1 addition & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pages
53 changes: 53 additions & 0 deletions e2e/cases/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { BlinnPhongMaterial, Camera, MeshRenderer, PrimitiveMesh, Vector3, WebGLEngine } from "@galacean/engine";
import { Gizmo, Group, State } from "@galacean/engine-toolkit";
import { PhysXPhysics } from "@galacean/engine-physics-physx";

document.addEventListener("pointerdown", (e) => {
console.log("pointer down", e);
});

document.addEventListener("pointermove", (e) => {
console.log("pointer move", e);
});

WebGLEngine.create({ canvas: "canvas", physics: new PhysXPhysics() }).then((engine) => {
engine.canvas.resizeByClientSize();
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity();

// init camera
const cameraEntity = rootEntity.createChild("camera");
const camera = cameraEntity.addComponent(Camera);
const pos = cameraEntity.transform.position;
pos.set(10, 10, 10);
cameraEntity.transform.position = pos;
Comment on lines +21 to +23
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify position setting for cameraEntity

You can directly set the position without creating an extra variable or redundant assignment. This makes the code cleaner.

Apply this diff to simplify the code:

-const pos = cameraEntity.transform.position;
-pos.set(10, 10, 10);
-cameraEntity.transform.position = pos;
+cameraEntity.transform.position.set(10, 10, 10);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const pos = cameraEntity.transform.position;
pos.set(10, 10, 10);
cameraEntity.transform.position = pos;
cameraEntity.transform.position.set(10, 10, 10);

cameraEntity.transform.lookAt(new Vector3(0, 0, 0));

// Initialize group for selection
const group = new Group();

// add gizmo
const gizmoEntity = rootEntity.createChild("editor-gizmo");
const gizmo = gizmoEntity.addComponent(Gizmo);
gizmo.init(camera, group);
gizmo.state = State.translate;

// init light
scene.ambientLight.diffuseSolidColor.set(1, 1, 1, 1);
scene.ambientLight.diffuseIntensity = 1.2;

// init cube
const cubeEntity = rootEntity.createChild("cube");
const renderer = cubeEntity.addComponent(MeshRenderer);
const mtl = new BlinnPhongMaterial(engine);
const color = mtl.baseColor;
color.r = 0.0;
color.g = 0.8;
color.b = 0.5;
color.a = 1.0;
Comment on lines +43 to +47
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify color assignment by using the set method

Instead of setting each color component individually, you can use the set method to assign all values at once, making the code more concise.

Apply this diff to simplify the color assignment:

const color = mtl.baseColor;
-color.r = 0.0;
-color.g = 0.8;
-color.b = 0.5;
-color.a = 1.0;
+color.set(0.0, 0.8, 0.5, 1.0);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const color = mtl.baseColor;
color.r = 0.0;
color.g = 0.8;
color.b = 0.5;
color.a = 1.0;
const color = mtl.baseColor;
color.set(0.0, 0.8, 0.5, 1.0);

renderer.mesh = PrimitiveMesh.createCuboid(engine);
renderer.setMaterial(mtl);
group.addEntity(cubeEntity);

engine.run();
});
Comment on lines +13 to +53
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for the promise returned by WebGLEngine.create

Currently, if WebGLEngine.create fails (e.g., due to a missing canvas element or initialization issues), the error is unhandled. Adding a .catch block would improve the robustness of the application.

Apply this diff to add error handling:

 WebGLEngine.create({ canvas: "canvas", physics: new PhysXPhysics() }).then((engine) => {
   // existing code...
   engine.run();
+}).catch((error) => {
+  console.error("Failed to create WebGLEngine:", error);
+});
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
WebGLEngine.create({ canvas: "canvas", physics: new PhysXPhysics() }).then((engine) => {
engine.canvas.resizeByClientSize();
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity();
// init camera
const cameraEntity = rootEntity.createChild("camera");
const camera = cameraEntity.addComponent(Camera);
const pos = cameraEntity.transform.position;
pos.set(10, 10, 10);
cameraEntity.transform.position = pos;
cameraEntity.transform.lookAt(new Vector3(0, 0, 0));
// Initialize group for selection
const group = new Group();
// add gizmo
const gizmoEntity = rootEntity.createChild("editor-gizmo");
const gizmo = gizmoEntity.addComponent(Gizmo);
gizmo.init(camera, group);
gizmo.state = State.translate;
// init light
scene.ambientLight.diffuseSolidColor.set(1, 1, 1, 1);
scene.ambientLight.diffuseIntensity = 1.2;
// init cube
const cubeEntity = rootEntity.createChild("cube");
const renderer = cubeEntity.addComponent(MeshRenderer);
const mtl = new BlinnPhongMaterial(engine);
const color = mtl.baseColor;
color.r = 0.0;
color.g = 0.8;
color.b = 0.5;
color.a = 1.0;
renderer.mesh = PrimitiveMesh.createCuboid(engine);
renderer.setMaterial(mtl);
group.addEntity(cubeEntity);
engine.run();
});
WebGLEngine.create({ canvas: "canvas", physics: new PhysXPhysics() }).then((engine) => {
engine.canvas.resizeByClientSize();
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity();
// init camera
const cameraEntity = rootEntity.createChild("camera");
const camera = cameraEntity.addComponent(Camera);
const pos = cameraEntity.transform.position;
pos.set(10, 10, 10);
cameraEntity.transform.position = pos;
cameraEntity.transform.lookAt(new Vector3(0, 0, 0));
// Initialize group for selection
const group = new Group();
// add gizmo
const gizmoEntity = rootEntity.createChild("editor-gizmo");
const gizmo = gizmoEntity.addComponent(Gizmo);
gizmo.init(camera, group);
gizmo.state = State.translate;
// init light
scene.ambientLight.diffuseSolidColor.set(1, 1, 1, 1);
scene.ambientLight.diffuseIntensity = 1.2;
// init cube
const cubeEntity = rootEntity.createChild("cube");
const renderer = cubeEntity.addComponent(MeshRenderer);
const mtl = new BlinnPhongMaterial(engine);
const color = mtl.baseColor;
color.r = 0.0;
color.g = 0.8;
color.b = 0.5;
color.a = 1.0;
renderer.mesh = PrimitiveMesh.createCuboid(engine);
renderer.setMaterial(mtl);
group.addEntity(cubeEntity);
engine.run();
}).catch((error) => {
console.error("Failed to create WebGLEngine:", error);
});

19 changes: 19 additions & 0 deletions e2e/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Galacean App</title>
<style>
canvas {
position: fixed;
overflow: hidden;
}
</style>
</head>
<body style="margin: 0; padding: 0">
<canvas id="canvas" style="width: 100vw; height: 100vh"></canvas>
<script type="module" src="$$src$$"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@galacean/toolkit-e2e",
"private": "true",
"type": "module",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview",
"e2e": "vite-node test.ts"
},
"devDependencies": {
"ts-node": "^10",
"vite": "^5",
"vite-node": "^2.0.5"
},
"dependencies": {
"@galacean/engine": "^1.3.0",
"@galacean/engine-physics-physx": "^1.3.0",
"@galacean/engine-toolkit": "workspace:*"
}
}
34 changes: 34 additions & 0 deletions e2e/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import path from "path";
import { createServer } from "vite";
import playwright from "playwright";
import fs from "fs";

const browser = await playwright.chromium.launch({
headless: false
});

async function runTests() {
const server = await createServer({
root: path.join(process.cwd())
});
await server.listen();
server.printUrls();

const page = await browser.newPage();
page.setViewportSize({ width: 500, height: 500 });

const pages = fs.readdirSync(path.join(__dirname, "pages"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use asynchronous file operations instead of synchronous ones

Using synchronous file system methods like fs.readdirSync and fs.existsSync can block the event loop and degrade performance. It's better to use their asynchronous counterparts to improve efficiency.

Apply this diff to refactor the code:

-  const pages = fs.readdirSync(path.join(__dirname, "pages"));
+  const pages = await fs.promises.readdir(path.join(__dirname, "pages"));

...

-  if (fs.existsSync(path.join(__dirname, "tests", `${pageName}.ts`))) {
+  if (
+    await fs.promises
+      .access(path.join(__dirname, "tests", `${pageName}.test`))
+      .then(() => true)
+      .catch(() => false)
+  ) {

Also applies to: 24-24

for (let i = 0; i < pages.length; i++) {
const pageName = path.basename(pages[i], ".html");
await page.goto(`http://localhost:1237/pages/${pageName}.html`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Retrieve server port dynamically instead of hardcoding

Hardcoding the port number (1237) may cause issues if the server runs on a different port, especially in different environments or configurations. It's better to retrieve the actual port number from the server instance after it starts listening.

Apply this diff to make the port dynamic:

+   const address = server.httpServer.address();
+   const port = typeof address === 'string' ? address : address.port;

...

Committable suggestion was skipped due to low confidence.

if (fs.existsSync(path.join(__dirname, "tests", `${pageName}.ts`))) {
const { run } = await import(`./tests/${pageName}.test`);
Comment on lines +24 to +25
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix file extension inconsistency in test file check and import

There's a discrepancy between the file extensions used when checking for the test file and when importing it. You're checking for ${pageName}.ts but importing ${pageName}.test. This might lead to the test files not being found or executed correctly.

Apply this diff to fix the inconsistency:

-  if (fs.existsSync(path.join(__dirname, "tests", `${pageName}.ts`))) {
-    const { run } = await import(`./tests/${pageName}.test`);
+  if (fs.existsSync(path.join(__dirname, "tests", `${pageName}.test`))) {
+    const { run } = await import(`./tests/${pageName}.test`);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (fs.existsSync(path.join(__dirname, "tests", `${pageName}.ts`))) {
const { run } = await import(`./tests/${pageName}.test`);
if (fs.existsSync(path.join(__dirname, "tests", `${pageName}.test`))) {
const { run } = await import(`./tests/${pageName}.test`);

if (run) run(page);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Await 'run' function if it's asynchronous

If the run function in your test modules is asynchronous, you should await it to ensure that the test completes before moving on to the next one. This ensures that tests are executed sequentially and the page state is consistent.

Apply this diff to fix the issue:

-  if (run) run(page);
+  if (run) await run(page);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (run) run(page);
if (run) await run(page);

}
}

browser.close()
server.close()
Comment on lines +30 to +31
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add 'await' when closing browser and server

Playwright's browser.close() and Vite's server.close() are asynchronous functions that return promises. To ensure that the browser and server are properly closed before the script exits, you should await these calls.

Apply this diff to fix the issue:

+  await browser.close();
+  await server.close();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
browser.close()
server.close()
await browser.close();
await server.close();

}
Comment on lines +10 to +32
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and ensure resource cleanup

To handle potential errors during the test execution and to ensure that the browser and server are properly closed even if an error occurs, consider wrapping your test logic in a try...catch...finally block. This approach enhances the reliability and maintainability of your test script.

Here's how you can refactor the code:

async function runTests() {
  const server = await createServer({
    root: path.join(process.cwd()),
  });
  await server.listen();
  const address = server.httpServer.address();
  const port = typeof address === "string" ? address : address.port;
  server.printUrls();

  const browser = await playwright.chromium.launch({
    headless: false,
  });

  try {
    const page = await browser.newPage();
    page.setViewportSize({ width: 500, height: 500 });

    const pages = await fs.promises.readdir(path.join(__dirname, "pages"));
    for (let i = 0; i < pages.length; i++) {
      const pageName = path.basename(pages[i], ".html");
      await page.goto(`http://localhost:${port}/pages/${pageName}.html`);
      if (
        await fs.promises
          .access(path.join(__dirname, "tests", `${pageName}.test`))
          .then(() => true)
          .catch(() => false)
      ) {
        const { run } = await import(`./tests/${pageName}.test`);
        if (run) await run(page);
      }
    }
  } catch (error) {
    console.error("Error during test execution:", error);
  } finally {
    await browser.close();
    await server.close();
  }
}


runTests();
7 changes: 7 additions & 0 deletions e2e/tests/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Page } from "playwright";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider importing additional Playwright utilities

The current import statement only brings in the Page type from Playwright. Given that this is a test file, it might be beneficial to import additional utilities that are commonly used in Playwright tests.

Consider updating the import statement as follows:

import { Page, expect, test } from "@playwright/test";

This change would allow you to use Playwright's test function for structuring your tests and the expect function for assertions, providing a more complete testing framework.


export function run(page: Page) {
page.mouse.move(250, 265);
page.mouse.down();
page.mouse.move(250, 400);
}
Comment on lines +1 to +7
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider enhancing the test structure and robustness

While the current implementation provides a basic framework for simulating mouse actions, there are several areas where it could be improved:

  1. The function lacks assertions, which are crucial for validating the expected behavior in a test scenario. Consider adding assertions to verify the outcome of the mouse actions.

  2. The use of hardcoded coordinates (250, 265) and (250, 400) may make the test brittle and dependent on specific screen sizes or layouts. It's recommended to use more robust selectors or relative positioning.

  3. The mouse is left in a pressed state after the actions, which could potentially affect subsequent tests. Consider adding a page.mouse.up() action at the end of the function.

  4. The purpose of this test is not immediately clear from the implementation. Consider adding comments or renaming the function to better describe its intent.

Here's a suggested refactor to address these points:

import { Page, expect } from "playwright";

/**
 * Simulates a vertical drag action and verifies its effect
 * @param page The Playwright Page object
 */
export async function testVerticalDrag(page: Page) {
  // Use more robust selectors instead of hardcoded coordinates
  const dragHandle = await page.locator('.drag-handle');
  const dragTarget = await page.locator('.drop-target');

  // Get the bounding boxes of the elements
  const handleBox = await dragHandle.boundingBox();
  const targetBox = await dragTarget.boundingBox();

  if (!handleBox || !targetBox) {
    throw new Error("Could not locate drag elements");
  }

  // Perform the drag action
  await page.mouse.move(handleBox.x + handleBox.width / 2, handleBox.y + handleBox.height / 2);
  await page.mouse.down();
  await page.mouse.move(targetBox.x + targetBox.width / 2, targetBox.y + targetBox.height / 2);
  await page.mouse.up();

  // Add an assertion to verify the drag action
  const result = await page.locator('.drag-result').textContent();
  expect(result).toBe("Drag successful");
}

This refactored version addresses the issues by using more robust selectors, completing the mouse action cycle, and including an assertion. It also provides a clearer purpose through naming and comments.

59 changes: 59 additions & 0 deletions e2e/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import path from "path";
import fs from "fs";
import { defineConfig } from "vite";

const templateStr = fs.readFileSync(path.join(__dirname, "index.html"), "utf8");
const platforms = fs.readdirSync(path.join(__dirname, "cases"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Filter 'cases' directory entries to only process TypeScript files

Currently, the code processes all entries in the cases directory, which may include non-TypeScript files or directories. To ensure that only TypeScript files are processed, filter the entries to include only .ts files.

Apply the following diff to filter the platforms array:

-const platforms = fs.readdirSync(path.join(__dirname, "cases"));
+const platforms = fs
+  .readdirSync(path.join(__dirname, "cases"))
+  .filter((file) => path.extname(file) === ".ts");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const platforms = fs.readdirSync(path.join(__dirname, "cases"));
const platforms = fs
.readdirSync(path.join(__dirname, "cases"))
.filter((file) => path.extname(file) === ".ts");

const outputDirectory = path.join(__dirname, "pages");
if (!fs.existsSync(outputDirectory)) {
fs.mkdirSync(outputDirectory);
}

platforms.forEach((page) => {
const outputCode = templateStr.replace("$$src$$", `../cases/${page}`);
const basename = path.basename(page, ".ts");
fs.writeFileSync(path.join(outputDirectory, `${basename}.html`), outputCode, "utf-8");
});

export default defineConfig({
server: {
host: "0.0.0.0",
port: 1237
},
clearScreen: false,
resolve: {
dedupe: ["@galacean/engine"]
},
optimizeDeps: {
esbuildOptions: {
target: "esnext",
// Node.js global to browser globalThis
define: {
global: "globalThis"
},
supported: {
bigint: true
}
},
exclude: [
"@galacean/engine",
"@galacean/engine-draco",
"@galacean/engine-lottie",
"@galacean/engine-spine",
"@galacean/tools-baker",
"@galacean/engine-toolkit",
"@galacean/engine-toolkit-auxiliary-lines",
"@galacean/engine-toolkit-controls",
"@galacean/engine-toolkit-framebuffer-picker",
"@galacean/engine-toolkit-gizmo",
"@galacean/engine-toolkit-lines",
"@galacean/engine-toolkit-outline",
"@galacean/engine-toolkit-planar-shadow-material",
"@galacean/engine-toolkit-skeleton-viewer",
"@galacean/engine-toolkit-grid-material",
"@galacean/engine-toolkit-navigation-gizmo",
"@galacean/engine-toolkit-geometry-sketch",
"@galacean/engine-toolkit-stats"
]
}
});
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
"version": "1.2.0-beta.0",
"private": true,
"workspaces": [
"packages/*"
"packages/*",
"e2e/*"
],
"homepage": "https://oasisengine.cn/",
"repository": "https://github.com/galacean/engine-toolkit",
"bugs": "https://github.com/galacean/engine-toolkit/issues",
"scripts": {
"preinstall": "npx only-allow pnpm",
"test": "cross-env TS_NODE_PROJECT=tsconfig.tests.json floss --path tests -r ts-node/register",
"test-debug": "cross-env TS_NODE_PROJECT=tsconfig.tests.json floss --path tests -r ts-node/register --debug",
"test-cov": "cross-env TS_NODE_PROJECT=tsconfig.tests.json nyc --reporter=lcov floss --path tests -r ts-node/register",
"test": "vitest",
"coverage": "vitest --coverage --ui",
"ci": "pnpm install && npm run build && npm run b:types && npm run test-cov",
"lint": "eslint packages/*/src --ext .ts",
"watch": "rollup -cw -m inline",
"b:types": "pnpm -r --filter=./packages/* run b:types",
"build": "rollup -c",
"b:all": "pnpm run b:types && cross-env BUILD_TYPE=ALL rollup -c",
"e2e": "pnpm --filter \"@galacean/toolkit-e2e\" e2e",
"clean": "pnpm -r exec rm -rf dist && pnpm -r exec rm -rf types"
},
"devDependencies": {
Expand All @@ -30,32 +31,30 @@
"@rollup/plugin-replace": "^5.0.2",
"@swc/core": "^1.3.49",
"@swc/helpers": "^0.5.0",
"@types/chai": "^4.3.3",
"@types/mocha": "^8.2.3",
"@types/node": "^18.7.18",
"@types/offscreencanvas": "^2019.7.0",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"@vitest/browser": "^2.0.5",
"@vitest/coverage-istanbul": "^2.0.5",
"@vitest/ui": "^2.0.5",
"camelcase": "^7.0.1",
"chai": "^4.3.6",
"cross-env": "^5.2.1",
"electron": "^13.6.9",
"eslint": "^7.32.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-prettier": "^3.4.1",
"floss": "^5.0.1",
"husky": "^8.0.3",
"lint-staged": "^10.5.4",
"nyc": "^15.1.0",
"playwright": "^1.46.1",
"prettier": "^2.7.1",
"rollup": "^3",
"rollup-plugin-binary2base64": "1.0.3",
"rollup-plugin-glslify": "^1.3.1",
"rollup-plugin-modify": "^3.0.0",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-swc3": "^0.8.0",
"ts-node": "^10",
"typescript": "^4.8.3"
"typescript": "^5",
"vitest": "^2.0.5"
},
"husky": {
"hooks": {
Expand Down
1 change: 1 addition & 0 deletions packages/controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"types": "types/index.d.ts",
"main": "dist/commonjs/browser.js",
"module": "dist/es/index.js",
"debug": "src/index.ts",
"files": [
"dist/**/*",
"types/**/*"
Expand Down
1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ packages:
- "packages/*"
# all packages in subdirs of components/
- "tests"
- 'e2e'
18 changes: 0 additions & 18 deletions tests/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions tests/src/OrbitControl.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { WebGLEngine } from "@galacean/engine";
import { OrbitControl } from "@galacean/engine-toolkit-controls";
import { expect } from "chai";
import { describe, beforeAll, it, expect } from "vitest"

const canvasDOM = document.createElement("canvas");
canvasDOM.width = 1024;
canvasDOM.height = 1024;

describe("orbit control test", function () {
let orbitControl: OrbitControl;
before(async () => {
beforeAll(async () => {
const engine = await WebGLEngine.create({ canvas: canvasDOM });
const node = engine.sceneManager.activeScene.createRootEntity();
orbitControl = node.addComponent(OrbitControl);
Expand Down
21 changes: 21 additions & 0 deletions tests/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import { defineProject } from "vitest/config"

export default defineProject({
optimizeDeps: {
exclude: [
"@galacean/engine",
"@galacean/engine-loader",
"@galacean/engine-rhi-webgl",
"@galacean/engine-math",
"@galacean/engine-core"
]
},
test: {
browser: {
provider: 'playwright',
enabled: true,
name: 'chromium',
},
}
})
10 changes: 10 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "vitest/config"

export default defineConfig({
test: {
coverage: {
provider: "istanbul",
reporter: ['html']
}
}
})
6 changes: 6 additions & 0 deletions vitest.workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineWorkspace } from "vitest/config"

export default defineWorkspace([
"packages/*",
"tests"
])