Skip to content

Commit

Permalink
Refactor unit and functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Loose committed Dec 11, 2019
1 parent 5d68c3e commit 9b2d5ef
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 67 deletions.
91 changes: 36 additions & 55 deletions src/test/testing/display/picker.functional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,17 @@ suite('Testing - TestDisplay', () => {

suite('displayFunctionTestPickerUI', () => {

const tests = createEmptyResults();
let paths: {
[match: string]: { fullPath: string; fileName: string };
mismatch: { fullPath: string; fileName: string };
};
let platformPaths: {
[win32: string]: { fullPath: string; fileName: string };
linux: { fullPath: string; fileName: string };
darwin: { fullPath: string; fileName: string };
const paths: { [key: string]: any } = {
match: {
fullPath: '/path/to/testfile',
fileName: '/path/to/testfile'
},
mismatch: {
fullPath: '/path/to/testfile',
fileName: '/testfile/to/path'
}
};
let tests: Tests;

function codeLensTestFunctions(testfunctions?: TestFunction[]): TestFunction[] {
if (!testfunctions) {
Expand All @@ -75,66 +76,46 @@ suite('Testing - TestDisplay', () => {
}

setup(() => {
paths = {
match: {
fullPath: 'path/to/testfile',
fileName: 'path/to/testfile'
},
mismatch: {
fullPath: 'path/to/testfile',
fileName: 'testfile/to/path'
}
};
platformPaths = {
win32: {
fullPath: 'C:\\path\\to\\testfile',
fileName: 'c:\\path\\to\\testfile'
},
linux: {
fullPath: 'path/to/testfile',
fileName: 'path/to/testfile'
},
darwin: {
fullPath: 'path/to/testfile',
fileName: 'path/to/testfile'
}
};
tests = createEmptyResults();
when(mockedServiceContainer.get<IFileSystem>(IFileSystem)).thenReturn(new FileSystem());
when(mockedTestCollectionStorage.getTests(wkspace)).thenReturn(tests);
when(mockedAppShell.showQuickPick(anything(), anything())).thenResolve();
});

['match', 'mismatch'].forEach(matchType => {
test(`#8627 codelens on parametrized tests does not open dropdown picker on windows (paths=>${matchType})`, () => {
test(`Test that a dropdown picker for parametrized tests is shown if compared paths are equal (OS independent) (#8627)`, () => {

const { fullPath, fileName } = paths[matchType];
fullPathInTests(tests, fullPath);
const { fullPath, fileName } = paths.match;
fullPathInTests(tests, fullPath);

testDisplay.displayFunctionTestPickerUI(CommandSource.commandPalette, wkspace, 'rootDirectory', Uri.parse(fileName), codeLensTestFunctions());
testDisplay.displayFunctionTestPickerUI(CommandSource.commandPalette, wkspace, 'rootDirectory', Uri.file(fileName), codeLensTestFunctions());

if (matchType === 'match') {
verify(mockedAppShell.showQuickPick(anything(), anything())).once();
} else {
verify(mockedAppShell.showQuickPick(anything(), anything())).never();
}
});
verify(mockedAppShell.showQuickPick(anything(), anything())).once();
});

['win32', 'linux', 'darwin'].forEach(platform => {
test(`#8627 codelens on parametrized tests does not open dropdown picker on windows (platform=>${platform})`, function () {
test(`Test that a dropdown picker for parametrized tests is NOT shown if compared paths are NOT equal (OS independent) (#8627)`, () => {

if (platform !== process.platform) {
// tslint:disable-next-line: no-invalid-this
this.skip();
}
const { fullPath, fileName } = paths.mismatch;
fullPathInTests(tests, fullPath);

const { fullPath, fileName } = platformPaths[platform];
fullPathInTests(tests, fullPath);
testDisplay.displayFunctionTestPickerUI(CommandSource.commandPalette, wkspace, 'rootDirectory', Uri.file(fileName), codeLensTestFunctions());

verify(mockedAppShell.showQuickPick(anything(), anything())).never();
});

test(`Test that clicking a codelens on parametrized tests opens a dropdown picker on windows (#8627)`, function () {

if (process.platform !== 'win32') {
// tslint:disable-next-line: no-invalid-this
this.skip();
}
// The error described in #8627 originated from the problem that the casing of the drive letter was different
// in a test items fullPath property to the one of a file that contained the clicked parametrized test.
const fileName = 'c:\\path\\to\\testfile';
fullPathInTests(tests, 'C:\\path\\to\\testfile');

testDisplay.displayFunctionTestPickerUI(CommandSource.commandPalette, wkspace, 'rootDirectory', Uri.parse(fileName), codeLensTestFunctions());
testDisplay.displayFunctionTestPickerUI(CommandSource.commandPalette, wkspace, 'rootDirectory', Uri.file(fileName), codeLensTestFunctions());

verify(mockedAppShell.showQuickPick(anything(), anything())).once();
});
verify(mockedAppShell.showQuickPick(anything(), anything())).once();
});
});
});
29 changes: 17 additions & 12 deletions src/test/testing/display/picker.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ suite('Testing - TestDisplay', () => {

suite('displayFunctionTestPickerUI', () => {

const tests = createEmptyResults();
const fileName = Uri.file('path/to/testfile');
let tests: Tests;

function codeLensTestFunctions(testfunctions?: TestFunction[]): TestFunction[] {
if (!testfunctions) {
Expand All @@ -136,26 +136,31 @@ suite('Testing - TestDisplay', () => {
}

setup(() => {
tests = createEmptyResults();
mockedFileSytem = mock(FileSystem);
when(mockedServiceContainer.get<IFileSystem>(IFileSystem)).thenReturn(instance(mockedFileSytem));
when(mockedTestCollectionStorage.getTests(wkspace)).thenReturn(tests);
when(mockedAppShell.showQuickPick(anything(), anything())).thenResolve();
});

[true, false].forEach(arePathSame => {
test(`#8627 codelens on parametrized tests does not open dropdown picker on windows (FileSystem.arePathSame=>${arePathSame})`, () => {
test(`Test that a dropdown picker for parametrized tests is shown if compared paths are equal (#8627)`, () => {

fullPathInTests(tests);
when(mockedFileSytem.arePathsSame(anything(), anything())).thenReturn(arePathSame);
fullPathInTests(tests);
when(mockedFileSytem.arePathsSame(anything(), anything())).thenReturn(true);

testDisplay.displayFunctionTestPickerUI(CommandSource.commandPalette, wkspace, 'rootDirectory', fileName, codeLensTestFunctions());
testDisplay.displayFunctionTestPickerUI(CommandSource.commandPalette, wkspace, 'rootDirectory', fileName, codeLensTestFunctions());

if (arePathSame) {
verify(mockedAppShell.showQuickPick(anything(), anything())).once();
} else {
verify(mockedAppShell.showQuickPick(anything(), anything())).never();
}
});
verify(mockedAppShell.showQuickPick(anything(), anything())).once();
});

test(`Test that a dropdown picker for parametrized tests is NOT shown if compared paths are NOT equal (#8627)`, () => {

fullPathInTests(tests);
when(mockedFileSytem.arePathsSame(anything(), anything())).thenReturn(false);

testDisplay.displayFunctionTestPickerUI(CommandSource.commandPalette, wkspace, 'rootDirectory', fileName, codeLensTestFunctions());

verify(mockedAppShell.showQuickPick(anything(), anything())).never();
});
});
});

0 comments on commit 9b2d5ef

Please sign in to comment.