|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | +* Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +* Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | +*--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import * as vscode from 'vscode'; |
| 7 | +import * as path from 'path'; |
| 8 | + |
| 9 | +import { should, expect } from 'chai'; |
| 10 | +import { activateCSharpExtension, isSlnWithCsproj } from './integrationHelpers'; |
| 11 | +import testAssetWorkspace from './testAssets/testAssetWorkspace'; |
| 12 | +import { EventStream } from '../../src/EventStream'; |
| 13 | +import { EventType } from '../../src/omnisharp/EventType'; |
| 14 | +import { BaseEvent, OmnisharpRequestMessage } from '../../src/omnisharp/loggingEvents'; |
| 15 | +import { poll } from './poll'; |
| 16 | +import { V2 } from '../../src/omnisharp/protocol'; |
| 17 | + |
| 18 | +const chai = require('chai'); |
| 19 | +chai.use(require('chai-arrays')); |
| 20 | +chai.use(require('chai-fs')); |
| 21 | + |
| 22 | +async function waitActivityToSettle(stream: EventStream, timeout: number): Promise<void> { |
| 23 | + let event: BaseEvent = { type: 0 }; |
| 24 | + |
| 25 | + const subscription = stream.subscribe((e: BaseEvent) => event = e); |
| 26 | + |
| 27 | + await poll(() => event, timeout, 500, e => !e || (event = null)); |
| 28 | + |
| 29 | + subscription.unsubscribe(); |
| 30 | +} |
| 31 | + |
| 32 | +async function waitForEvent<T extends BaseEvent>(stream: EventStream, captureType: EventType, stopCondition: (e: T) => boolean, timeout: number): Promise<T> { |
| 33 | + let event: T = null; |
| 34 | + |
| 35 | + const subscription = stream.subscribe((e: BaseEvent) => { |
| 36 | + if (e.type === captureType) { |
| 37 | + const tEvent = <T>e; |
| 38 | + |
| 39 | + if (stopCondition(tEvent)) { |
| 40 | + event = tEvent; |
| 41 | + subscription.unsubscribe(); |
| 42 | + } |
| 43 | + } |
| 44 | + }); |
| 45 | + |
| 46 | + await poll(() => event, timeout, 500, e => !!e); |
| 47 | + |
| 48 | + return event; |
| 49 | +} |
| 50 | + |
| 51 | +suite(`DotnetTest: ${testAssetWorkspace.description}`, function () { |
| 52 | + let fileUri: vscode.Uri; |
| 53 | + let eventStream: EventStream; |
| 54 | + |
| 55 | + suiteSetup(async function () { |
| 56 | + should(); |
| 57 | + |
| 58 | + // These tests only run on the slnWithCsproj solution |
| 59 | + if (!isSlnWithCsproj(vscode.workspace)) { |
| 60 | + this.skip(); |
| 61 | + } |
| 62 | + else { |
| 63 | + const activation = await activateCSharpExtension(); |
| 64 | + await testAssetWorkspace.restoreAndWait(activation); |
| 65 | + |
| 66 | + eventStream = activation.eventStream; |
| 67 | + |
| 68 | + let fileName = 'UnitTest1.cs'; |
| 69 | + let projectDirectory = testAssetWorkspace.projects[2].projectDirectoryPath; |
| 70 | + let filePath = path.join(projectDirectory, fileName); |
| 71 | + fileUri = vscode.Uri.file(filePath); |
| 72 | + |
| 73 | + await vscode.commands.executeCommand("vscode.open", fileUri); |
| 74 | + |
| 75 | + await waitActivityToSettle(eventStream, 90 * 1000); |
| 76 | + } |
| 77 | + }); |
| 78 | + |
| 79 | + suiteTeardown(async () => { |
| 80 | + await testAssetWorkspace.cleanupWorkspace(); |
| 81 | + }); |
| 82 | + |
| 83 | + test("Undefined runsettings path is unchanged", async function () { |
| 84 | + const omnisharpConfig = vscode.workspace.getConfiguration('omnisharp'); |
| 85 | + await omnisharpConfig.update('testRunSettings', undefined); |
| 86 | + |
| 87 | + const eventWaiter = waitForEvent<OmnisharpRequestMessage>(eventStream, EventType.OmnisharpRequestMessage, e => e.request.command === V2.Requests.RunTestsInContext, /* timeout */ 10 * 1000); |
| 88 | + |
| 89 | + await vscode.commands.executeCommand('dotnet.test.runTestsInContext'); |
| 90 | + |
| 91 | + const event = await eventWaiter; |
| 92 | + const runTestsRequest = <V2.RunTestsInContextRequest>event.request.data; |
| 93 | + |
| 94 | + expect(runTestsRequest.RunSettings).to.be.undefined; |
| 95 | + }); |
| 96 | + |
| 97 | + test("Absolute runsettings path is unchanged", async function () { |
| 98 | + const relativeRunSettingsPath = `.\\settings\\TestSettings.runsettings`.replace("\\", path.sep); |
| 99 | + const absoluteRunSettingsPath = path.join(process.cwd(), relativeRunSettingsPath); |
| 100 | + |
| 101 | + const omnisharpConfig = vscode.workspace.getConfiguration('omnisharp'); |
| 102 | + await omnisharpConfig.update('testRunSettings', absoluteRunSettingsPath); |
| 103 | + |
| 104 | + const eventWaiter = waitForEvent<OmnisharpRequestMessage>(eventStream, EventType.OmnisharpRequestMessage, e => e.request.command === V2.Requests.RunTestsInContext, /* timeout */ 10 * 1000); |
| 105 | + |
| 106 | + await vscode.commands.executeCommand('dotnet.test.runTestsInContext'); |
| 107 | + |
| 108 | + const event = await eventWaiter; |
| 109 | + const runTestsRequest = <V2.RunTestsInContextRequest>event.request.data; |
| 110 | + |
| 111 | + expect(runTestsRequest.RunSettings).to.be.equal(absoluteRunSettingsPath); |
| 112 | + }); |
| 113 | + |
| 114 | + test("Relative runsettings path is made absolute", async function () { |
| 115 | + const endingPath = 'settings\\TestSettings.runsettings'.replace("\\", path.sep); |
| 116 | + const relativeRunSettingPath = `.\\${endingPath}`.replace("\\", path.sep); |
| 117 | + |
| 118 | + const omnisharpConfig = vscode.workspace.getConfiguration('omnisharp'); |
| 119 | + await omnisharpConfig.update('testRunSettings', relativeRunSettingPath); |
| 120 | + |
| 121 | + const eventWaiter = waitForEvent<OmnisharpRequestMessage>(eventStream, EventType.OmnisharpRequestMessage, e => e.request.command === V2.Requests.RunTestsInContext, /* timeout */ 10 * 1000); |
| 122 | + |
| 123 | + await vscode.commands.executeCommand('dotnet.test.runTestsInContext'); |
| 124 | + |
| 125 | + const event = await eventWaiter; |
| 126 | + const runTestsRequest = <V2.RunTestsInContextRequest>event.request.data; |
| 127 | + |
| 128 | + expect(runTestsRequest.RunSettings).to.be.not.null; |
| 129 | + expect(runTestsRequest.RunSettings.endsWith(endingPath), "Path includes relative path").to.be.true; |
| 130 | + expect(path.isAbsolute(runTestsRequest.RunSettings), "Path is absolute").to.be.true; |
| 131 | + }); |
| 132 | +}); |
| 133 | + |
0 commit comments