Skip to content

Commit f2a5585

Browse files
committed
Merge branch 'feature/testability' into feature/summary_chart
2 parents 6b57374 + 417c528 commit f2a5585

2 files changed

Lines changed: 121 additions & 1 deletion

File tree

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
"watch": "tsc -watch -p ./",
4949
"pretest": "npm run compile && npm run lint",
5050
"lint": "eslint src --ext ts",
51-
"test": "node ./out/test/runTest.js"
51+
"test": "node ./out/test/runTest.js",
52+
"generate-test-data": "node scripts/generate-test-data.js",
53+
"refresh-extension": "code --uninstall-extension noorashuvo.simple-coding-time-tracker && vsce package && code --install-extension $(npm pack --quiet)"
5254
},
5355
"devDependencies": {
5456
"@types/vscode": "^1.60.0",

scripts/generate-test-data.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const os = require('os');
4+
5+
// Simple list of professional project names
6+
const projects = [
7+
'React Dashboard',
8+
'Node.js API',
9+
'Mobile App',
10+
'Database Migration',
11+
'UI Components',
12+
'Backend Service',
13+
'Documentation',
14+
'Testing Suite',
15+
'DevOps Setup',
16+
'Data Analytics'
17+
];
18+
19+
// Function to generate test data
20+
function generateTestData() {
21+
const today = new Date();
22+
const entries = [];
23+
24+
// Generate data for the last 90 days
25+
for (let i = 0; i < 90; i++) {
26+
const date = new Date(today);
27+
date.setDate(date.getDate() - i);
28+
const dateString = date.toISOString().split('T')[0];
29+
30+
// Generate 1-3 entries per day
31+
const entriesCount = Math.floor(Math.random() * 3) + 1;
32+
33+
for (let j = 0; j < entriesCount; j++) {
34+
const project = projects[Math.floor(Math.random() * projects.length)];
35+
// Random time between 30 minutes and 4 hours (in minutes)
36+
const timeSpent = Math.floor(Math.random() * 210) + 30;
37+
38+
entries.push({
39+
date: dateString,
40+
project,
41+
timeSpent
42+
});
43+
}
44+
}
45+
46+
// Add some special test cases
47+
const yesterday = new Date(today);
48+
yesterday.setDate(yesterday.getDate() - 1);
49+
const yesterdayString = yesterday.toISOString().split('T')[0];
50+
const todayString = today.toISOString().split('T')[0];
51+
52+
// Add a long session for yesterday
53+
entries.push({
54+
date: yesterdayString,
55+
project: 'Node.js API',
56+
timeSpent: 480 // 8 hours
57+
});
58+
59+
// Add multiple sessions for today
60+
entries.push({
61+
date: todayString,
62+
project: 'React Dashboard',
63+
timeSpent: 120 // 2 hours
64+
});
65+
entries.push({
66+
date: todayString,
67+
project: 'Documentation',
68+
timeSpent: 60 // 1 hour
69+
});
70+
71+
return entries;
72+
}
73+
74+
// Function to update the global state
75+
function updateGlobalState() {
76+
const vscodeDir = path.join(os.homedir(), '.vscode');
77+
const globalStoragePath = path.join(vscodeDir, 'globalStorage');
78+
const extensionId = 'noorashuvo.simple-coding-time-tracker';
79+
const extensionStoragePath = path.join(globalStoragePath, extensionId);
80+
const storagePath = path.join(extensionStoragePath, 'globalState.json');
81+
82+
try {
83+
console.log('Generating test data...');
84+
const testData = generateTestData();
85+
console.log(`Generated ${testData.length} time entries`);
86+
87+
// Create directories if they don't exist
88+
if (!fs.existsSync(vscodeDir)) {
89+
fs.mkdirSync(vscodeDir);
90+
}
91+
if (!fs.existsSync(globalStoragePath)) {
92+
fs.mkdirSync(globalStoragePath);
93+
}
94+
if (!fs.existsSync(extensionStoragePath)) {
95+
fs.mkdirSync(extensionStoragePath);
96+
}
97+
98+
// Read existing global state or create new one
99+
let globalState = {};
100+
if (fs.existsSync(storagePath)) {
101+
globalState = JSON.parse(fs.readFileSync(storagePath, 'utf8'));
102+
}
103+
104+
// Update the timeEntries
105+
globalState.timeEntries = testData;
106+
107+
// Write back to file
108+
fs.writeFileSync(storagePath, JSON.stringify(globalState, null, 2));
109+
console.log('\n✅ Test data has been generated and saved successfully!');
110+
console.log(`📁 Data file location: ${storagePath}`);
111+
console.log('🔄 Please reload VS Code to see the changes');
112+
} catch (error) {
113+
console.error('❌ Error updating global state:', error);
114+
}
115+
}
116+
117+
// Run the script
118+
updateGlobalState();

0 commit comments

Comments
 (0)