Add First Test
This commit is contained in:
parent
e1d41f6025
commit
b9b6aec528
6 changed files with 88 additions and 29 deletions
|
|
@ -1,17 +1,42 @@
|
|||
//
|
||||
// Note: This example test is leveraging the Mocha test framework.
|
||||
// Please refer to their documentation on https://mochajs.org/ for help.
|
||||
//
|
||||
|
||||
// The module 'assert' provides assertion methods from node
|
||||
import * as assert from "assert";
|
||||
import { FormattingOptions } from "vscode";
|
||||
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
import * as vscode from "vscode";
|
||||
import * as myExtension from "../extension";
|
||||
import { TestDataLoader } from "./test-utils/test-data-loader";
|
||||
|
||||
import { XmlFormatter } from "../formatting/xml-formatter";
|
||||
import { XmlFormattingOptions } from "../formatting/xml-formatting-options";
|
||||
import { V2XmlFormatter } from "../formatting/formatters/v2-xml-formatter";
|
||||
|
||||
describe("V2XmlFormatter", () => {
|
||||
|
||||
const xmlFormatter = new V2XmlFormatter();
|
||||
|
||||
describe("#formatXml(xml, options)", () => {
|
||||
|
||||
const options = {
|
||||
editorOptions: {
|
||||
insertSpaces: true,
|
||||
tabSize: 4
|
||||
},
|
||||
newLine: "\r\n",
|
||||
removeCommentsOnMinify: false,
|
||||
splitAttributesOnFormat: false,
|
||||
splitXmlnsOnFormat: true
|
||||
};
|
||||
|
||||
it("should handle basic XML", () => {
|
||||
testFormatter(xmlFormatter, options, "basic");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// Defines a Mocha test suite to group tests of similar kind together
|
||||
suite("Extension Tests", () => {
|
||||
// TODO: implement tests
|
||||
});
|
||||
|
||||
function testFormatter(xmlFormatter: XmlFormatter, options: XmlFormattingOptions, fileLabel: string): void {
|
||||
const expectedFormattedXml = TestDataLoader.load(`${fileLabel}.formatted.xml`);
|
||||
const unformattedXml = TestDataLoader.load(`${fileLabel}.unformatted.xml`);
|
||||
|
||||
const actualFormattedXml = xmlFormatter.formatXml(unformattedXml, options);
|
||||
|
||||
assert.equal(actualFormattedXml, expectedFormattedXml, "Actual formatted XML does not match expected formatted XML.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import * as testRunner from "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.)
|
||||
ui: "bdd",
|
||||
useColors: true // colored output from test results
|
||||
});
|
||||
|
||||
|
|
|
|||
3
src/test/test-data/basic.formatted.xml
Normal file
3
src/test/test-data/basic.formatted.xml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<root>
|
||||
<element>text</element>
|
||||
</root>
|
||||
1
src/test/test-data/basic.unformatted.xml
Normal file
1
src/test/test-data/basic.unformatted.xml
Normal file
|
|
@ -0,0 +1 @@
|
|||
<root><element>text</element></root>
|
||||
7
src/test/test-utils/test-data-loader.ts
Normal file
7
src/test/test-utils/test-data-loader.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import * as fs from "fs";
|
||||
|
||||
export class TestDataLoader {
|
||||
static load(fileName: string): string {
|
||||
return fs.readFileSync(`${__dirname}/../../../src/test/test-data/${fileName}`, "UTF-8");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue