voltjs-framework 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1265 -0
- package/bin/volt.js +139 -0
- package/package.json +56 -0
- package/src/api/graphql.js +399 -0
- package/src/api/rest.js +204 -0
- package/src/api/websocket.js +285 -0
- package/src/cli/build.js +111 -0
- package/src/cli/create.js +371 -0
- package/src/cli/db.js +106 -0
- package/src/cli/dev.js +114 -0
- package/src/cli/generate.js +278 -0
- package/src/cli/lint.js +172 -0
- package/src/cli/routes.js +118 -0
- package/src/cli/start.js +42 -0
- package/src/cli/test.js +138 -0
- package/src/core/app.js +701 -0
- package/src/core/config.js +232 -0
- package/src/core/middleware.js +133 -0
- package/src/core/plugins.js +88 -0
- package/src/core/react-renderer.js +244 -0
- package/src/core/renderer.js +337 -0
- package/src/core/router.js +183 -0
- package/src/database/index.js +461 -0
- package/src/database/migration.js +192 -0
- package/src/database/model.js +285 -0
- package/src/database/query.js +394 -0
- package/src/database/seeder.js +89 -0
- package/src/index.js +156 -0
- package/src/security/auth.js +425 -0
- package/src/security/cors.js +80 -0
- package/src/security/csrf.js +125 -0
- package/src/security/encryption.js +110 -0
- package/src/security/helmet.js +103 -0
- package/src/security/index.js +75 -0
- package/src/security/rateLimit.js +119 -0
- package/src/security/sanitizer.js +113 -0
- package/src/security/xss.js +110 -0
- package/src/ui/component.js +224 -0
- package/src/ui/reactive.js +503 -0
- package/src/ui/template.js +448 -0
- package/src/utils/cache.js +216 -0
- package/src/utils/collection.js +772 -0
- package/src/utils/cron.js +213 -0
- package/src/utils/date.js +223 -0
- package/src/utils/events.js +181 -0
- package/src/utils/excel.js +482 -0
- package/src/utils/form.js +547 -0
- package/src/utils/hash.js +121 -0
- package/src/utils/http.js +461 -0
- package/src/utils/logger.js +186 -0
- package/src/utils/mail.js +347 -0
- package/src/utils/paginator.js +179 -0
- package/src/utils/pdf.js +417 -0
- package/src/utils/queue.js +199 -0
- package/src/utils/schema.js +985 -0
- package/src/utils/sms.js +243 -0
- package/src/utils/storage.js +348 -0
- package/src/utils/string.js +236 -0
- package/src/utils/validation.js +318 -0
package/src/cli/test.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VoltJS CLI — `volt test`
|
|
3
|
+
* Simple built-in test runner (zero dependencies).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
const c = {
|
|
12
|
+
reset: '\x1b[0m', bold: '\x1b[1m', dim: '\x1b[2m',
|
|
13
|
+
red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', cyan: '\x1b[36m',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Simple test framework
|
|
17
|
+
const suites = [];
|
|
18
|
+
let currentSuite = null;
|
|
19
|
+
|
|
20
|
+
global.describe = function(name, fn) {
|
|
21
|
+
currentSuite = { name, tests: [], before: null, after: null, passed: 0, failed: 0 };
|
|
22
|
+
suites.push(currentSuite);
|
|
23
|
+
fn();
|
|
24
|
+
currentSuite = null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
global.it = function(name, fn) {
|
|
28
|
+
if (currentSuite) {
|
|
29
|
+
currentSuite.tests.push({ name, fn });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
global.test = global.it;
|
|
34
|
+
|
|
35
|
+
global.beforeEach = function(fn) {
|
|
36
|
+
if (currentSuite) currentSuite.before = fn;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
global.afterEach = function(fn) {
|
|
40
|
+
if (currentSuite) currentSuite.after = fn;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
module.exports = async function testRunner(args) {
|
|
44
|
+
const cwd = process.cwd();
|
|
45
|
+
const testDir = path.join(cwd, 'tests');
|
|
46
|
+
const pattern = args[0]; // Optional filter
|
|
47
|
+
|
|
48
|
+
console.log(`${c.cyan}${c.bold}⚡ VoltJS Test Runner${c.reset}\n`);
|
|
49
|
+
|
|
50
|
+
// Find test files
|
|
51
|
+
const testFiles = [];
|
|
52
|
+
|
|
53
|
+
if (fs.existsSync(testDir)) {
|
|
54
|
+
findTestFiles(testDir, testFiles);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Also check for *.test.js in root
|
|
58
|
+
const rootFiles = fs.readdirSync(cwd).filter(f => f.endsWith('.test.js'));
|
|
59
|
+
for (const f of rootFiles) {
|
|
60
|
+
testFiles.push(path.join(cwd, f));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (testFiles.length === 0) {
|
|
64
|
+
console.log(` ${c.dim}No test files found. Create tests in tests/ directory.${c.reset}`);
|
|
65
|
+
console.log(` ${c.dim}Example: tests/app.test.js${c.reset}`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Filter if pattern provided
|
|
70
|
+
const filteredFiles = pattern
|
|
71
|
+
? testFiles.filter(f => f.includes(pattern))
|
|
72
|
+
: testFiles;
|
|
73
|
+
|
|
74
|
+
// Load test files
|
|
75
|
+
for (const file of filteredFiles) {
|
|
76
|
+
try {
|
|
77
|
+
require(file);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
console.error(` ${c.red}✗ Error loading ${path.relative(cwd, file)}: ${err.message}${c.reset}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Run tests
|
|
84
|
+
let totalPassed = 0;
|
|
85
|
+
let totalFailed = 0;
|
|
86
|
+
let totalTime = 0;
|
|
87
|
+
|
|
88
|
+
for (const suite of suites) {
|
|
89
|
+
console.log(` ${c.bold}${suite.name}${c.reset}`);
|
|
90
|
+
|
|
91
|
+
for (const test of suite.tests) {
|
|
92
|
+
const start = performance.now();
|
|
93
|
+
try {
|
|
94
|
+
if (suite.before) await suite.before();
|
|
95
|
+
await test.fn();
|
|
96
|
+
if (suite.after) await suite.after();
|
|
97
|
+
|
|
98
|
+
const duration = (performance.now() - start).toFixed(1);
|
|
99
|
+
totalTime += parseFloat(duration);
|
|
100
|
+
suite.passed++;
|
|
101
|
+
totalPassed++;
|
|
102
|
+
console.log(` ${c.green}✓${c.reset} ${test.name} ${c.dim}(${duration}ms)${c.reset}`);
|
|
103
|
+
} catch (err) {
|
|
104
|
+
const duration = (performance.now() - start).toFixed(1);
|
|
105
|
+
totalTime += parseFloat(duration);
|
|
106
|
+
suite.failed++;
|
|
107
|
+
totalFailed++;
|
|
108
|
+
console.log(` ${c.red}✗${c.reset} ${test.name} ${c.dim}(${duration}ms)${c.reset}`);
|
|
109
|
+
console.log(` ${c.red}${err.message}${c.reset}`);
|
|
110
|
+
if (err.actual !== undefined && err.expected !== undefined) {
|
|
111
|
+
console.log(` ${c.dim}Expected: ${c.green}${JSON.stringify(err.expected)}${c.reset}`);
|
|
112
|
+
console.log(` ${c.dim}Actual: ${c.red}${JSON.stringify(err.actual)}${c.reset}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
console.log('');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Summary
|
|
120
|
+
const total = totalPassed + totalFailed;
|
|
121
|
+
console.log(` ${c.bold}Results:${c.reset} ${c.green}${totalPassed} passed${c.reset}${totalFailed > 0 ? `, ${c.red}${totalFailed} failed${c.reset}` : ''} ${c.dim}(${total} total in ${totalTime.toFixed(0)}ms)${c.reset}\n`);
|
|
122
|
+
|
|
123
|
+
if (totalFailed > 0) {
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
function findTestFiles(dir, files) {
|
|
129
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
130
|
+
for (const entry of entries) {
|
|
131
|
+
const fullPath = path.join(dir, entry.name);
|
|
132
|
+
if (entry.isDirectory()) {
|
|
133
|
+
findTestFiles(fullPath, files);
|
|
134
|
+
} else if (entry.name.endsWith('.test.js') || entry.name.endsWith('.spec.js')) {
|
|
135
|
+
files.push(fullPath);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|