Skip to content
Open
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
3 changes: 3 additions & 0 deletions qt-cpp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,17 @@
"tsc-test": "npm run compile && npm run build-test && cd ./out/test/ && node runTest.js",
"prepare-vsix": "npm --prefix ../qt-core run package",
"run-test-build": "cd ./out/test/ && node runTest.build.js",
"run-test-presets": "cd ./out/test/ && node runTest.presets.js",
"natvis:golden:update": "npm run compile-test && cd ./out/test/ && cross-env UPDATE_NATVIS_GOLDEN=1 QT_TEST_QT_ROOT=${npm_config_qt_root:-$QT_TEST_QT_ROOT} node runTest.natvis.js",
"run-test-natvis": "cd ./out/test/ && node runTest.natvis.js",
"run-test": "cd ./out/test/ && node runTest.js",
"test:only:natvis": "npm run compile-test && npm run run-test-natvis --",
"test:only:build": "npm run compile-test && npm run run-test-build --",
"test:only:presets": "npm run compile-test && npm run run-test-presets --",
"test:only": "npm run compile-test && npm run run-test && npm run run-test-build && npm run run-test-natvis",
"run-tests": "cd ./out/test/ && QT_TEST_QT_ROOT=${npm_config_qt_root:-$QT_TEST_QT_ROOT} node runTest.js && QT_TEST_QT_ROOT=${npm_config_qt_root:-$QT_TEST_QT_ROOT} node runTest.build.js && QT_TEST_QT_ROOT=${npm_config_qt_root:-$QT_TEST_QT_ROOT} node runTest.natvis.js",
"test:build": "npm run prepare-vsix && npm run test:only:build --",
"test:presets": "npm run prepare-vsix && npm run test:only:presets --",
"test:natvis": "npm run prepare-vsix && npm run test:only:natvis --",
"test": "npm run prepare-vsix && npm run compile-test && npm run run-tests",
"lint": "npm run prettierWrite && eslint . --fix --cache",
Expand Down
49 changes: 42 additions & 7 deletions qt-cpp/test/helper.mts
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,48 @@ export async function cleanBuildDir(
return buildDir;
}

