@@ -14,21 +14,21 @@ function getAttrFile() {
1414}
1515
1616// Helper to create temp directory and run test
17- async function runTest ( files , callback ) {
17+ async function runTest ( files , callback , cache = true ) {
1818 const testDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'zero-ui-test' ) ) ;
1919 const originalCwd = process . cwd ( ) ;
2020
2121 try {
2222 process . chdir ( testDir ) ;
2323
2424 // Clear the global file cache to prevent stale entries from previous tests
25- try {
26- const astParsing = require ( '../../dist/postcss/ast-parsing.js' ) ;
27- if ( astParsing . clearCache ) {
25+ if ( cache ) {
26+ try {
27+ const astParsing = require ( '../../dist/postcss/ast-parsing.js' ) ;
2828 astParsing . clearCache ( ) ;
29+ } catch {
30+ // Cache clearing is best-effort
2931 }
30- } catch {
31- // Cache clearing is best-effort
3232 }
3333
3434 // Create test files
@@ -1150,145 +1150,3 @@ test('generated variants for initial value without setterFn', async () => {
11501150 }
11511151 ) ;
11521152} ) ;
1153- /*
1154- The following tests are for advanced edge cases
1155- --------------------------------------------------------------------------------------------
1156- ----------------------------------------------
1157- ----------------------------------------------
1158- ----------------------------------------------
1159- ----------------------------------------------
1160- ----------------------------------------------
1161- --------------------------------------------------------------------------------------------
1162- ----------------------------------------------
1163- ----------------------------------------------
1164- ----------------------------------------------
1165- ----------------------------------------------
1166- ----------------------------------------------
1167- ----------------------------------------------
1168- */
1169-
1170- test . skip ( 'handles all common setter patterns - full coverage sanity check - COMPLEX' , async ( ) => {
1171- await runTest (
1172- {
1173- 'app/component.tsx' : `
1174- import { useUI } from '@react-zero-ui/core';
1175-
1176- const DARK = 'dark';
1177- const LIGHT = 'light';
1178-
1179- function Component() {
1180- const [theme, setTheme] = useUI<'light' | 'dark' | 'contrast' | 'neon' | 'retro'>('theme', 'light');
1181- const [size, setSize] = useUI<'sm' | 'lg'>('size', 'sm');
1182-
1183- setTheme('dark'); // direct
1184- setTheme(DARK); // identifier
1185- setTheme(() => 'light'); // arrow fn
1186- setTheme(prev => prev === 'light' ? 'dark' : 'light'); // updater
1187- setTheme(prev => { if (a) return 'neon'; return 'retro'; }); // block
1188- setTheme(userPref || 'contrast'); // logical fallback
1189- setSize(SIZES.SMALL); // object constant
1190-
1191- return (
1192- <>
1193- <button onClick={() => setTheme('contrast')}>Contrast</button>
1194- <select onChange={e => setTheme(e.target.value)}>
1195- <option value="neon">Neon</option>
1196- <option value="retro">Retro</option>
1197- </select>
1198- </>
1199- );
1200- }
1201-
1202- const SIZES = {
1203- SMALL: 'sm',
1204- LARGE: 'lg'
1205- };
1206- ` ,
1207- } ,
1208- ( result ) => {
1209- console . log ( '\n📄 Full coverage test:' ) ;
1210-
1211- // ✅ things that MUST be included
1212- assert ( result . css . includes ( '@custom-variant theme-dark' ) ) ;
1213- assert ( result . css . includes ( '@custom-variant theme-light' ) ) ;
1214- assert ( result . css . includes ( '@custom-variant theme-contrast' ) ) ;
1215- assert ( result . css . includes ( '@custom-variant theme-neon' ) ) ;
1216- assert ( result . css . includes ( '@custom-variant theme-retro' ) ) ;
1217- assert ( result . css . includes ( '@custom-variant size-sm' ) ) ;
1218- assert ( result . css . includes ( '@custom-variant size-lg' ) ) ;
1219-
1220- // ❌ known misses: test exposes what won't work without resolution
1221- // assert(result.css.includes('@custom-variant theme-dynamic-from-e-target'));
1222- }
1223- ) ;
1224- } ) ;
1225-
1226- test ( 'performance with large files and many variants' , async ( ) => {
1227- // Generate a large file with many useUI calls
1228- const generateLargeFile = ( ) => {
1229- let content = `import { useUI } from '@react-zero-ui/core';\n\n` ;
1230-
1231- // Create many components with different state keys
1232- for ( let i = 0 ; i < 50 ; i ++ ) {
1233- const toggleInitial = i % 2 === 0 ? "'true'" : "'false'" ;
1234- content += `
1235- function Component${ i } () {
1236- const [state${ i } , setState${ i } ] = useUI('state-${ i } ', 'initial-${ i } ');
1237- const [toggle${ i } , setToggle${ i } ] = useUI('toggle-${ i } ', ${ toggleInitial } );
1238-
1239-
1240-
1241- return <div className="state-${ i } -initial-${ i } :bg-blue-500 state-${ i } -true:bg-red-500 state-${ i } -false:bg-green-500 toggle-${ i } -true:bg-yellow-500 toggle-${ i } -false:bg-purple-500 toggle-${ i } -test:bg-orange-500">Component ${ i } </div>;
1242- }
1243- ` ;
1244- }
1245-
1246- return content ;
1247- } ;
1248-
1249- const startTime = Date . now ( ) ;
1250-
1251- await runTest ( { 'app/large-file.jsx' : generateLargeFile ( ) } , ( result ) => {
1252- const endTime = Date . now ( ) ;
1253- const duration = endTime - startTime ;
1254-
1255- console . log ( `\n⏱️ Large file processing took: ${ duration } ms` ) ;
1256-
1257- // Should handle large files reasonably quickly (< 5 seconds)
1258- assert ( duration < 5000 , `Processing took too long: ${ duration } ms` ) ;
1259-
1260- // Should still extract all variants correctly
1261- assert ( result . css . includes ( '@custom-variant state-0-initial-0' ) ) ;
1262- assert ( result . css . includes ( '@custom-variant state-49-initial-49' ) ) ;
1263- assert ( result . css . includes ( '@custom-variant toggle-0-true' ) ) ;
1264- assert ( result . css . includes ( '@custom-variant toggle-0-false' ) ) ;
1265- } ) ;
1266- } ) ;
1267-
1268- test ( 'caching works correctly' , async ( ) => {
1269- const testFiles = {
1270- 'app/cached.jsx' : `
1271- import { useUI } from '@react-zero-ui/core';
1272-
1273- function Component() {
1274- const [theme, setTheme] = useUI('theme', 'light');
1275- return <div>Test</div>;
1276- }
1277- ` ,
1278- } ;
1279-
1280- // First run
1281- const start1 = Date . now ( ) ;
1282- await runTest ( testFiles , ( ) => { } ) ;
1283- const duration1 = Date . now ( ) - start1 ;
1284-
1285- // Second run with same files (should be faster due to caching)
1286- const start2 = Date . now ( ) ;
1287- await runTest ( testFiles , ( ) => { } ) ;
1288- const duration2 = Date . now ( ) - start2 ;
1289-
1290- console . log ( `\n📊 First run: ${ duration1 } ms, Second run: ${ duration2 } ms` ) ;
1291-
1292- // Note: This test might be flaky in CI, but useful for development
1293- // Second run should generally be faster, but timing can vary
1294- } ) ;
0 commit comments