Skip to content

Commit

Permalink
Update mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Weatherford committed Nov 10, 2021
1 parent bec3b8b commit 63a091b
Show file tree
Hide file tree
Showing 17 changed files with 484 additions and 549 deletions.
905 changes: 422 additions & 483 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@
"@types/decompress": "^4.2.3",
"@types/fs-extra": "^5.1.0",
"@types/gulp": "^4.0.8",
"@types/mocha": "^2.2.41",
"@types/mocha": "^9.0.0",
"@types/node": "^14.14.24",
"@types/opn": "^5.5.0",
"@types/recursive-readdir": "^2.2.0",
Expand All @@ -642,7 +642,7 @@
"gulp": "^4.0.2",
"gulp-decompress": "^2.0.2",
"gulp-download": "^0.0.1",
"mocha": "^8.2.1",
"mocha": "^9.1.3",
"recursive-readdir": "^2.2.2",
"ts-node": "^8.10.2",
"tslint": "^5.20.1",
Expand Down
22 changes: 9 additions & 13 deletions test/DeploymentTemplate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as assert from "assert";
import { randomBytes } from "crypto";
import { ISuiteCallbackContext, ITestCallbackContext } from "mocha";
import { Context, Suite } from "mocha";
import { Uri } from "vscode";
import { parseError } from "vscode-azureextensionui";
import { DefinitionKind, DeploymentTemplateDoc, getVSCodeRangeFromSpan, Histogram, INamedDefinition, IncorrectArgumentsCountIssue, IParameterDefinition, Issue, IssueKind, IVariableDefinition, Json, LineColPos, ReferenceInVariableDefinitionsVisitor, ReferenceList, Span, TemplateScope, UnrecognizedUserFunctionIssue, UnrecognizedUserNamespaceIssue } from "../extension.bundle";
Expand Down Expand Up @@ -933,7 +933,7 @@ suite("DeploymentTemplate", () => {
assert.deepStrictEqual(visitor.referenceSpans, []);
});

