Skip to content

Commit

Permalink
Adding basic test for markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Feb 8, 2018
1 parent 5cf57a1 commit 14b7051
Show file tree
Hide file tree
Showing 6 changed files with 1,774 additions and 13 deletions.
15 changes: 14 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"version": "0.1.0",
"configurations": [

{
"type": "node",
"request": "launch",
Expand Down Expand Up @@ -160,6 +159,20 @@
"${workspaceFolder}/extensions/git/out/**/*.js"
]
},
{
"type": "extensionHost",
"request": "launch",
"name": "VS Code Markdown Extension Tests",
"runtimeExecutable": "${execPath}",
"args": [
"${workspaceFolder}/extensions/markdown/test-fixtures",
"--extensionDevelopmentPath=${workspaceFolder}/extensions/markdown",
"--extensionTestsPath=${workspaceFolder}/extensions/markdown/out/test"
],
"outFiles": [
"${workspaceFolder}/extensions/markdown/out/**/*.js"
]
},
{
"type": "node",
"request": "launch",
Expand Down
5 changes: 3 additions & 2 deletions extensions/markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"publisher": "Microsoft",
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
"engines": {
"vscode": "^1.0.0"
"vscode": "^1.20.0"
},
"main": "./out/extension",
"categories": [
Expand Down Expand Up @@ -336,6 +336,7 @@
"@types/markdown-it": "0.0.2",
"@types/node": "7.0.43",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4"
"gulp-replace": "^0.5.4",
"vscode": "^1.1.10"
}
}
1 change: 0 additions & 1 deletion extensions/markdown/src/tableOfContentsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,3 @@ export class TableOfContentsProvider {
return header.replace(/^\s*#+\s*(.*?)\s*#*$/, (_, word) => word.trim());
}
}

28 changes: 28 additions & 0 deletions extensions/markdown/src/test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

//
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
//
// This file is providing the test runner to use when running extension tests.
// By default the test runner in use is Mocha based.
//
// You can provide your own test runner if you want to override it by exporting
// a function run(testRoot: string, clb: (error:Error) => void) that the extension
// host can call to run the tests. The test runner is expected to use console.log
// to report the results back to the caller. When the tests are finished, return
// a possible error to the callback or null if none.

const testRunner = require('vscode/lib/testrunner');

// You can directly control Mocha options by uncommenting the following lines
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
testRunner.configure({
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
useColors: process.platform !== 'win32', // colored output from test results (only windows cannot handle)
timeout: 60000
});

export = testRunner;
75 changes: 75 additions & 0 deletions extensions/markdown/src/test/tableOfContentsProvider.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import * as vscode from 'vscode';

import { TableOfContentsProvider } from '../tableOfContentsProvider';
import { MarkdownEngine } from '../markdownEngine';

suite('markdown.TableOfContentsProvider', () => {
test('Should not return anything for empty document', async () => {
const doc = new InMemoryDocument(vscode.Uri.parse('test.md'), '');
const provider = new TableOfContentsProvider(new MarkdownEngine(), doc);

assert.strictEqual(await provider.lookup(''), undefined);
assert.strictEqual(await provider.lookup('foo'), undefined);
});
});

class InMemoryDocument implements vscode.TextDocument {
private readonly _lines: string[];

constructor(
public readonly uri: vscode.Uri,
contents: string
) {
this._lines = contents.split(/\n/g);
}

fileName: string = '';
isUntitled: boolean = false;
languageId: string = '';
version: number = 1;
isDirty: boolean = false;
isClosed: boolean = false;
eol: vscode.EndOfLine = vscode.EndOfLine.LF;

get lineCount(): number {
return this._lines.length;
}

lineAt(line: any): vscode.TextLine {
return {
lineNumber: line,
text: this._lines[line],
range: new vscode.Range(0, 0, 0, 0),
firstNonWhitespaceCharacterIndex: 0,
rangeIncludingLineBreak: new vscode.Range(0, 0, 0, 0),
isEmptyOrWhitespace: false
};
}
offsetAt(_position: vscode.Position): never {
throw new Error('Method not implemented.');
}
positionAt(_offset: number): never{
throw new Error('Method not implemented.');
}
getText(_range?: vscode.Range | undefined): never {
throw new Error('Method not implemented.');
}
getWordRangeAtPosition(_position: vscode.Position, _regex?: RegExp | undefined): never {
throw new Error('Method not implemented.');
}
validateRange(_range: vscode.Range): never {
throw new Error('Method not implemented.');
}
validatePosition(_position: vscode.Position): never {
throw new Error('Method not implemented.');
}
save(): never {
throw new Error('Method not implemented.');
}
}
Loading

0 comments on commit 14b7051

Please sign in to comment.