export async function setCMakeGeneratorForPlatform(
ws: vscode.WorkspaceFolder
): Promise<void> {
const generator = process.platform === 'win32' ? 'Ninja' : 'Unix Makefiles';
await vscode.workspace
.getConfiguration('cmake', ws.uri)
.update('generator', generator, vscode.ConfigurationTarget.Workspace);
class CMakeConfigrator {
private ws: vscode.WorkspaceFolder;
private resetValues: Map<string, unknown> = new Map();

constructor(ws: vscode.WorkspaceFolder) {
this.ws = ws;
}

async set(
settingName: string,
value: unknown,
resetValue?: unknown
): Promise<void> {
if (!this.resetValues.has(settingName)) {
this.resetValues.set(settingName, resetValue);
}
await vscode.workspace
.getConfiguration('cmake', this.ws.uri)
.update(settingName, value, vscode.ConfigurationTarget.Workspace);
}
resetAll() {
const resets: Promise<void>[] = [];
for (const [settingName, value] of this.resetValues.entries()) {
resets.push(
Promise.resolve(
vscode.workspace
.getConfiguration('cmake', this.ws.uri)
.update(settingName, value, vscode.ConfigurationTarget.Workspace)
)
);
}
this.resetValues.clear();
return Promise.all(resets);
}
}

export function cmakeConfigForWorkspace(ws: vscode.WorkspaceFolder) {
return new CMakeConfigrator(ws);
}

export function getPlatformCMakeGenerator(): string {
return process.platform === 'win32' ? 'Ninja' : 'Unix Makefiles';
}

/**
Expand Down
6 changes: 5 additions & 1 deletion qt-cpp/test/runTest.build.mts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ async function main() {
setupVSCodeSettings(userDataDir, qtRoot, {
'cmake.configureOnOpen': false
});
installRequiredExtensions(cli, args, localQtCoreVsix);
const extensions = [
{ idOrVsix: 'ms-vscode.cmake-tools' },
{ idOrVsix: localQtCoreVsix }
];
installRequiredExtensions(cli, args, extensions);

// The workspace folder we want to open
const projectDir = path.resolve(__dirname, '../../test/projectFolder');
Expand Down
6 changes: 5 additions & 1 deletion qt-cpp/test/runTest.mts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ async function main() {
await setupTestInfrastructure(vscodeExecutablePath);

setupVSCodeSettings(userDataDir, qtRoot);
installRequiredExtensions(cli, args, localQtCoreVsix);
const extensions = [
{ idOrVsix: 'ms-vscode.cmake-tools' },
{ idOrVsix: localQtCoreVsix }
];
installRequiredExtensions(cli, args, extensions);

// Run the integration tests (no need to pass launchArgs; we reused the same dirs)
await runTests({
Expand Down
22 changes: 6 additions & 16 deletions qt-cpp/test/runTest.natvis.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ import * as fsp from 'fs/promises';

import { downloadAndUnzipVSCode, runTests } from '@vscode/test-electron';

import { getQuietVSCodeArgs } from '../../qt-lib/src/test-constants.js';

import {
installExtensionWithRetry,
debugListExtensions,
assertExtensionsInstalled
} from '../../qt-lib/src/test-vscode-install.js';

import {
setupVSCodeSettings,
setupTestInfrastructure,
Expand Down Expand Up @@ -46,14 +38,12 @@ async function main() {
});

// Install core required extensions (CMake Tools + qt-core) via helper
installRequiredExtensions(cli, args, localQtCoreVsix);

const quietArgs = [...args, ...getQuietVSCodeArgs()];
installExtensionWithRetry(cli, quietArgs, 'ms-vscode.cpptools');

// Final extension check: ensure cpptools is present
debugListExtensions(cli, quietArgs);
assertExtensionsInstalled(cli, quietArgs, ['ms-vscode.cpptools']);
const extensions = [
{ idOrVsix: 'ms-vscode.cmake-tools' },
{ idOrVsix: 'ms-vscode.cpptools' },
{ idOrVsix: localQtCoreVsix }
];
installRequiredExtensions(cli, args, extensions);

// The workspace folder we want to open
const projectDir = path.resolve(
Expand Down
70 changes: 70 additions & 0 deletions qt-cpp/test/runTest.presets.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only

import * as path from 'path';
import * as os from 'os';
import * as fsp from 'fs/promises';

import { downloadAndUnzipVSCode, runTests } from '@vscode/test-electron';

import {
setupTestInfrastructure,
setupVSCodeSettings,
installRequiredExtensions
} from './runTestHelper.mjs';
import { ExtensionInstallInfo } from 'qt-lib/src/test-vscode-install.ts';

async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to --extensionDevelopmentPath
const extensionDevelopmentPath = path.resolve(__dirname, '../../');

// The path to the extension test script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index-presets');

const vscodeExecutablePath = await downloadAndUnzipVSCode();

const { qtRoot, localQtCoreVsix, cli, args, userDataDir } =
await setupTestInfrastructure(vscodeExecutablePath);

setupVSCodeSettings(userDataDir, qtRoot, {
'cmake.configureOnOpen': false
});
const extensions: ExtensionInstallInfo[] = [
{ idOrVsix: 'ms-vscode.cmake-tools', preRelease: true },
{ idOrVsix: localQtCoreVsix }
];
installRequiredExtensions(cli, args, extensions);

// The workspace folder we want to open
const projectDir = path.resolve(__dirname, '../../test/projectFolder');
console.log('[runTest] Using project dir:', projectDir);
const tmpWs = await fsp.mkdtemp(path.join(os.tmpdir(), 'qt-cpp-ws-'));
const tmpProject = path.join(tmpWs, 'project');
await fsp.mkdir(tmpProject, { recursive: true });
// Node 16+: recursive copy
await fsp.cp(projectDir, tmpProject, { recursive: true });
console.log('[runTest] Copied project to temp dir:', tmpProject);

// Run the integration tests (no need to pass launchArgs; we reused the same dirs)
try {
await runTests({
launchArgs: [tmpProject, '--disable-workspace-trust'],
extensionDevelopmentPath,
extensionTestsPath
});
} finally {
try {
await fsp.rm(tmpWs, { recursive: true, force: true });
} catch {}
}
} catch (e: Error | unknown) {
console.error('Failed to run tests');
console.error(e);
process.exit(1);
}
}

main();
12 changes: 6 additions & 6 deletions qt-cpp/test/runTestHelper.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
installExtensionWithRetry,
debugListExtensions,
assertExtensionsInstalled,
getDebugLevel
getDebugLevel,
ExtensionInstallInfo
} from '../../qt-lib/src/test-vscode-install.js';

const QT_INS_ROOT_CONFIG_NAME = 'qtInstallationRoot';
Expand Down Expand Up @@ -108,18 +109,17 @@ export function setupVSCodeSettings(
export function installRequiredExtensions(
cli: string,
args: string[],
localQtCoreVsix: string
extensions: ExtensionInstallInfo[],
requiredIDs: string[] = ['ms-vscode.cmake-tools', 'theqtcompany.qt-core']
): void {
const quietArgs = [...args, ...getQuietVSCodeArgs()];
const required = ['ms-vscode.cmake-tools', localQtCoreVsix];
const requiredIds = ['ms-vscode.cmake-tools', 'theqtcompany.qt-core'];

for (const ext of required) {
for (const ext of extensions) {
installExtensionWithRetry(cli, quietArgs, ext);
}

debugListExtensions(cli, args);
assertExtensionsInstalled(cli, args, requiredIds);
assertExtensionsInstalled(cli, args, requiredIDs);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions qt-cpp/test/suite/build.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
prepareCMakeQtEnvWithVersion,
getWorkspaceFolderOrThrow,
cleanBuildDir,
setCMakeGeneratorForPlatform,
cmakeConfigForWorkspace,
getPlatformCMakeGenerator,
prepareStandardCMakeArgs,
readCMakeCacheVar,
selectAndApplyKit
Expand All @@ -33,11 +34,12 @@ describe('build: minimal Qt project (index-build)', function () {

it('configures and builds a tiny Qt app', async function () {
const wsFolder = getWorkspaceFolderOrThrow();
const cmakeConfigurator = cmakeConfigForWorkspace(wsFolder);
const projectDir = wsFolder.uri.fsPath;
console.log('Using projectDir:', projectDir);
const buildDir = await cleanBuildDir(projectDir);

await setCMakeGeneratorForPlatform(wsFolder);
await cmakeConfigurator.set('generator', getPlatformCMakeGenerator());

await selectAndApplyKit();

Expand Down Expand Up @@ -85,5 +87,7 @@ describe('build: minimal Qt project (index-build)', function () {
expect(fs.existsSync(outPath), `Expected build artifact at ${outPath}`).to
.be.true;
expect(errSpy.called, 'Unexpected error popups during build').to.be.false;

await cmakeConfigurator.resetAll();
});
});
33 changes: 33 additions & 0 deletions qt-cpp/test/suite/index-presets.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only

// This index is used exclusively for CMake Presets tests.
// It should only include presets.test.mts to test CMake Presets functionality
// with the prerelease version of CMake Tools.

import * as path from 'path';
import Mocha from 'mocha';
import * as glob from 'glob';

export function run(): Promise<void> {
const mocha = new Mocha({ ui: 'bdd', color: true });

const testsRoot = path.resolve(__dirname);

return new Promise((resolve, reject) => {
// Only include the presets test file that esbuild outputs
const g = new glob.Glob('presets.test.js', { cwd: testsRoot });

g.stream()
.on('data', (file) => mocha.addFile(path.resolve(testsRoot, file)))
.on('error', (err) =>
reject(err instanceof Error ? err : new Error(String(err)))
)
.on('end', () => {
mocha.timeout(150_000);
mocha.run((failures) =>
failures ? reject(new Error(`${failures} tests failed.`)) : resolve()
);
});
});
}
2 changes: 1 addition & 1 deletion qt-cpp/test/suite/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function run(): Promise<void> {
return new Promise((c, e) => {
const testFiles = new glob.Glob('**.test.js', {
cwd: testsRoot,
ignore: ['**/build.test.js', '**/natvis.test.js']
ignore: ['**/build.test.js', '**/natvis.test.js', '**/presets.test.js']
});
const testFileStream = testFiles.stream();
testFileStream.on('data', (file) => {
Expand Down
Loading
Loading