testWithLanguageServer("expecting error: reference in variable definition", async function (this: ITestCallbackContext): Promise<void> {
testWithLanguageServer("expecting error: reference in variable definition", async function (this: Context): Promise<void> {
await testDiagnostics(
{
"variables": {
Expand All @@ -949,7 +949,7 @@ suite("DeploymentTemplate", () => {
]);
});

testWithLanguageServer("expecting error: reference in variable definition inside user function", async function (this: ITestCallbackContext): Promise<void> {
testWithLanguageServer("expecting error: reference in variable definition inside user function", async function (this: Context): Promise<void> {
await testDiagnostics(
{
"variables": {
Expand Down Expand Up @@ -1013,7 +1013,7 @@ suite("DeploymentTemplate", () => {
});
});

suite("Incomplete JSON shouldn't cause crash", function (this: ISuiteCallbackContext): void {
suite("Incomplete JSON shouldn't cause crash", function (this: Suite): void {
this.timeout(60000);

async function exercisePositionContextAtEveryPointInTheDoc(json: string): Promise<void> {
Expand Down Expand Up @@ -1174,10 +1174,9 @@ ${err}`);
dt.getFunctionCounts();
});

test("typing character by character", async function (this: ITestCallbackContext): Promise<void> {
test("typing character by character", async function (this: Context): Promise<void> {
if (DISABLE_SLOW_TESTS) {
this.skip();
return;
}

// Just make sure nothing throws
Expand All @@ -1192,10 +1191,9 @@ ${err}`);
}
});

test("typing backwards character by character", async function (this: ITestCallbackContext): Promise<void> {
test("typing backwards character by character", async function (this: Context): Promise<void> {
if (DISABLE_SLOW_TESTS) {
this.skip();
return;
}

// Just make sure nothing throws
Expand All @@ -1210,7 +1208,7 @@ ${err}`);
}
});

test("try parsing the document with a single character deleted (repeat through the whole document)", async function (this: ITestCallbackContext): Promise<void> {
test("try parsing the document with a single character deleted (repeat through the whole document)", async function (this: Context): Promise<void> {
if (DISABLE_SLOW_TESTS) {
this.skip();
return;
Expand All @@ -1229,20 +1227,18 @@ ${err}`);
}
});

test("exercise PositionContext at every point in the full json", async function (this: ITestCallbackContext): Promise<void> {
test("exercise PositionContext at every point in the full json", async function (this: Context): Promise<void> {
if (DISABLE_SLOW_TESTS) {
this.skip();
return;
}

// Just make sure nothing throws
await exercisePositionContextAtEveryPointInTheDoc(template);
});

test("Random modifications", async function (this: ITestCallbackContext): Promise<void> {
test("Random modifications", async function (this: Context): Promise<void> {
if (DISABLE_SLOW_TESTS) {
this.skip();
return;
}

// Just make sure nothing throws
Expand Down
6 changes: 3 additions & 3 deletions test/TestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ----------------------------------------------------------------------------

import * as fs from 'fs';
import { ITest, ITestCallbackContext } from 'mocha';
import { Context, Test } from 'mocha';
import * as path from 'path';
import { AzureRMAssets, Completion, Span } from "../extension.bundle";
import { writeToLog } from './support/testLog';
Expand All @@ -24,7 +24,7 @@ export function useRealFunctionMetadata(): void {
export class UseRealFunctionMetadata implements ITestPreparation {
public static readonly instance: UseRealFunctionMetadata = new UseRealFunctionMetadata();

public pretest(this: ITestCallbackContext): ITestPreparationResult {
public pretest(this: Context): ITestPreparationResult {
useRealFunctionMetadata();
return {
postTestActions: useTestFunctionMetadata
Expand All @@ -42,7 +42,7 @@ export async function runWithRealFunctionMetadata(callback: () => Promise<unknow
}
}

export function testWithRealFunctionMetadata(expectation: string, callback?: (this: ITestCallbackContext) => Promise<unknown>): ITest {
export function testWithRealFunctionMetadata(expectation: string, callback?: (this: Context) => Promise<unknown>): Test {
return testWithPrep(expectation, [UseRealFunctionMetadata.instance], callback);
}

Expand Down
2 changes: 1 addition & 1 deletion test/Treeview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ suite("TreeView", async (): Promise<void> => {
suite("JsonOutlineProvider", async (): Promise<void> => {
let provider: JsonOutlineProvider;

setup(function (this: Mocha.IHookCallbackContext, done: MochaDone): void {
setup(function (this: Mocha.Context, done: Mocha.Done): void {
this.timeout(15000);

async function mySetup(): Promise<void> {
Expand Down
7 changes: 3 additions & 4 deletions test/colorization/tle-colorization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const OVERWRITE = false;

import * as assert from 'assert';
import * as fs from 'fs';
import { ISuiteCallbackContext, ITestCallbackContext } from 'mocha';
import { Context, Suite } from 'mocha';
import * as os from 'os';
import * as path from 'path';
import { commands, Uri } from 'vscode';
Expand Down Expand Up @@ -313,7 +313,7 @@ function getTestcaseResults(testCases: ITestcase[]): { text: string; results: st
return { text, results: results.map(r => r.full), fullScopeString, shortScopeString };
}

suite('TLE colorization', function (this: ISuiteCallbackContext): void {
suite('TLE colorization', function (this: Suite): void {
this.timeout(50000); // I've seen as high as 32s on server (esp the first ARM one), although most are no more than a second or two

let testFolder = path.join(__dirname, '..', '..', '..', 'test', 'colorization', 'inputs');
Expand Down Expand Up @@ -357,10 +357,9 @@ suite('TLE colorization', function (this: ISuiteCallbackContext): void {
if (testFile.startsWith('TO' + 'DO')) {
test(testFile);
} else {
test(testFile, async function (this: ITestCallbackContext): Promise<void> {
test(testFile, async function (this: Context): Promise<void> {
if (DISABLE_SLOW_TESTS) {
this.skip();
return;
}

// tslint:disable-next-line:no-non-null-assertion
Expand Down
6 changes: 3 additions & 3 deletions test/formatDocument.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import * as assert from "assert";
import * as fs from 'fs';
import { ISuiteCallbackContext, ITestCallbackContext } from "mocha";
import { Context, Suite } from "mocha";
import * as path from 'path';
import { commands, languages, Range, Selection, TextDocument, TextEditor, window, workspace } from "vscode";
import { armTemplateLanguageId } from "../extension.bundle";
Expand All @@ -23,11 +23,11 @@ import { testWithLanguageServer } from "./support/testWithLanguageServer";
const formatDocumentCommand = 'editor.action.formatDocument';
const formatRangeCommand = 'editor.action.formatSelection';

suite("Format document", function (this: ISuiteCallbackContext): void {
suite("Format document", function (this: Suite): void {
this.timeout(defaultDiagnosticsTimeoutMs);

function testFormat(testName: string, source: string, expected: string, range?: Range | RegExp): void {
testWithLanguageServer(testName, async function (this: ITestCallbackContext): Promise<void> {
testWithLanguageServer(testName, async function (this: Context): Promise<void> {
let sourceIsFile = false;
let jsonUnformatted: string = source;
if (source.match(/\.jsonc?$/)) {
Expand Down
4 changes: 2 additions & 2 deletions test/functional/contextualizedSnippets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
const DEBUG_BREAK_AFTER_INSERTING_SNIPPET = false;

import * as assert from 'assert';
import { ITestCallbackContext } from 'mocha';
import { Context } from 'mocha';
import { Position, Selection } from "vscode";
import { ext } from "../../extension.bundle";
import { assertEx } from '../support/assertEx';
Expand Down Expand Up @@ -42,7 +42,7 @@ suite("Contextualized snippets", () => {
// tslint:disable-next-line: prefer-template
const name = `${testName}, triggered by ${triggerCharacter ? ("'" + triggerCharacter + "'") : 'CTRL+SPACE'}`;
// tslint:disable:no-function-expression
testWithRealSnippets(name, async function (this: ITestCallbackContext): Promise<void> {
testWithRealSnippets(name, async function (this: Context): Promise<void> {
const start = Date.now();
this.timeout(timeout);

Expand Down
7 changes: 3 additions & 4 deletions test/functional/snippets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const LOG_DOC_TEXT_BEFORE_AND_AFTER_SNIPPET_INSERTION = false;

import * as assert from 'assert';
import * as fse from 'fs-extra';
import { ITestCallbackContext } from 'mocha';
import { Context } from 'mocha';
import * as path from 'path';
import * as stripJsonComments from 'strip-json-comments';
import { commands, Selection, Uri, window, workspace } from "vscode";
Expand Down Expand Up @@ -261,7 +261,7 @@ suite("Snippets functional tests", () => {
testWithPrep(
`snippet: ${snippetName}`,
[RequiresLanguageServer.instance, UseRealSnippets.instance],
async function (this: ITestCallbackContext): Promise<void> {
async function (this: Context): Promise<void> {
const snippets = (await manager.getAllSnippets());
const snippet = snippets.find(s => s.name === snippetName);
assert(snippet !== undefined, `Couldn't find snippet ${snippetName}`);
Expand All @@ -273,10 +273,9 @@ suite("Snippets functional tests", () => {
});
}

async function testSnippet(testCallbackContext: ITestCallbackContext, snippetsPath: string, snippetName: string, snippet: ISnippet): Promise<void> {
async function testSnippet(testCallbackContext: Context, snippetsPath: string, snippetName: string, snippet: ISnippet): Promise<void> {
if (overrideSkipTests[snippetName]) {
testCallbackContext.skip();
return;
}

validateSnippet();
Expand Down
20 changes: 12 additions & 8 deletions test/global.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let previousSettings = {
};

// Runs before all tests
suiteSetup(async function (this: mocha.IHookCallbackContext): Promise<void> {
suiteSetup(async function (this: mocha.Context): Promise<void> {
// Create logs folder
if (await fse.pathExists(logsFolder)) {
rimraf.sync(logsFolder);
Expand Down Expand Up @@ -67,7 +67,7 @@ suiteSetup(async function (this: mocha.IHookCallbackContext): Promise<void> {
});

// Runs after all tests are done
suiteTeardown(async function (this: mocha.IHookCallbackContext): Promise<void> {
suiteTeardown(async function (this: mocha.Context): Promise<void> {
writeToLog('Done: global.test.ts: suiteTeardown');

await displayCacheStatus();
Expand All @@ -92,20 +92,24 @@ suiteTeardown(async function (this: mocha.IHookCallbackContext): Promise<void> {
});

// Runs before each individual test
setup(function (this: Mocha.IBeforeAndAfterContext): void {
writeToLog(`Running: ${this.currentTest.title}`);
setup(function (this: Mocha.Context): void {
// tslint:disable-next-line: no-non-null-assertion
writeToLog(`Running: ${this.currentTest!.title}`);
});

// Runs after each individual test
teardown(function (this: Mocha.IBeforeAndAfterContext): void {
teardown(function (this: Mocha.Context): void {
let message: string;
const failed = (!this.currentTest.state || this.currentTest.state === 'failed');
// tslint:disable-next-line: no-non-null-assertion
const failed = (!this.currentTest!.state || this.currentTest!.state === 'failed');

if (failed) {
if (getTestLogContents()) {
message = `Failed: ${this.currentTest.title}`;
// tslint:disable-next-line: no-non-null-assertion
message = `Failed: ${this.currentTest!.title}`;
} else {
message = `Failed (test log is empty): ${this.currentTest.title}`;
// tslint:disable-next-line: no-non-null-assertion
message = `Failed (test log is empty): ${this.currentTest!.title}`;
}
} else {
message = `Passed: ${this.currentTest}\n`;
Expand Down
4 changes: 2 additions & 2 deletions test/networkTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// tslint:disable:promise-function-async no-implicit-dependencies

import * as dns from "dns";
import { ITestCallbackContext } from "mocha";
import { Context } from "mocha";

let internetConnected: Promise<boolean>;
/**
Expand All @@ -29,7 +29,7 @@ function hasInternetConnection(): Promise<boolean> {
*/
// tslint:disable-next-line:no-any
export function networkTest(testName: string, testFunction: () => void | Promise<any>): void {
test(testName, function (this: ITestCallbackContext): Promise<void> {
test(testName, function (this: Context): Promise<void> {
this.timeout(10000);

return hasInternetConnection()
Expand Down
4 changes: 2 additions & 2 deletions test/performance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

import * as assert from "assert";
import * as fse from "fs-extra";
import { ITestCallbackContext } from "mocha";
import { Context } from "mocha";
import { parseTemplate } from "./support/parseTemplate";
import { resolveInTestFolder } from "./support/resolveInTestFolder";

suite("Performance tests", () => {
suite("warnings and errors performance", () => {
test("Lots of variables", async function (this: ITestCallbackContext): Promise<Promise<void>> {
test("Lots of variables", async function (this: Context): Promise<Promise<void>> {
// Takes less than a second on my local dev machine
this.timeout(5000);

Expand Down
8 changes: 4 additions & 4 deletions test/support/TestSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// ----------------------------------------------------------------------------

import { ITest, ITestCallbackContext } from 'mocha';
import { Context, Test } from 'mocha';
import * as path from 'path';
import { ext, SnippetManager } from "../../extension.bundle";
import { writeToLog } from './testLog';
Expand All @@ -28,7 +28,7 @@ export function useNoSnippets(): void {
export class UseRealSnippets implements ITestPreparation {
public static readonly instance: UseRealSnippets = new UseRealSnippets();

public pretest(this: ITestCallbackContext): ITestPreparationResult {
public pretest(this: Context): ITestPreparationResult {
useRealSnippets();
return {
postTestActions: useTestSnippets
Expand All @@ -39,15 +39,15 @@ export class UseRealSnippets implements ITestPreparation {
export class UseNoSnippets implements ITestPreparation {
public static readonly instance: UseNoSnippets = new UseNoSnippets();

public pretest(this: ITestCallbackContext): ITestPreparationResult {
public pretest(this: Context): ITestPreparationResult {
useNoSnippets();
return {
postTestActions: useTestSnippets
};
}
}

export function testWithRealSnippets(expectation: string, callback?: (this: ITestCallbackContext) => Promise<unknown>): ITest {
export function testWithRealSnippets(expectation: string, callback?: (this: Context) => Promise<unknown>): Test {
return testWithPrep(
expectation,
[UseRealSnippets.instance, RequiresLanguageServer.instance], // Language server needed for format document
Expand Down
Loading

0 comments on commit 63a091b

Please sign in to comment.