import assert from 'node:assert/strict'; import fs from 'node:fs/promises'; import React from 'react'; import {renderToStaticMarkup} from 'react-dom/server'; import {createServer} from 'vite'; const server=await createServer({configFile:false,server:{middlewareMode:true,watch:null},appType:'custom',optimizeDeps:{noDiscovery:true}}); try{ const {default:Workspace}=await server.ssrLoadModule('/resources/js/StockMenuWorkspace.jsx'); const {milliQuantity}=await server.ssrLoadModule('/resources/js/StockReadWorkspace.jsx'); const context={token:'qa',company:{id:1,name:'Synthetic company'},unit:{id:7,name:'Synthetic unit'}}; const company=p=>p==='company.view',stock=(p,u)=>company(p)||(p==='stock.view'&&u===7); const informational=renderToStaticMarkup(React.createElement(Workspace,{section:'stock_balances',context,can:company,navigate:()=>{},api:()=>{throw Error('SSR must not fetch');}})); assert(informational.includes('Consulta de existências indisponível'));assert(!informational.includes('{},api:()=>{throw Error('SSR must not fetch');}})); for(const text of ['Somente leitura','Existências físicas','Movimentos','Armazéns','Artigos'])assert(reading.includes(text)); assert(!reading.includes('Consulta de existências indisponível'));assert(!reading.includes('value="0"')); assert.equal(milliQuantity(null),'Indeterminado');assert.equal(milliQuantity('-2000'),'-2,000'); assert.equal(milliQuantity('9007199254740993000'),'9007199254740993,000'); const denied=renderToStaticMarkup(React.createElement(Workspace,{section:'stock_balances',context,can:()=>false,navigate:()=>{},api:()=>{}})); assert(!denied.includes('