Skip to content

Visualize Your Ideas With Code

test(2d): configure vitest (#537)

Jacob7ac9cf576a1d
diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml
index 686acd00..5107a975 100644
--- a/.github/workflows/verify.yml
+++ b/.github/workflows/verify.yml
@@ -53,6 +53,7 @@ jobs:
node-version: 18
cache: npm
- run: npm ci
+ - run: npm run core:build
- run: npx lerna run test
build:
name: Build
diff --git a/package-lock.json b/package-lock.json
index 77bd6f38..1d83e4c4 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -22483,7 +22483,9 @@
"mathjax-full": "^3.2.2"
},
"devDependencies": {
- "@motion-canvas/internal": "0.0.0"
+ "@motion-canvas/internal": "0.0.0",
+ "jsdom": "^21.1.0",
+ "vitest": "^0.29.2"
}
},
"packages/2d/node_modules/code-fns": {
@@ -26131,7 +26133,9 @@
"@motion-canvas/core": "^3.2.0",
"@motion-canvas/internal": "0.0.0",
"code-fns": "^0.8.2",
- "mathjax-full": "^3.2.2"
+ "jsdom": "^21.1.0",
+ "mathjax-full": "^3.2.2",
+ "vitest": "^0.29.2"
},
"dependencies": {
"code-fns": {
diff --git a/package.json b/package.json
index 85434437..eea45975 100644
--- a/package.json
+++ b/package.json
@@ -11,6 +11,7 @@
"core:test": "npm run test -w packages/core",
"2d:build": "npm run build -w packages/2d",
"2d:watch": "npm run watch -w packages/2d",
+ "2d:test": "npm run test -w packages/2d",
"ui:build": "npm run build -w packages/ui",
"ui:serve": "npm run dev -w packages/ui",
"ui:showcase": "npm run showcase -w packages/ui",
diff --git a/packages/2d/package.json b/packages/2d/package.json
index 268d03cd..ecf056fb 100644
--- a/packages/2d/package.json
+++ b/packages/2d/package.json
@@ -11,7 +11,8 @@
"types": "./lib/scenes/index.d.ts",
"scripts": {
"build": "ttsc",
- "watch": "ttsc -w"
+ "watch": "ttsc -w",
+ "test": "vitest"
},
"sideEffects": false,
"repository": {
@@ -24,7 +25,9 @@
"tsconfig.project.json"
],
"devDependencies": {
- "@motion-canvas/internal": "0.0.0"
+ "@motion-canvas/internal": "0.0.0",
+ "jsdom": "^21.1.0",
+ "vitest": "^0.29.2"
},
"dependencies": {
"@motion-canvas/core": "^3.2.0",
diff --git a/packages/2d/src/curves/getPolylineProfile.test.ts b/packages/2d/src/curves/getPolylineProfile.test.ts
new file mode 100644
index 00000000..d8a283bf
--- /dev/null
+++ b/packages/2d/src/curves/getPolylineProfile.test.ts
@@ -0,0 +1,21 @@
+import {describe, expect, test} from 'vitest';
+import {getPolylineProfile} from './getPolylineProfile';
+import {Vector2} from '@motion-canvas/core/lib/types';
+
+describe('getPolylineProfile', () => {
+ test('Correct arc length', () => {
+ const profile = getPolylineProfile(
+ [
+ Vector2.zero,
+ Vector2.zero,
+ new Vector2(100, 0),
+ new Vector2(100, 100),
+ new Vector2(0, 100),
+ ],
+ 0,
+ true,
+ );
+
+ expect(profile.arcLength).toBe(400);
+ });
+});
diff --git a/packages/2d/vitest.config.ts b/packages/2d/vitest.config.ts
new file mode 100644
index 00000000..908dc395
--- /dev/null
+++ b/packages/2d/vitest.config.ts
@@ -0,0 +1,9 @@
+import {defineConfig} from 'vitest/config';
+import markdownLiterals from '@motion-canvas/internal/vite/markdown-literals';
+
+export default defineConfig({
+ plugins: [markdownLiterals()],
+ test: {
+ environment: 'jsdom',
+ },
+});