-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1122 from JL03-Yue/JL03-Yue/error-issue
fix logging issue and add a logging unit test
- Loading branch information
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
vscode-dotnet-runtime-library/src/test/unit/LoggingObserver.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
import * as chai from 'chai'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { LoggingObserver } from '../../EventStream/LoggingObserver'; | ||
import { MockEventStream } from '../mocks/MockObjects'; | ||
import { DotnetUninstallAllStarted } from '../../EventStream/EventStreamEvents'; | ||
const assert = chai.assert; | ||
|
||
suite('LoggingObserver Unit Tests', () => { | ||
const eventStream = new MockEventStream(); | ||
const tempPath = path.join(__dirname, `${ new Date().getTime()}` ); | ||
|
||
test('Log file is writing output', async () => { | ||
// Create an empty folder | ||
if (!fs.existsSync(tempPath)) { | ||
fs.mkdirSync(tempPath); | ||
} | ||
// Create a logging observer | ||
const loggingObserver = new LoggingObserver(path.join(tempPath, 'logTest.txt')); | ||
|
||
// Create a fake event and call the post/dispose function | ||
const fakeEvent = new DotnetUninstallAllStarted(); | ||
loggingObserver.post(fakeEvent); | ||
loggingObserver.dispose(); | ||
|
||
// Check if the log file content is same as expected content | ||
fs.readdirSync(tempPath).forEach(file => { | ||
const logContent = fs.readFileSync(path.join(tempPath, file)).toString(); | ||
assert.include(logContent, fakeEvent.eventName, 'The log file does not contain the expected content that should be written to it?'); | ||
}); | ||
|
||
}); | ||
}); |