Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ dist/
public/
test-resources/
.DS_Store

.nyc_output/
64 changes: 64 additions & 0 deletions build/run-instrument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/

import { mkdirSync, readFileSync, statSync, writeFileSync } from 'fs';
import * as glob from 'glob';
import { createInstrumenter } from 'istanbul-lib-instrument';
import * as path from 'path';

/* eslint-disable no-console */
console.log('Instrumenting files...');

const instrumenter = createInstrumenter({
coverageVariable: '__coverage__',
embedSource: true, // Embed the source code into the instrumented file
});

// Find the Extension root directory
console.log(`Script File: ${__filename}`);
console.log(`Script Dir: ${__dirname}`);
const extDir = path.resolve(__dirname, __dirname.endsWith('out/build') ? '../../' : '../');
console.log(`Extension Root dir: ${extDir}`);

// Define the source and output directories
const sourceDir = path.resolve(extDir, 'out/src-orig'); // Original source directory
const outputDir = path.resolve(extDir, 'out/src'); // Instrumented files will be saved here

console.log('Source dir: ', sourceDir);
console.log('Output dir: ', outputDir);

// Ensure the output directory exists
mkdirSync(outputDir, { recursive: true });

// Use glob to match all JavaScript files in the source directory
const files = glob.sync(path.join(sourceDir, '**/*'));
// Loop over each file and instrument it

files.forEach((file) => {
process.stdout.write(`Instrumenting: ${file}... `);

// Get the relative path of the file and write the instrumented code to the output directory
const relativePath = path.relative(sourceDir, file);
const outputPath = path.join(outputDir, relativePath);

// Ensure the directory exists
mkdirSync(path.dirname(outputPath), { recursive: true });

const stats = statSync(file);
if (stats.isDirectory()) {
console.log('Directory');
} else if (stats.isFile()) {
const code = readFileSync(file, 'utf8');
const isJsFile = /\.js$/i.test(file);
const instrumentedCode = isJsFile ? instrumenter.instrumentSync(code, file) : code;


// Write the instrumented file
writeFileSync(outputPath, instrumentedCode, 'utf8');
console.log(isJsFile ? 'Done' : 'Skipped');
}
});

console.log('Files have been instrumented.');
103 changes: 88 additions & 15 deletions build/run-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import * as etest from '@vscode/test-electron';
import * as path from 'path';
import * as configData from '../package.json';

/**
* Run mocha tests from project's tests folder.
Expand All @@ -13,25 +14,97 @@ import * as path from 'path';
*/
async function main(): Promise<void> {
const [, , tests, extension = ''] = process.argv;
const extensionRootPath = path.resolve(__dirname, '../../');
const extensionRootPath = path.resolve(__dirname, __dirname.endsWith('out/build') ? '../../' : '../');
const extensionDevelopmentPath = path.resolve(extensionRootPath, extension);
const extensionTestsPath = path.resolve(extensionRootPath, 'out', 'test', tests);
const integrationWorkspacePath = path.resolve(extensionRootPath, 'test', 'fixtures', 'components', 'components.code-workspace');
const unitTestWorkspacePath = path.resolve(extensionRootPath, 'test', 'fixtures', 'components', 'empty.code-workspace');
try {
await etest.runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [
tests === 'integration' ? integrationWorkspacePath : unitTestWorkspacePath,
'--disable-workspace-trust',
],
});
} catch (err) {
// eslint-disable-next-line no-console
console.error(`Failed to run tests: ${err}`);
process.exit(1);

/* eslint-disable no-console */
console.info(`${__filename}: Started`);

console.info(`${path.basename(__filename)}: __dirname: ${__dirname}`);
console.info(`${path.basename(__filename)}: extensionRootPath: ${extensionRootPath}`);
console.info(`${path.basename(__filename)}: extensionDevelopmentPath: ${extensionDevelopmentPath}`);
console.info(`${path.basename(__filename)}: extensionTestsPath: ${extensionTestsPath}`);
console.info(`${path.basename(__filename)}: integrationWorkspacePath: ${integrationWorkspacePath}`);
console.info(`${path.basename(__filename)}: unitTestWorkspacePath: ${unitTestWorkspacePath}`);

console.info(`${path.basename(__filename)}: NYC config vales:`);
console.log('NYC include paths:', path.resolve('../src/**/*'));
console.log('NYC report-dir:', process.env.NYC_REPORT_DIR || 'coverage (default)');
console.log('NYC temp-dir:', process.env.NYC_TEMP_DIR || '.nyc_output (default)');


const boolPattern = /^(true|1|yes)$/i;
const verbose = boolPattern.test(process.env.VERBOSE);

/* eslint-disable no-console */
if (process.env.COVERAGE) {
console.log(`Running nyc as part of the ${tests} tests execution...`)
// const { instrument } = require('istanbul-lib-instrument');
// const __instrumenter = new Instrumenter();

const nyc = require('nyc');
// const nycConfig = {
// cwd: path.resolve(__dirname),
// require: ['ts-node/register'],
// extension: ['.ts'],
// reporter: ['lcov', 'text-summary'],
// };
const nycConfig = configData.nyc;
const nycInstance = new nyc(nycConfig);

nycInstance.wrap();

// // // Now run your tests with the Electron runner
// // void (async () => {
// // try {
// // const result = await etest.runTests({
// // extensionDevelopmentPath,
// // extensionTestsPath,
// // launchArgs: [
// // tests === 'integration' ? integrationWorkspacePath : unitTestWorkspacePath,
// // '--disable-workspace-trust',
// // ],
// // });

// // console.error(`Run tests spawn result: ${result}`);
// // process.exit(result);
// // } catch (err) {
// // console.error(`Failed to run tests: ${err}`);
// // process.exit(1);
// // }
// // })();
} else {
console.log(`Running the ${tests} tests...`)
}
try {
const result = await etest.runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [
tests === 'integration' ? integrationWorkspacePath : unitTestWorkspacePath,
'--disable-workspace-trust',
verbose ? '--verbose' : ''
],
});

// eslint-disable-next-line no-console
console.error(`Run tests spawn result: ${result}`);
process.exit(result);
} catch (err) {
// eslint-disable-next-line no-console
console.error(`Failed to run tests: ${err}`);
process.exit(1);
}
// }
}

void main();
// void main();

main().catch((err) => {
// eslint-disable-next-line no-console
console.error('Failed to run tests:', err);
process.exit(1);
});
5 changes: 4 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export default [
'vars': 'local',
'args': 'none', // Check args after they're used
'caughtErrors': 'none', // Disable checking for caught errors
'varsIgnorePattern': '^_',
"argsIgnorePattern": "^_",
}
],
'@typescript-eslint/no-explicit-any': 'warn',
Expand Down Expand Up @@ -173,9 +175,10 @@ export default [
'out',
'.vscode-test',
'.yarn',
'.*',
'images',
'doc/images',
'__coverage__',
'.nyc_output',
'coverage',
'public/dist',
'*.min.js',
Expand Down
Loading
Loading