Skip to content

Commit

Permalink
Fix tests by using new vscode test structure and updating various com…
Browse files Browse the repository at this point in the history
…ponents
  • Loading branch information
Stephen Weatherford committed Jan 14, 2022
1 parent 98c7019 commit 5baa1c2
Show file tree
Hide file tree
Showing 65 changed files with 7,221 additions and 9,928 deletions.
6 changes: 6 additions & 0 deletions .azure-pipelines/common/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ steps:
testResultsFiles: "test-results.xml"
testRunTitle: "$(Agent.OS)"
condition: succeededOrFailed()

- script: |
ls
cat logs/testlog.txt
displayName: "Dump test logs"
condition: succeededOrFailed()
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
"--extensionTestsPath=${workspaceFolder}/out/test/index",
],
"stopOnEntry": false,
"sourceMaps": true,
Expand All @@ -50,6 +50,7 @@
"MOCHA_invert": "0", // Invert the RegExp
"MOCHA_bail": "0", // Bail after first failure
"AZCODE_ARM_IGNORE_BUNDLE": "1",
"IS_RUNNING_TESTS": "1",
"MOCHA_enableTimeouts": "0", // Disable time-outs
"DEBUGTELEMETRY": "verbose", // 1=quiet; verbose=see telemetry in console; 0=send telemetry
"NODE_DEBUG": "",
Expand Down Expand Up @@ -108,6 +109,7 @@
"DEBUGTELEMETRY": "1", // 1=quiet; verbose=see telemetry in console; 0=send telemetry
"NODE_DEBUG": "",
"AZCODE_ARM_IGNORE_BUNDLE": "0",
"IS_RUNNING_TESTS": "1",
"ECHO_OUTPUT_CHANNEL_TO_CONSOLE": "1",
"BREAK_ON_ASSERT": "",
"ALWAYS_ECHO_TEST_LOG": "" // If 1 or true, always immediately echos test log to console; otherwise test log is only echoed after a failed testcase
Expand Down
26 changes: 23 additions & 3 deletions src/constants.ts → common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,35 @@
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// NOTE: This is used by gulp and should avoid referencing code from ./src

import { assert } from "console";
import * as fs from "fs";
import * as os from 'os';
import * as path from 'path';

export const isWebpack: boolean = /^(false|0)?$/i.test(process.env.AZCODE_ARM_IGNORE_BUNDLE ?? '');
export const isWebpack: boolean = !!/^(false|0)?$/i.test(process.env.AZCODE_ARM_IGNORE_BUNDLE ?? '');
console.error(`isWebpack: ${isWebpack}`);

export const isWin32: boolean = os.platform() === 'win32';
export const isCaseSensitiveFileSystem: boolean = !isWin32;

export const basePath = path.join(__dirname, isWebpack ? "" : "..", "..");
export const assetsPath = path.join(basePath, "assets");
let base = __dirname;
while (true) {
let test = path.join(base, "assets");
if (fs.existsSync(test)) {
base = test;
break;
}
base = path.dirname(base);
assert(base != '', "Could not find base project path");
}
export const assetsPath = base;
export const basePath = path.join(assetsPath, "..");
export const iconsPath = path.join(basePath, "icons");
assert(fs.existsSync(assetsPath), "Assets path does not exist: " + assetsPath);

export const DEFAULT_TESTCASE_TIMEOUT_MS = 3 * 60 * 1000;

