Skip to content

Commit 35b1fa5

Browse files
committed
Replace () => arrow lambds with function () for Mocha
The former lexically binds `this` and so prevents access to Mocha's test context, hence its documentation advises the use of `function ()` instead. This allows access to the context for skipping, parameterization, etc. Note that this requires disabling the TSLint rule which disagrees with Mocha's recommendation.
1 parent cd52e8a commit 35b1fa5

9 files changed

+50
-49
lines changed

test/core/paths.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import * as path from "path";
77
import * as vscode from "vscode";
88
import utils = require("../utils");
99

10-
describe("Path assumptions", () => {
10+
describe("Path assumptions", function() {
1111
before(utils.ensureExtensionIsActivated);
1212

1313
// TODO: This is skipped because it intereferes with other tests. Either
1414
// need to find a way to close the opened folder via a Code API, or find
1515
// another way to test this.
16-
it.skip("The examples folder can be opened (and exists)", async () => {
16+
it.skip("The examples folder can be opened (and exists)", async function() {
1717
assert(await vscode.commands.executeCommand("PowerShell.OpenExamplesFolder"));
1818
});
1919

20-
it("The session folder is created in the right place", async () => {
20+
it("The session folder is created in the right place", async function() {
2121
assert(fs.existsSync(path.resolve(utils.rootPath, "sessions")));
2222
});
2323

24-
it("The logs folder is created in the right place", async () => {
24+
it("The logs folder is created in the right place", async function() {
2525
assert(fs.existsSync(path.resolve(utils.rootPath, "logs")));
2626
});
2727
});

test/core/platform.test.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ function setupTestEnvironment(testPlatform: ITestPlatform) {
467467
}
468468
}
469469

470-
describe("Platform module", () => {
471-
describe("PlatformDetails", () => {
470+
describe("Platform module", function() {
471+
describe("PlatformDetails", function() {
472472
const platformDetails: platform.IPlatformDetails = platform.getPlatformDetails();
473473
switch (process.platform) {
474474
case "darwin":
@@ -521,14 +521,14 @@ describe("Platform module", () => {
521521
}
522522
});
523523

524-
describe("Default PowerShell installation", () => {
525-
afterEach(() => {
524+
describe("Default PowerShell installation", function() {
525+
afterEach(function() {
526526
sinon.restore();
527527
mockFS.restore();
528528
});
529529

530530
for (const testPlatform of successTestCases) {
531-
it(`Default PowerShell path on ${testPlatform.name}`, () => {
531+
it(`Default PowerShell path on ${testPlatform.name}`, function() {
532532
setupTestEnvironment(testPlatform);
533533

534534
const powerShellExeFinder = new platform.PowerShellExeFinder(testPlatform.platformDetails);
@@ -542,7 +542,7 @@ describe("Platform module", () => {
542542
}
543543

544544
for (const testPlatform of errorTestCases) {
545-
it(`Extension startup fails gracefully on ${testPlatform.name}`, () => {
545+
it(`Extension startup fails gracefully on ${testPlatform.name}`, function() {
546546
setupTestEnvironment(testPlatform);
547547

548548
const powerShellExeFinder = new platform.PowerShellExeFinder(testPlatform.platformDetails);
@@ -553,14 +553,14 @@ describe("Platform module", () => {
553553
}
554554
});
555555

556-
describe("Expected PowerShell installation list", () => {
557-
afterEach(() => {
556+
describe("Expected PowerShell installation list", function() {
557+
afterEach(function() {
558558
sinon.restore();
559559
mockFS.restore();
560560
});
561561

562562
for (const testPlatform of successTestCases) {
563-
it(`PowerShell installation list on ${testPlatform.name}`, () => {
563+
it(`PowerShell installation list on ${testPlatform.name}`, function() {
564564
setupTestEnvironment(testPlatform);
565565

566566
const powerShellExeFinder = new platform.PowerShellExeFinder(testPlatform.platformDetails);
@@ -583,7 +583,7 @@ describe("Platform module", () => {
583583
}
584584

585585
for (const testPlatform of errorTestCases) {
586-
it(`Extension startup fails gracefully on ${testPlatform.name}`, () => {
586+
it(`Extension startup fails gracefully on ${testPlatform.name}`, function() {
587587
setupTestEnvironment(testPlatform);
588588

589589
const powerShellExeFinder = new platform.PowerShellExeFinder(testPlatform.platformDetails);
@@ -594,16 +594,16 @@ describe("Platform module", () => {
594594
}
595595
});
596596

597-
describe("Windows PowerShell path fix", () => {
598-
afterEach(() => {
597+
describe("Windows PowerShell path fix", function() {
598+
afterEach(function() {
599599
sinon.restore();
600600
mockFS.restore();
601601
});
602602

603603
for (const testPlatform of successTestCases
604604
.filter((tp) => tp.platformDetails.operatingSystem === platform.OperatingSystem.Windows)) {
605605

606-
it(`Corrects the Windows PowerShell path on ${testPlatform.name}`, () => {
606+
it(`Corrects the Windows PowerShell path on ${testPlatform.name}`, function() {
607607
setupTestEnvironment(testPlatform);
608608

609609
function getWinPSPath(systemDir: string) {

test/core/settings.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import * as assert from "assert";
55
import * as vscode from "vscode";
66
import Settings = require("../../src/settings");
77

8-
describe("Settings module", () => {
9-
it("Settings load without error", () => {
8+
describe("Settings module", function() {
9+
it("Settings load without error", function() {
1010
assert.doesNotThrow(Settings.load);
1111
});
1212

13-
it("Settings update correctly", async () => {
13+
it("Settings update correctly", async function() {
1414
// then syntax
1515
Settings.change("helpCompletion", "BlockComment", false).then(() =>
1616
assert.strictEqual(Settings.load().helpCompletion, "BlockComment"));
@@ -20,7 +20,7 @@ describe("Settings module", () => {
2020
assert.strictEqual(Settings.load().helpCompletion, "LineComment");
2121
});
2222

23-
it("Settings that can only be user settings update correctly", async () => {
23+
it("Settings that can only be user settings update correctly", async function() {
2424
// set to false means it's set as a workspace-level setting so this should throw.
2525
const psExeDetails = [{
2626
versionName: "My PowerShell",
@@ -34,7 +34,7 @@ describe("Settings module", () => {
3434
assert.strictEqual(Settings.load().powerShellAdditionalExePaths[0].versionName, psExeDetails[0].versionName);
3535
});
3636

37-
it("Can get effective configuration target", async () => {
37+
it("Can get effective configuration target", async function() {
3838
await Settings.change("helpCompletion", "LineComment", false);
3939
let target = await Settings.getEffectiveConfigurationTarget("helpCompletion");
4040
assert.strictEqual(target, vscode.ConfigurationTarget.Workspace);

test/features/CustomViews.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function convertToVSCodeResourceScheme(filePath: string): string {
3030
return vscode.Uri.file(filePath).toString().replace("file://", "vscode-resource://");
3131
}
3232

33-
describe("CustomViews tests", () => {
33+
describe("CustomViews tests", function() {
3434
const testCases: IHtmlContentViewTestCase[] = [
3535
// Basic test that has no js or css.
3636
{
@@ -108,7 +108,7 @@ hello
108108
];
109109

110110
for (const testCase of testCases) {
111-
it(`Can create an HtmlContentView and get its content - ${testCase.name}`, () => {
111+
it(`Can create an HtmlContentView and get its content - ${testCase.name}`, function() {
112112
const htmlContentView = new HtmlContentView();
113113

114114
const jsPaths = testCase.javaScriptFiles.map((jsFile) => {

test/features/ExternalApi.test.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import * as assert from "assert";
55
import utils = require("../utils");
66
import { IExternalPowerShellDetails, IPowerShellExtensionClient } from "../../src/features/ExternalApi";
77

8-
describe("ExternalApi feature - Registration API", () => {
8+
describe("ExternalApi feature - Registration API", function() {
99
let powerShellExtensionClient: IPowerShellExtensionClient;
10-
before(async () => {
10+
before(async function() {
1111
const powershellExtension = await utils.ensureExtensionIsActivated();
1212
powerShellExtensionClient = powershellExtension!.exports as IPowerShellExtensionClient;
1313
});
1414

15-
it("It can register and unregister an extension", () => {
15+
it("It can register and unregister an extension", function() {
1616
const sessionId: string = powerShellExtensionClient.registerExternalExtension(utils.extensionId);
1717
assert.notStrictEqual(sessionId , "");
1818
assert.notStrictEqual(sessionId , null);
@@ -21,7 +21,7 @@ describe("ExternalApi feature - Registration API", () => {
2121
true);
2222
});
2323

24-
it("It can register and unregister an extension with a version", () => {
24+
it("It can register and unregister an extension with a version", function() {
2525
const sessionId: string = powerShellExtensionClient.registerExternalExtension(utils.extensionId, "v2");
2626
assert.notStrictEqual(sessionId , "");
2727
assert.notStrictEqual(sessionId , null);
@@ -33,12 +33,12 @@ describe("ExternalApi feature - Registration API", () => {
3333
/*
3434
NEGATIVE TESTS
3535
*/
36-
it("API fails if not registered", async () => {
36+
it("API fails if not registered", async function() {
3737
assert.rejects(
3838
async () => await powerShellExtensionClient.getPowerShellVersionDetails(""))
3939
});
4040

41-
it("It can't register the same extension twice", async () => {
41+
it("It can't register the same extension twice", async function() {
4242
const sessionId: string = powerShellExtensionClient.registerExternalExtension(utils.extensionId);
4343
try {
4444
assert.throws(
@@ -51,7 +51,7 @@ describe("ExternalApi feature - Registration API", () => {
5151
}
5252
});
5353

54-
it("It can't unregister an extension that isn't registered", async () => {
54+
it("It can't unregister an extension that isn't registered", async function() {
5555
assert.throws(
5656
() => powerShellExtensionClient.unregisterExternalExtension("not-real"),
5757
{
@@ -64,20 +64,20 @@ describe("ExternalApi feature - Other APIs", () => {
6464
let sessionId: string;
6565
let powerShellExtensionClient: IPowerShellExtensionClient;
6666

67-
before(async () => {
67+
before(async function() {
6868
const powershellExtension = await utils.ensureExtensionIsActivated();
6969
powerShellExtensionClient = powershellExtension!.exports as IPowerShellExtensionClient;
7070
});
7171

72-
beforeEach(() => {
72+
beforeEach(function() {
7373
sessionId = powerShellExtensionClient.registerExternalExtension(utils.extensionId);
7474
});
7575

76-
afterEach(() => {
76+
afterEach(function() {
7777
powerShellExtensionClient.unregisterExternalExtension(sessionId);
7878
});
7979

80-
it("It can get PowerShell version details", async () => {
80+
it("It can get PowerShell version details", async function() {
8181
const versionDetails: IExternalPowerShellDetails = await powerShellExtensionClient.getPowerShellVersionDetails(sessionId);
8282

8383
assert.notStrictEqual(versionDetails.architecture, "");

test/features/ISECompatibility.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ import * as vscode from "vscode";
66
import { ISECompatibilityFeature } from "../../src/features/ISECompatibility";
77
import utils = require("../utils");
88

9-
describe("ISECompatibility feature", () => {
9+
describe("ISECompatibility feature", function() {
1010
let currentTheme: string;
1111

12-
before(async () => {
12+
before(async function() {
1313
// Save user's current theme.
1414
currentTheme = await vscode.workspace.getConfiguration("workbench").get("colorTheme");
1515
await utils.ensureExtensionIsActivated();
1616
});
1717

18-
beforeEach(async () => { await vscode.commands.executeCommand("PowerShell.EnableISEMode"); });
18+
beforeEach(async function() { await vscode.commands.executeCommand("PowerShell.EnableISEMode"); });
1919

20-
afterEach(async () => { await vscode.commands.executeCommand("PowerShell.DisableISEMode"); });
20+
afterEach(async function() { await vscode.commands.executeCommand("PowerShell.DisableISEMode"); });
2121

22-
after(async () => {
22+
after(async function() {
2323
// Reset user's current theme.
2424
await vscode.workspace.getConfiguration("workbench").update("colorTheme", currentTheme, true);
2525
assert.strictEqual(vscode.workspace.getConfiguration("workbench").get("colorTheme"), currentTheme);
2626
});
2727

28-
it("It sets ISE Settings", async () => {
28+
it("It sets ISE Settings", async function() {
2929
for (const iseSetting of ISECompatibilityFeature.settings) {
3030
const currently = vscode.workspace.getConfiguration(iseSetting.path).get(iseSetting.name);
3131
assert.strictEqual(currently, iseSetting.value);
3232
}
3333
});
3434

35-
it("It unsets ISE Settings", async () => {
35+
it("It unsets ISE Settings", async function() {
3636
// Change state to something that DisableISEMode will change
3737
await vscode.workspace.getConfiguration("workbench").update("colorTheme", "PowerShell ISE", true);
3838
assert.strictEqual(vscode.workspace.getConfiguration("workbench").get("colorTheme"), "PowerShell ISE");
@@ -44,7 +44,7 @@ describe("ISECompatibility feature", () => {
4444
}
4545
});
4646

47-
it("It doesn't change theme when disabled if theme was manually changed after being enabled", async () => {
47+
it("It doesn't change theme when disabled if theme was manually changed after being enabled", async function() {
4848
assert.strictEqual(vscode.workspace.getConfiguration("workbench").get("colorTheme"), "PowerShell ISE");
4949

5050
// "Manually" change theme after enabling ISE mode. Use a built-in theme but not the default.

test/features/RunCode.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ enum LaunchType {
1818
Run,
1919
}
2020

21-
describe("RunCode tests", () => {
21+
describe("RunCode tests", function() {
2222
before(utils.ensureExtensionIsActivated);
2323

24-
it("Can create the launch config", () => {
24+
it("Can create the launch config", function() {
2525
const commandToRun: string = "Invoke-Build";
2626
const args: string[] = ["Clean"];
2727

@@ -42,7 +42,7 @@ describe("RunCode tests", () => {
4242
assert.deepStrictEqual(actual, expected);
4343
});
4444

45-
it("Can run Pester tests from file", async () => {
45+
it("Can run Pester tests from file", async function() {
4646
const pesterTests = path.resolve(__dirname, "../../../examples/Tests/SampleModule.Tests.ps1");
4747
assert(fs.existsSync(pesterTests));
4848

test/features/UpdatePowerShell.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import { GitHubReleaseInformation } from "../../src/features/UpdatePowerShell";
88
// the GitHub API rate limit often. Let's skip these tests on macOS until
99
// they are hooked up to only run on release.
1010
if (process.env.TF_BUILD && process.platform === "win32") {
11-
describe("UpdatePowerShell tests", () => {
12-
it("Can get the latest version", async () => {
11+
describe("UpdatePowerShell tests", function() {
12+
it("Can get the latest version", async function() {
1313
const release: GitHubReleaseInformation = await GitHubReleaseInformation.FetchLatestRelease(false);
1414
assert.strictEqual(release.isPreview, false, "expected to not be preview.");
1515
assert.strictEqual(
1616
release.version.prerelease.length === 0, true, "expected to not have preview in version.");
1717
assert.strictEqual(release.assets.length > 0, true, "expected to have assets.");
1818
});
1919

20-
it("Can get the latest preview version", async () => {
20+
it("Can get the latest preview version", async function() {
2121
const release: GitHubReleaseInformation = await GitHubReleaseInformation.FetchLatestRelease(true);
2222
assert.strictEqual(release.isPreview, true, "expected to be preview.");
2323
assert.strictEqual(release.version.prerelease.length > 0, true, "expected to have preview in version.");

tslint.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"indent": [true, "spaces", 4],
99
"max-classes-per-file": false,
1010
"object-literal-sort-keys": false,
11+
"only-arrow-functions": false,
1112
"file-header": [
1213
true,
1314
{

0 commit comments

Comments
 (0)