Skip to content

Commit b21ef94

Browse files
committed
fix: added tests to eslint, fixed test errors
1 parent 039de9b commit b21ef94

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const browserGlobals = {
3232

3333
export default [
3434
/* 1 - never lint generated / vendor files */
35-
{ ignores: ['**/node_modules/**', '**/dist/**', '**/.next/**', '**/*.test.*', '**/*.spec.*', 'tests/**', 'eslint.config.js'] },
35+
{ ignores: ['**/node_modules/**', '**/dist/**', '**/.next/**', 'eslint.config.js'] },
3636

3737
/* 2 - baseline rules */
3838
js.configs.recommended,

packages/core/__tests__/unit/cli.test.cjs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function cleanupTestDir(testDir) {
3131
fs.rmdirSync(fullPath);
3232
} catch (e) {
3333
// Ignore
34+
console.log(`Error deleting directory ${fullPath}: ${e.message}`);
3435
}
3536
} else {
3637
try {
@@ -128,6 +129,8 @@ test('CLI script uses existing package.json if it exists', async () => {
128129
// Run CLI (this will timeout on npm install, but that's ok for this test)
129130
const result = await runCLIScript(testDir, 5000).catch(err => {
130131
// We expect this to timeout/fail during npm install
132+
console.log('CLI run resulted in:', err.message);
133+
console.log('CLI run result:', result);
131134
return { timedOut: true };
132135
});
133136

@@ -190,7 +193,7 @@ test('CLI script installs correct dependencies', async () => {
190193

191194
try {
192195
// Run CLI script
193-
const result = await runCLIScript(testDir, 10000).catch(err => {
196+
await runCLIScript(testDir, 10000).catch(err => {
194197
console.log('CLI run resulted in:', err.message);
195198
return { error: err.message };
196199
});
@@ -237,7 +240,7 @@ test('CLI script handles different target directories', async () => {
237240
// Run CLI with subdirectory target
238241
const binScript = path.resolve(__dirname, '../../../cli/bin.js');
239242

240-
const result = await new Promise((resolve, reject) => {
243+
await new Promise((resolve, reject) => {
241244
const child = spawn('node', [binScript, 'my-project'], { cwd: baseTestDir, stdio: ['pipe', 'pipe', 'pipe'] });
242245

243246
const timer = setTimeout(() => {
@@ -314,7 +317,10 @@ test('CLI script imports and executes library CLI', async () => {
314317
process.env.PATH = `${testDir}:${originalPath}`;
315318

316319
try {
317-
const result = await runCLIScript(testDir, 10000);
320+
const result = await runCLIScript(testDir, 10000).catch(err => {
321+
console.log('CLI run resulted in:', err.message);
322+
return { error: err.message };
323+
});
318324

319325
// Check that CLI was executed
320326
assert(
@@ -464,7 +470,7 @@ fi
464470
// Run CLI without any arguments (should default to current directory)
465471
const binScript = path.resolve(__dirname, '../../../cli/bin.js');
466472

467-
const result = await new Promise((resolve, reject) => {
473+
await new Promise((resolve, reject) => {
468474
const child = spawn('node', [binScript], {
469475
// No target directory argument
470476
cwd: testDir,
@@ -508,7 +514,7 @@ test('CLI script handles invalid target directory', async () => {
508514
// Try to run CLI with a non-existent directory
509515
const binScript = path.resolve(__dirname, '../../../cli/bin.js');
510516

511-
const result = await new Promise((resolve, reject) => {
517+
const result = await new Promise(resolve => {
512518
const child = spawn('node', [binScript, 'non-existent-dir'], { cwd: testDir, stdio: ['pipe', 'pipe', 'pipe'] });
513519

514520
let stderr = '';
@@ -719,7 +725,7 @@ test('CLI script validates and preserves existing package.json fields', async ()
719725
fs.writeFileSync(packageJsonPath, JSON.stringify(complexPackageJson, null, 2));
720726

721727
// Run CLI with timeout to avoid full installation
722-
const result = await runCLIScript(testDir, 3000).catch(err => ({ timedOut: true }));
728+
await runCLIScript(testDir, 3000).catch(() => ({ timedOut: true }));
723729

724730
// Verify all original fields are preserved
725731
const updatedPackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));

packages/core/__tests__/unit/index.test.cjs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ async function runTest(files, callback) {
4848

4949
test('generates body attributes file correctly', async () => {
5050
await runTest(
51-
'attributes',
5251
{
5352
'app/test.jsx': `
5453
import { useUI } from 'react-zero-ui';
@@ -83,7 +82,6 @@ test('generates body attributes file correctly', async () => {
8382

8483
test('generates body attributes file correctly when kebab-case is used', async () => {
8584
await runTest(
86-
'attributes',
8785
{
8886
'app/test.jsx': `
8987
import { useUI } from 'react-zero-ui';
@@ -120,7 +118,6 @@ test('generates body attributes file correctly when kebab-case is used', async (
120118

121119
test('handles TypeScript generic types', async () => {
122120
await runTest(
123-
'typescript-generics',
124121
{
125122
'src/component.tsx': `
126123
import { useUI } from 'react-zero-ui';
@@ -150,7 +147,6 @@ test('handles TypeScript generic types', async () => {
150147

151148
test('detects JavaScript setValue calls', async () => {
152149
await runTest(
153-
'javascript-detection',
154150
{
155151
'src/modal.js': `
156152
import { useUI } from 'react-zero-ui';
@@ -191,7 +187,7 @@ test('detects JavaScript setValue calls', async () => {
191187

192188
test('handles boolean values', async () => {
193189
await runTest(
194-
'boolean-values',
190+
195191
{
196192
'app/toggle.tsx': `
197193
import { useUI } from 'react-zero-ui';
@@ -224,7 +220,7 @@ test('handles boolean values', async () => {
224220

225221
test('handles kebab-case conversion', async () => {
226222
await runTest(
227-
'kebab-case',
223+
228224
{
229225
'src/styles.jsx': `
230226
import { useUI } from 'react-zero-ui';
@@ -262,7 +258,7 @@ test('handles kebab-case conversion', async () => {
262258

263259
test('handles conditional expressions', async () => {
264260
await runTest(
265-
'conditionals',
261+
266262
{
267263
'app/conditional.jsx': `
268264
import { useUI } from 'react-zero-ui';
@@ -299,7 +295,7 @@ test('handles conditional expressions', async () => {
299295

300296
test('handles multiple files and deduplication', async () => {
301297
await runTest(
302-
'multiple-files',
298+
303299
{
304300
'src/header.jsx': `
305301
import { useUI } from 'react-zero-ui';
@@ -341,7 +337,7 @@ test('handles multiple files and deduplication', async () => {
341337

342338
test('handles parsing errors gracefully', async () => {
343339
await runTest(
344-
'parse-errors',
340+
345341
{
346342
'src/valid.jsx': `
347343
import { useUI } from 'react-zero-ui';
@@ -376,7 +372,7 @@ test('throws on empty string initial value', () => {
376372

377373
test('valid edge cases: underscores + missing initial', async () => {
378374
await runTest(
379-
'valid-edge',
375+
380376
{
381377
'src/edge.jsx': `
382378
import { useUI } from 'react-zero-ui';
@@ -403,7 +399,7 @@ test('watches for file changes', async () => {
403399
}
404400

405401
await runTest(
406-
'file-watching',
402+
407403
{
408404
'src/initial.jsx': `
409405
import { useUI } from 'react-zero-ui';
@@ -442,7 +438,6 @@ test('watches for file changes', async () => {
442438

443439
test('ignores node_modules and hidden directories', async () => {
444440
await runTest(
445-
'ignored-dirs',
446441
{
447442
'src/valid.jsx': `
448443
import { useUI } from 'react-zero-ui';
@@ -477,7 +472,7 @@ test('ignores node_modules and hidden directories', async () => {
477472

478473
test('handles deeply nested file structures', async () => {
479474
await runTest(
480-
'deep-nesting',
475+
481476
{
482477
'src/features/auth/components/login/LoginForm.jsx': `
483478
import { useUI } from 'react-zero-ui';
@@ -496,7 +491,7 @@ test('handles deeply nested file structures', async () => {
496491

497492
test('handles complex TypeScript scenarios', async () => {
498493
await runTest(
499-
'complex-typescript',
494+
500495
{
501496
'src/complex.tsx': `
502497
import { useUI } from 'react-zero-ui';
@@ -547,7 +542,7 @@ test('handles large projects efficiently', async function () {
547542

548543
const startTime = Date.now();
549544

550-
await runTest('performance', files, result => {
545+
await runTest(files, result => {
551546
const endTime = Date.now();
552547
const duration = endTime - startTime;
553548

@@ -563,7 +558,6 @@ test('handles large projects efficiently', async function () {
563558

564559
test('handles special characters in values', async () => {
565560
await runTest(
566-
'special-chars',
567561
{
568562
'src/special.jsx': `
569563
import { useUI } from 'react-zero-ui';
@@ -590,7 +584,6 @@ test('handles special characters in values', async () => {
590584
test('handles concurrent file modifications', async () => {
591585
// Test that rapid changes don't cause issues
592586
await runTest(
593-
'concurrent',
594587
{
595588
'src/rapid.jsx': `
596589
import { useUI } from 'react-zero-ui';
@@ -800,7 +793,7 @@ test('patchConfigAlias - config file patching', async t => {
800793
}
801794
});
802795

803-
test('patchConfigAlias prefers tsconfig.json over jsconfig.json', async () => {
796+
await t.test('patchConfigAlias prefers tsconfig.json over jsconfig.json', async () => {
804797
const testDir = fs.mkdtempSync(path.join(os.tmpdir(), 'zero-ui-config-test'));
805798
const originalCwd = process.cwd();
806799

0 commit comments

Comments
 (0)