7 lines
3.1 KiB
TypeScript
7 lines
3.1 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import crypto from "node:crypto";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
const root=path.resolve(import.meta.dirname,"../../..");const fixture=fs.readFileSync(path.join(root,"tests/files/web/basic_scene.blend"));const fixtureSha256=crypto.createHash("sha256").update(fixture).digest("hex");
|
|
test("WBV2-P21-002 binds renameId to compiled WASM Main",async({page})=>{test.setTimeout(120000);await page.goto("/");const result=await page.evaluate(async(bytes)=>{const{WebEngineClient}=await import("/src/engine-client/WebEngineClient.ts");const client=new WebEngineClient({timeoutMs:30000});const reopened=new WebEngineClient({timeoutMs:30000});try{const opened=await client.openBlend(Uint8Array.from(bytes).buffer);const object=opened.snapshot.nodes.find(n=>n.type==="MESH");if(!object)throw new Error("basic scene has no mesh object");const baseRevision=opened.snapshot.revision;const changed=await client.applyCommand({type:"renameId",id:object.id,name:"WBV2P2102Renamed"}as any);const renamed=changed.snapshot.nodes.find(n=>n.id===changed.snapshot.activeObjectId)||changed.snapshot.nodes.find(n=>n.id===object.id);const undone=await client.applyCommand({type:"undo"});const redone=await client.applyCommand({type:"redo"});const malformed=await client.applyCommand({type:"renameId",id:"object:missing",name:"x"}as any).then(()=>({code:"NO_ERROR"})).catch((e:any)=>({code:e?.code,message:e?.message}));const afterMalformed=await client.snapshot();const saved=await client.saveBlend();const reopen=await reopened.openBlend(saved);const renamedReopened=reopen.snapshot.nodes.find(n=>n.id===reopen.snapshot.activeObjectId)||reopen.snapshot.nodes.find(n=>n.type==="MESH");return{browser:"chromium",baseRevision,objectId:object.id,beforeName:object.name,afterName:renamed?.name,afterId:renamed?.id,createRevision:changed.snapshot.revision,undoRevision:undone.snapshot.revision,redoRevision:redone.snapshot.revision,malformed,malformedRevisionPreserved:afterMalformed.snapshot.revision===redone.snapshot.revision,reopenedName:renamedReopened?.name,reopenedRevision:reopen.snapshot.revision,savedSha256:await(async(v)=>{const h=await crypto.subtle.digest("SHA-256",v);return Array.from(new Uint8Array(h),b=>b.toString(16).padStart(2,"0")).join("")})(saved)}}finally{client.terminate();reopened.terminate()}} ,Array.from(fixture));fs.mkdirSync(path.join(root,"tests/golden/WBV2-P21-002"),{recursive:true});const output=process.env.WBV2_RENAME_REPORT??"object-rename-production.json";fs.writeFileSync(path.join(root,"tests/golden/WBV2-P21-002",output),`${JSON.stringify({schemaVersion:1,task:"WBV2-P21-002",operation:"OBJECT_RENAME_ENGINE_CHROMIUM",queueMutation:false,fixtureSha256,...result},null,2)}\n`);expect(result.browser).toBe("chromium");expect(result.afterName).toBe("WBV2P2102Renamed");expect(result.createRevision).toBe(result.baseRevision+1);expect(result.undoRevision).toBe(result.baseRevision+2);expect(result.redoRevision).toBe(result.baseRevision+3);expect(result.malformed.code).not.toBe("NO_ERROR");expect(result.malformedRevisionPreserved).toBe(true);expect(result.reopenedName).toBe("WBV2P2102Renamed");expect(result.reopenedRevision).toBe(1)});
|