-
Notifications
You must be signed in to change notification settings - Fork 727
Capture separate logs for each lsptoolshost test suite #8529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import { EOL, platform } from 'os'; | ||
import { describe, expect, test } from '@jest/globals'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separated these helpers out because they use |
||
import { usingDevKit } from './lsptoolshost/integrationTests/integrationHelpers'; | ||
|
||
export async function expectText(document: vscode.TextDocument, expectedLines: string[]) { | ||
const expectedText = expectedLines.join(EOL); | ||
expect(document.getText()).toBe(expectedText); | ||
} | ||
|
||
export function expectPath(expected: vscode.Uri, actual: vscode.Uri) { | ||
if (isLinux()) { | ||
expect(actual.path).toBe(expected.path); | ||
} else { | ||
const actualPath = actual.path.toLowerCase(); | ||
const expectedPath = expected.path.toLocaleLowerCase(); | ||
expect(actualPath).toBe(expectedPath); | ||
} | ||
} | ||
|
||
export const describeIfCSharp = describeIf(!usingDevKit()); | ||
export const describeIfDevKit = describeIf(usingDevKit()); | ||
export const describeIfNotMacOS = describeIf(!isMacOS()); | ||
export const describeIfWindows = describeIf(isWindows()); | ||
export const testIfCSharp = testIf(!usingDevKit()); | ||
export const testIfDevKit = testIf(usingDevKit()); | ||
export const testIfNotMacOS = testIf(!isMacOS()); | ||
export const testIfWindows = testIf(isWindows()); | ||
|
||
function describeIf(condition: boolean) { | ||
return condition ? describe : describe.skip; | ||
} | ||
|
||
function testIf(condition: boolean) { | ||
return condition ? test : test.skip; | ||
} | ||
|
||
function isMacOS() { | ||
const currentPlatform = platform(); | ||
return currentPlatform === 'darwin'; | ||
} | ||
|
||
function isWindows() { | ||
const currentPlatform = platform(); | ||
return currentPlatform === 'win32'; | ||
} | ||
|
||
function isLinux() { | ||
return !(isMacOS() || isWindows()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,73 @@ | |
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import * as fsExtra from 'fs-extra'; | ||
import path from 'path'; | ||
import { AggregatedResult } from '@jest/test-result'; | ||
import { runIntegrationTests } from '../../runIntegrationTests'; | ||
import { jestIntegrationTestProjectName } from './jest.config'; | ||
import { activateCSharpExtension } from './integrationHelpers'; | ||
|
||
export async function run() { | ||
process.env.RUNNING_INTEGRATION_TESTS = 'true'; | ||
|
||
await runIntegrationTests(jestIntegrationTestProjectName); | ||
await activateCSharpExtension(); | ||
await moveLogs('activated'); | ||
|
||
let anyFailures = false; | ||
let results: AggregatedResult | undefined; | ||
if (process.env.TEST_FILE_FILTER) { | ||
results = await runIntegrationTests(jestIntegrationTestProjectName); | ||
await moveLogs(path.basename(process.env.TEST_FILE_FILTER, '.integration.test.ts')); | ||
anyFailures = anyFailures || !results.success; | ||
} else { | ||
const workingDirectory = process.cwd(); | ||
|
||
const testFiles = (await fsExtra.readdir(__dirname)) | ||
.filter((file) => file.endsWith('.integration.test.js')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of doing this, I think you could probably simplify all this by getting the rootPath here, and then just go directly to the typescript files? |
||
.map((file) => path.join(__dirname, file)); | ||
|
||
for (let file of testFiles) { | ||
// We have to fix up the file path because the test file was discovered in the /out/ directory. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do sourcemaps still work if we do this? e.g. f5 launching integration tests is fine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. our launch targets set the |
||
file = file.substring(0, file.length - 2) + 'ts'; | ||
file = file.replace(/[\\/]out[\\/]/, path.sep); | ||
file = workingDirectory[0] + file.substring(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So locally |
||
|
||
console.log(''); | ||
console.log(`-- Running integration tests for ${path.basename(file)} --`); | ||
console.log(''); | ||
|
||
process.env.TEST_FILE_FILTER = file; | ||
|
||
results = await runIntegrationTests(jestIntegrationTestProjectName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current runs logs should still be in the logs folder even if they aren't moved. |
||
await moveLogs(path.basename(process.env.TEST_FILE_FILTER, '.integration.test.ts')); | ||
anyFailures = anyFailures || !results.success; | ||
} | ||
} | ||
|
||
// Explicitly exit the process - VSCode likes to write a bunch of cancellation errors to the console after this | ||
// which make it look like the tests always fail. We're done with the tests at this point, so just exit. | ||
process.exit(anyFailures ? 1 : 0); | ||
} | ||
|
||
async function moveLogs(name: string) { | ||
const exports = vscode.extensions.getExtension('ms-dotnettools.csharp')?.exports; | ||
if (!exports) { | ||
throw new Error('Failed to get C# extension exports for cleanup'); | ||
} | ||
|
||
if (!exports.logDirectory) { | ||
console.warn(`Failed to get log directory from C# extension exports`); | ||
return; | ||
} | ||
|
||
const targetLogDir = path.join( | ||
path.dirname(exports.logDirectory), | ||
`${name ?? 'unknown'}_${path.basename(exports.logDirectory)}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can remove unknown, name isn't nullable here |
||
); | ||
await fsExtra.copy(exports.logDirectory, targetLogDir); | ||
console.log(`Copied extension logs from ${exports.logDirectory} to ${targetLogDir}`); | ||
|
||
await new Promise((resolve) => fsExtra.rm(path.join(exports.logDirectory, '*.log'), resolve)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed project loading did not like running on a .NET 10 preview while building net6.0 projects.