fuzzyworld

nordic-skating / local-littlejs / files / test / littlejs-migration.test.ts

Branch local-littlejs · default branch · all branches

littlejs-migration.test.ts

3.0 KB · history · blame

1/**
2 * Tests for LittleJS migration
3 */
4
5import { describe, it, expect } from 'vitest'
6import { ThreeToLittleJSAdapter as Adapter } from '../src/adapters/three-to-littlejs.js'
7import * as THREE from 'three'
8
9describe('Three.js to LittleJS Conversion', () => {
10 describe('Color Conversion', () => {
11 it('should convert Three.js Color to number correctly', () => {
12 const color = new THREE.Color(0xff0000) // Red
13 const result = Adapter.convertColor(color)
14 expect(result).toBe(0xff0000)
15 })
16
17 it('should handle different color values', () => {
18 const blue = new THREE.Color(0x0000ff)
19 const green = new THREE.Color(0x00ff00)
20 const white = new THREE.Color(0xffffff)
21
22 expect(Adapter.convertColor(blue)).toBe(0x0000ff)
23 expect(Adapter.convertColor(green)).toBe(0x00ff00)
24 expect(Adapter.convertColor(white)).toBe(0xffffff)
25 })
26 })
27
28 describe('Vector Conversion', () => {
29 it('should convert Vector3 to array', () => {
30 const vec = new THREE.Vector3(1, 2, 3)
31 const result = Adapter.convertVector3(vec)
32 expect(result).toEqual([1, 2, 3])
33 })
34
35 it('should convert Vector4 to array', () => {
36 const vec = new THREE.Vector4(1, 2, 3, 4)
37 const result = Adapter.convertVector4(vec)
38 expect(result).toEqual([1, 2, 3, 4])
39 })
40 })
41
42 describe('Material Creation', () => {
43 it('should create basic material with color', () => {
44 const color = new THREE.Color(0xff00ff)
45 const result = Adapter.createBasicMaterial({ color })
46 expect(result.color).toBe(0xff00ff)
47 })
48
49 it('should handle transparency settings', () => {
50 const result = Adapter.createBasicMaterial({
51 transparent: true,
52 opacity: 0.5
53 })
54 expect(result.transparent).toBe(true)
55 expect(result.opacity).toBe(0.5)
56 })
57
58 it('should handle emissive properties', () => {
59 const emissive = new THREE.Color(0x00ffff)
60 const result = Adapter.createBasicMaterial({
61 emissive,
62 emissiveIntensity: 2.0
63 })
64 expect(result.emissive).toBe(0x00ffff)
65 expect(result.emissiveIntensity).toBe(2.0)
66 })
67 })
68
69 describe('Uniform Adaptation', () => {
70 it('should adapt color uniforms', () => {
71 const color = new THREE.Color(0x123456)
72 const uniforms = {
73 testColor: { value: color }
74 }
75 const result = Adapter.adaptUniforms(uniforms)
76 expect(result.testColor).toBe(Adapter.convertColor(color))
77 })
78
79 it('should adapt vector uniforms', () => {
80 const uniforms = {
81 testVec3: { value: new THREE.Vector3(1, 2, 3) },
82 testVec4: { value: new THREE.Vector4(4, 5, 6, 7) }
83 }
84 const result = Adapter.adaptUniforms(uniforms)
85 expect(result.testVec3).toEqual([1, 2, 3])
86 expect(result.testVec4).toEqual([4, 5, 6, 7])
87 })
88
89 it('should handle numeric uniforms', () => {
90 const uniforms = {
91 testFloat: { value: 3.14 }
92 }
93 const result = Adapter.adaptUniforms(uniforms)
94 expect(result.testFloat).toBe(3.14)
95 })
96 })
97})