-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathtest-local.js
More file actions
executable file
Β·129 lines (110 loc) Β· 4.27 KB
/
test-local.js
File metadata and controls
executable file
Β·129 lines (110 loc) Β· 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env node
/**
* Quick script to test TypeScript project generation locally
* Usage: node test-local.js
*/
const path = require('path');
const fs = require('fs');
const { TemplateService, TemplateType } = require('./lib');
// Configure test directory (change this to wherever you want)
const TEST_DIR = process.env.TEST_DIR || '/tmp/sf-template-tests';
const PROJECTS_TO_TEST = [
{ name: 'ts-standard', template: 'standard', lwcLanguage: 'typescript' },
{ name: 'ts-empty', template: 'empty', lwcLanguage: 'typescript' },
{ name: 'js-standard', template: 'standard', lwcLanguage: 'javascript' },
{ name: 'js-empty', template: 'empty', lwcLanguage: undefined }, // Test without lwcLanguage
];
async function testProjectGeneration() {
console.log('π§ͺ Testing TypeScript Project Generation\n');
console.log(`π Test directory: ${TEST_DIR}\n`);
// Clean up and create test directory
if (fs.existsSync(TEST_DIR)) {
console.log('π§Ή Cleaning up previous tests...');
fs.rmSync(TEST_DIR, { recursive: true });
}
fs.mkdirSync(TEST_DIR, { recursive: true });
const templateService = TemplateService.getInstance();
const results = [];
for (const project of PROJECTS_TO_TEST) {
console.log(
`\nπ¦ Generating: ${project.name} (${project.template}, ${
project.lwcLanguage || 'default'
})`
);
try {
await templateService.create(TemplateType.Project, {
projectname: project.name,
template: project.template,
defaultpackagedir: 'force-app',
manifest: false,
ns: '',
loginurl: 'https://login.salesforce.com',
lwcLanguage: project.lwcLanguage,
outputdir: TEST_DIR,
});
// Verify key files
const projectPath = path.join(TEST_DIR, project.name);
const checks = {
'sfdx-project.json': fs.existsSync(
path.join(projectPath, 'sfdx-project.json')
),
'package.json': fs.existsSync(path.join(projectPath, 'package.json')),
'tsconfig.json': fs.existsSync(path.join(projectPath, 'tsconfig.json')),
'force-app': fs.existsSync(path.join(projectPath, 'force-app')),
};
// Check sfdx-project.json content
const sfdxProject = JSON.parse(
fs.readFileSync(path.join(projectPath, 'sfdx-project.json'), 'utf8')
);
const hasLwcLanguage = !!sfdxProject.defaultLwcLanguage;
console.log(` β
Project created at: ${projectPath}`);
console.log(
` β
sfdx-project.json: ${checks['sfdx-project.json'] ? 'β' : 'β'}`
);
console.log(` β
package.json: ${checks['package.json'] ? 'β' : 'β'}`);
console.log(
` ${checks['tsconfig.json'] ? 'β
' : 'βͺ'} tsconfig.json: ${
checks['tsconfig.json'] ? 'β' : 'β (expected for JS)'
}`
);
console.log(
` ${hasLwcLanguage ? 'β
' : 'βͺ'} defaultLwcLanguage: ${
hasLwcLanguage ? sfdxProject.defaultLwcLanguage : '(not set)'
}`
);
results.push({ ...project, success: true, checks, hasLwcLanguage });
} catch (error) {
console.error(` β Error: ${error.message}`);
results.push({ ...project, success: false, error: error.message });
}
}
// Summary
console.log('\nβββββββββββββββββββββββββββββββββββββββββββ');
console.log('π Test Summary\n');
const passed = results.filter((r) => r.success).length;
const failed = results.filter((r) => !r.success).length;
console.log(`β
Passed: ${passed}/${PROJECTS_TO_TEST.length}`);
if (failed > 0) {
console.log(`β Failed: ${failed}/${PROJECTS_TO_TEST.length}`);
}
console.log('\nπ Generated projects:');
results.forEach((r) => {
if (r.success) {
console.log(` ${path.join(TEST_DIR, r.name)}`);
}
});
console.log('\nπ§Ή To clean up:');
console.log(` rm -rf ${TEST_DIR}`);
console.log('βββββββββββββββββββββββββββββββββββββββββββ\n');
return results;
}
// Run tests
testProjectGeneration()
.then(() => {
console.log('β¨ Tests completed!');
process.exit(0);
})
.catch((error) => {
console.error('β Test failed:', error);
process.exit(1);
});