export namespace documentSchemes {
export const file: string = 'file'; // Locally-saved files
Expand Down Expand Up @@ -101,6 +119,8 @@ export namespace globalStateKeys {
export const diagnosticsCompletePrefix = "Diagnostics complete: ";
export const expressionsDiagnosticsCompletionMessage = diagnosticsCompletePrefix + expressionsDiagnosticsSource;

export const isRunningTests: boolean = /^(true|1)$/i.test(process.env.IS_RUNNING_TESTS ?? '');

export namespace templateKeys {
// Top-level
export const schema = '$schema';
Expand Down
4 changes: 3 additions & 1 deletion extension.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import * as Json from "./src/language/json/JSON";
import * as basic from "./src/language/json/Tokenizer";
import * as Completion from './src/vscodeIntegration/Completion';

export * from "./common";
export { activateInternal, deactivateInternal } from './src/AzureRMTools'; // Export activate/deactivate for main.js
export * from "./src/constants";
export * from "./src/documents/DeploymentDocument";
export * from "./src/documents/parameters/DeploymentFileMapping";
export * from "./src/documents/parameters/DeploymentParametersDoc";
Expand Down Expand Up @@ -89,6 +89,7 @@ export * from "./src/util/debugMarkStrings";
export * from "./src/util/deepClone";
export * from "./src/util/delayWhileSync";
export * from './src/util/Duration';
export * from "./src/util/envUtils";
export * from './src/util/filterByType';
export * from "./src/util/Histogram";
export * from './src/util/httpGet';
Expand Down Expand Up @@ -122,3 +123,4 @@ export { Completion };
export { Json };
export { basic };
export { TLE };

67 changes: 29 additions & 38 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,19 @@

import * as assert from 'assert';
import * as cp from 'child_process';
import { File } from 'decompress';
import * as fse from 'fs-extra';
import * as glob from 'glob';
import * as gulp from 'gulp';
import * as os from 'os';
import * as path from 'path';
import * as process from 'process';
import * as recursiveReadDir from 'recursive-readdir';
import * as shelljs from 'shelljs';
import { Stream } from 'stream';
import { gulp_webpack } from 'vscode-azureextensiondev';
import { langServerDotnetVersion, languageServerFolderName } from './src/constants';
import { downloadAndUnzipVSCode, resolveCliPathFromVSCodeExecutablePath } from "vscode-test";
import { DEFAULT_TESTCASE_TIMEOUT_MS, langServerDotnetVersion, languageServerFolderName } from './common';
import { getTempFilePath } from './test/support/getTempFilePath';
import { DEFAULT_TESTCASE_TIMEOUT_MS } from "./test/testConstants";

// tslint:disable:no-require-imports
import decompress = require('gulp-decompress');
import download = require('gulp-download');
import rimraf = require('rimraf');
// tslint:enable:no-require-imports

const filesAndFoldersToPackage: string[] = [
// NOTE: License.txt and languageServer folder are handled separately so should not be in this list
Expand Down Expand Up @@ -83,13 +76,14 @@ interface IExpressionMetadata {
}[];
}

function test(): cp.ChildProcess {
async function test(): Promise<cp.ChildProcess> {
env.DEBUGTELEMETRY = '0'; // 1=quiet; verbose=see telemetry in console; 0=send telemetry
env.CODE_TESTS_PATH = path.join(__dirname, 'dist/test');
env.IS_RUNNING_TESTS = '1';
// This is the timeout for individual tests
env.MOCHA_timeout = String(DEFAULT_TESTCASE_TIMEOUT_MS);
env.MOCHA_enableTimeouts = "1";
env.MOCHA_grep = '';
env.MOCHA_grep = "";
env.DISABLE_SLOW_TESTS = "";
env.ALWAYS_ECHO_TEST_LOG = "";

Expand All @@ -99,7 +93,29 @@ function test(): cp.ChildProcess {
console.log("*******");
console.log("");

return cp.spawn('node', ['./node_modules/vscode/bin/test'], { stdio: 'inherit', env });
const vscodeExecutablePath = await downloadAndUnzipVSCode();
const cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath);

const extensionInstallArguments = [
"--install-extension",
"ms-dotnettools.vscode-dotnet-runtime",
];

// Install .NET Install Tool as a dependency.
cp.spawnSync(cliPath, extensionInstallArguments, {
encoding: "utf-8",
stdio: "inherit",
});

return cp.spawn('node', ['./out/test/runTest.js'], { stdio: 'inherit', env });
}

async function postTest(): Promise<void> {
console.log("");
console.log("*******");
console.log("******* TESTS DONE");
console.log("*******");
console.log("");
}

function buildTLEGrammar(): void {
Expand Down Expand Up @@ -382,34 +398,9 @@ async function verifyTestsReferenceOnlyExtensionBundle(testFolder: string): Prom
}
}

export function gulp_installDotNetExtension(): Promise<void> | Stream {
const extensionName = '.NET Install Tool for Extension Authors';
console.log(`Installing ${extensionName}`);
const version: string = '0.1.0';
const extensionPath: string = path.join(os.homedir(), `.vscode/extensions/ms-dotnettools.vscode-dotnet-runtime-${version}`);
console.log(extensionPath);
const existingExtensions: string[] = glob.sync(extensionPath.replace(version, '*'));
if (existingExtensions.length === 0) {
// tslint:disable-next-line:no-http-string
return download(`http://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/ms-dotnettools/extension/vscode-dotnet-runtime/${version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage`)
.pipe(decompress({
filter: (file: File): boolean => file.path.startsWith('extension/'),
map: (file: File): File => {
file.path = file.path.slice(10);
return file;
}
}))
.pipe(gulp.dest(extensionPath));
} else {
console.log(`${extensionName} already installed.`);
// We need to signal to gulp that we've completed this async task
return Promise.resolve();
}
}

exports['webpack-dev'] = gulp.series(() => gulp_webpack('development'), buildGrammars);
exports['webpack-prod'] = gulp.series(() => gulp_webpack('production'), buildGrammars);
exports.test = gulp.series(gulp_installDotNetExtension, test);
exports.test = gulp.series(test, postTest);
exports['build-grammars'] = buildGrammars;
exports['watch-grammars'] = (): unknown => gulp.watch('grammars/**', buildGrammars);
exports['get-language-server'] = getLanguageServer;
Expand Down
Loading

0 comments on commit 5baa1c2

Please sign in to comment.