29import * as
path from
'path';
30import * as
fs from
'fs/promises';
41suite(
'Extension Integration Test Suite', () => {
43 let testDocument:
vscode.TextDocument | undefined;
45 let testEditor:
vscode.TextEditor | undefined;
49 let extensionContext:
vscode.ExtensionContext;
58 suiteSetup(async () => {
60 tempDir = await
fs.mkdtemp(
path.join(require(
'os').tmpdir(),
'extension-test-'));
63 const possibleIds = [
'asperguide.asperheader',
'henryletellierfr.asperheader',
'asperheader'];
64 let extension:
vscode.Extension<any> | undefined;
66 for (
const id of possibleIds) {
67 extension =
vscode.extensions.getExtension(
id);
75 await extension.activate();
76 extensionContext = extension.exports?.context || {
77 extensionPath: extension.extensionPath,
81 update: () => Promise.resolve()
85 update: () => Promise.resolve(),
86 setKeysForSync: () => { }
91 console.log(
'Extension activation failed in test environment:', error);
96 extensionPath:
path.resolve(__dirname,
'..',
'..'),
100 update: () => Promise.resolve()
103 get: () => undefined,
104 update: () => Promise.resolve(),
105 setKeysForSync: () => { }
118 suiteTeardown(async () => {
121 await
fs.rmdir(tempDir, { recursive:
true }).
catch(() => { });
126 await
vscode.window.showTextDocument(testDocument);
127 await
vscode.commands.executeCommand(
'workbench.action.closeActiveEditor');
140 testDocument = undefined;
141 testEditor = undefined;
151 teardown(async () => {
154 await
vscode.commands.executeCommand(
'workbench.action.closeActiveEditor');
165 suite(
'Extension Lifecycle', () => {
170 test(
'should activate successfully', async () => {
172 const possibleIds = [
173 'asperguide.asperheader',
174 'henryletellierfr.asperheader',
178 let extension:
vscode.Extension<any> | undefined;
179 for (
const id of possibleIds) {
180 extension =
vscode.extensions.getExtension(
id);
190 assert.doesNotThrow(() => {
192 require(
'../extension');
193 },
'Extension module should be loadable');
197 assert.ok(extension,
'Extension should be loaded');
200 if (!extension.isActive) {
202 await extension.activate();
213 test(
'should register all expected commands', async () => {
214 const commands = await
vscode.commands.getCommands(
true);
216 const expectedCommands = [
226 for (
const expectedCommand of expectedCommands) {
228 commands.includes(expectedCommand),
229 `Command
'${expectedCommand}' should be registered`
238 test(
'should handle deactivation gracefully', () => {
240 assert.doesNotThrow(() => {
242 },
'Deactivation should not throw errors');
253 suite(
'Command Execution Tests', () => {
258 test(
'should execute helloWorld command without errors', async () => {
259 await
assert.doesNotReject(async () => {
261 },
'HelloWorld command should execute without errors');
268 test(
'should execute sayHelloWorld command with active editor', async () => {
270 const testContent =
'// Test file content\n';
271 const testFilePath =
path.join(tempDir,
'test.ts');
272 await
fs.writeFile(testFilePath, testContent);
274 const uri =
vscode.Uri.file(testFilePath);
275 testDocument = await
vscode.workspace.openTextDocument(uri);
276 testEditor = await
vscode.window.showTextDocument(testDocument);
278 const originalLength = testDocument.getText().length;
283 const newLength = testDocument.getText().length;
284 assert.ok(newLength > originalLength,
'Content should be added to the document');
291 test(
'should handle sayHelloWorld command with no active editor', async () => {
293 await
vscode.commands.executeCommand(
'workbench.action.closeAllEditors');
296 await
assert.doesNotReject(async () => {
298 },
'SayHelloWorld command should handle no active editor gracefully');
305 test(
'should execute injectHeader command', async () => {
306 await
assert.doesNotReject(async () => {
308 },
'InjectHeader command should execute without errors');
315 test(
'should execute refreshHeader command', async () => {
316 await
assert.doesNotReject(async () => {
318 },
'RefreshHeader command should execute without errors');
325 test(
'should execute darling command', async () => {
326 await
assert.doesNotReject(async () => {
328 },
'Darling command should execute without errors');
335 test(
'should execute author command', async () => {
336 await
assert.doesNotReject(async () => {
338 },
'Author command should execute without errors');
345 test(
'should execute displayRandomLogo command', async () => {
346 await
assert.doesNotReject(async () => {
348 },
'DisplayRandomLogo command should execute without errors');
359 suite(
'File Information Extraction', () => {
364 test(
'should extract file info from TypeScript file', async () => {
365 const testContent =
'const test: string = "hello";';
366 const testFilePath =
path.join(tempDir,
'test.ts');
367 await
fs.writeFile(testFilePath, testContent);
369 const uri =
vscode.Uri.file(testFilePath);
370 testDocument = await
vscode.workspace.openTextDocument(uri);
371 testEditor = await
vscode.window.showTextDocument(testDocument);
376 const documentText = testDocument.getText();
377 assert.ok(documentText.includes(
'.ts'),
'Should detect TypeScript file extension');
378 assert.ok(documentText.includes(
'test.ts'),
'Should detect correct filename');
385 test(
'should extract file info from Python file', async () => {
386 const testContent =
'print("hello world")';
387 const testFilePath =
path.join(tempDir,
'test.py');
388 await
fs.writeFile(testFilePath, testContent);
390 const uri =
vscode.Uri.file(testFilePath);
391 testDocument = await
vscode.workspace.openTextDocument(uri);
392 testEditor = await
vscode.window.showTextDocument(testDocument);
396 const documentText = testDocument.getText();
397 assert.ok(documentText.includes(
'.py'),
'Should detect Python file extension');
398 assert.ok(documentText.includes(
'test.py'),
'Should detect correct filename');
405 test(
'should handle files without extensions', async () => {
406 const testContent =
'Some content without extension';
407 const testFilePath =
path.join(tempDir,
'README');
408 await
fs.writeFile(testFilePath, testContent);
410 const uri =
vscode.Uri.file(testFilePath);
411 testDocument = await
vscode.workspace.openTextDocument(uri);
412 testEditor = await
vscode.window.showTextDocument(testDocument);
416 const documentText = testDocument.getText();
417 assert.ok(documentText.includes(
'README'),
'Should detect filename without extension');
427 suite(
'Document Save Integration', () => {
432 test(
'should handle document save events', async () => {
433 const testContent =
'// Initial content\n';
434 const testFilePath =
path.join(tempDir,
'savetest.js');
435 await
fs.writeFile(testFilePath, testContent);
437 const uri =
vscode.Uri.file(testFilePath);
438 testDocument = await
vscode.workspace.openTextDocument(uri);
439 testEditor = await
vscode.window.showTextDocument(testDocument);
442 await testEditor.edit(editBuilder => {
443 editBuilder.insert(
new vscode.Position(1, 0),
'console.log("test");\n');
447 await
assert.doesNotReject(async () => {
449 await testDocument.save();
451 },
'Document save should be handled without errors');
458 test(
'should prevent concurrent save operations', async () => {
459 const testContent =
'// Concurrent save test\n';
460 const testFilePath =
path.join(tempDir,
'concurrent.js');
461 await
fs.writeFile(testFilePath, testContent);
463 const uri =
vscode.Uri.file(testFilePath);
464 testDocument = await
vscode.workspace.openTextDocument(uri);
465 testEditor = await
vscode.window.showTextDocument(testDocument);
468 await testEditor.edit(editBuilder => {
469 editBuilder.insert(
new vscode.Position(1, 0),
'const test = true;\n');
473 const savePromises = testDocument ? [
479 await
assert.doesNotReject(async () => {
480 await Promise.all(savePromises);
481 },
'Concurrent saves should be handled safely');
491 suite(
'Workspace Management', () => {
496 test(
'should handle workspace without folders', () => {
498 assert.doesNotThrow(() => {
501 },
'Should handle workspace without folders');
508 test(
'should detect workspace folders when available', () => {
510 const workspaceFolders =
vscode.workspace.workspaceFolders;
511 if (workspaceFolders && workspaceFolders.length > 0) {
512 assert.ok(workspaceFolders[0].name,
'Should have workspace folder name');
523 suite(
'Error Handling and Edge Cases', () => {
528 test(
'should handle commands with invalid context gracefully', async () => {
530 await
vscode.commands.executeCommand(
'workbench.action.closeAllEditors');
533 await
assert.doesNotReject(async () => {
535 },
'Should handle refresh header without active document');
542 test(
'should handle file operations on read-only files', async () => {
544 const testContent =
'// Read-only test\n';
545 const testFilePath =
path.join(tempDir,
'readonly.js');
546 await
fs.writeFile(testFilePath, testContent);
548 const uri =
vscode.Uri.file(testFilePath);
549 testDocument = await
vscode.workspace.openTextDocument(uri);
550 testEditor = await
vscode.window.showTextDocument(testDocument);
553 await
assert.doesNotReject(async () => {
555 },
'Should handle file operations gracefully');
565 suite(
'Performance and Resource Management', () => {
570 test(
'should complete activation within reasonable time',
function () {
574 const extension =
vscode.extensions.getExtension(
'asperguide.asperheader');
575 if (extension && !extension.isActive) {
576 return extension.activate();
584 test(
'should handle multiple rapid command executions', async () => {
586 const commandPromises = [
588 vscode.commands.executeCommand(`${moduleName}.displayRandomLogo`),
590 vscode.commands.executeCommand(`${moduleName}.darling`)
593 await
assert.doesNotReject(async () => {
594 await Promise.all(commandPromises);
595 },
'Should handle multiple rapid command executions');
602 test(
'should clean up resources properly', () => {
604 assert.doesNotThrow(() => {
606 },
'Resource cleanup should not throw errors');
616 suite(
'Module Integration Tests', () => {
621 test(
'should have properly initialized all modules', async () => {
623 const moduleCommands = [
630 for (
const command of moduleCommands) {
631 await
assert.doesNotReject(async () => {
632 await
vscode.commands.executeCommand(command);
633 }, `Module integration test
for ${command} should not fail`);
641 test(
'should handle asset loading failures gracefully', async () => {
643 await
assert.doesNotReject(async () => {
647 },
'Should handle asset loading issues gracefully');
export const moduleName
Module identifier used in package.json and extension marketplace.
import *as vscode from vscode
import *as path from path
import *as assert from assert
function export deactivate()
Extension cleanup and deactivation handler.
function async activate(context:vscode.ExtensionContext)
Main extension activation entry point.
export const Record< string,(...args:any[])=> string