mirror of
https://github.com/VSCodeVim/Vim.git
synced 2024-09-11 12:25:59 +03:00
Replace getTestingFunctions
with plain old exports/imports
Not sure why it was ever done this way
This commit is contained in:
parent
ca4e60284d
commit
1564e647dc
@ -10,10 +10,8 @@ import {
|
||||
reloadConfiguration,
|
||||
setupWorkspace,
|
||||
} from './../testUtils';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
|
||||
import { newTest } from '../testSimplifier';
|
||||
suite('Basic substitute', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
let modeHandler: ModeHandler;
|
||||
|
||||
setup(async () => {
|
||||
|
@ -2,11 +2,10 @@ import * as assert from 'assert';
|
||||
import * as srcConfiguration from '../../src/configuration/configuration';
|
||||
import * as testConfiguration from '../testConfiguration';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './../testUtils';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { Mode } from '../../src/mode/mode';
|
||||
import { newTest } from '../testSimplifier';
|
||||
|
||||
suite('Configuration', () => {
|
||||
const { newTest } = getTestingFunctions();
|
||||
const configuration = new testConfiguration.Configuration();
|
||||
configuration.leader = '<space>';
|
||||
configuration.normalModeKeyBindingsNonRecursive = [
|
||||
|
@ -1,14 +1,12 @@
|
||||
import * as assert from 'assert';
|
||||
import { getAndUpdateModeHandler } from '../../extension';
|
||||
import { Mode } from '../../src/mode/mode';
|
||||
import { ModeHandler } from '../../src/mode/modeHandler';
|
||||
import { Configuration } from '../testConfiguration';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { newTestWithRemaps } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from '../testUtils';
|
||||
|
||||
suite('Remaps', () => {
|
||||
let modeHandler: ModeHandler;
|
||||
const { newTestWithRemaps, newTestWithRemapsOnly, newTestWithRemapsSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
const configuration = new Configuration();
|
||||
|
@ -4,12 +4,10 @@ import * as vscode from 'vscode';
|
||||
import { Jump } from './../src/jumps/jump';
|
||||
import { JumpTracker } from '../src/jumps/jumpTracker';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './testUtils';
|
||||
import { getTestingFunctions } from './testSimplifier';
|
||||
import { Position } from 'vscode';
|
||||
import { newTest } from './testSimplifier';
|
||||
|
||||
suite('Record and navigate jumps', () => {
|
||||
const { newTest } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
});
|
||||
|
@ -1,9 +1,7 @@
|
||||
import { getTestingFunctions } from './testSimplifier';
|
||||
import { newTest } from './testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './testUtils';
|
||||
|
||||
suite('Record and execute a macro', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
});
|
||||
|
@ -1,26 +1,21 @@
|
||||
import * as assert from 'assert';
|
||||
|
||||
import * as error from '../../src/error';
|
||||
|
||||
import { getAndUpdateModeHandler } from '../../extension';
|
||||
import { Mode } from '../../src/mode/mode';
|
||||
import { ModeHandler } from '../../src/mode/modeHandler';
|
||||
import { TextEditor } from '../../src/textEditor';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import {
|
||||
assertEqualLines,
|
||||
assertStatusBarEqual,
|
||||
cleanUpWorkspace,
|
||||
setupWorkspace,
|
||||
reloadConfiguration,
|
||||
} from './../testUtils';
|
||||
import { Globals } from '../../src/globals';
|
||||
import { newTest } from '../testSimplifier';
|
||||
|
||||
suite('Mode Insert', () => {
|
||||
let modeHandler: ModeHandler;
|
||||
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
modeHandler = await getAndUpdateModeHandler();
|
||||
|
@ -4,12 +4,11 @@ import { Mode } from '../../src/mode/mode';
|
||||
import { ModeHandler } from '../../src/mode/modeHandler';
|
||||
import { TextEditor } from '../../src/textEditor';
|
||||
import { Configuration } from '../testConfiguration';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { newTest } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './../testUtils';
|
||||
|
||||
suite('Mode Normal', () => {
|
||||
let modeHandler: ModeHandler;
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
const configuration = new Configuration();
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './../testUtils';
|
||||
import { Mode } from '../../src/mode/mode';
|
||||
import { newTest } from '../testSimplifier';
|
||||
|
||||
suite('Mode Replace', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
});
|
||||
|
@ -5,7 +5,7 @@ import { Globals } from '../../src/globals';
|
||||
import { Mode } from '../../src/mode/mode';
|
||||
import { ModeHandler } from '../../src/mode/modeHandler';
|
||||
import { TextEditor } from '../../src/textEditor';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { newTest, newTestSkip } from '../testSimplifier';
|
||||
import {
|
||||
assertEqualLines,
|
||||
cleanUpWorkspace,
|
||||
@ -16,8 +16,6 @@ import {
|
||||
suite('Mode Visual', () => {
|
||||
let modeHandler: ModeHandler;
|
||||
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
modeHandler = await getAndUpdateModeHandler();
|
||||
|
@ -4,14 +4,12 @@ import * as assert from 'assert';
|
||||
import { getAndUpdateModeHandler } from '../../extension';
|
||||
import { Mode } from '../../src/mode/mode';
|
||||
import { ModeHandler } from '../../src/mode/modeHandler';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { assertEqualLines, cleanUpWorkspace, setupWorkspace } from './../testUtils';
|
||||
import { newTest } from '../testSimplifier';
|
||||
|
||||
suite('Mode Visual Block', () => {
|
||||
let modeHandler: ModeHandler;
|
||||
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
modeHandler = await getAndUpdateModeHandler();
|
||||
|
@ -4,14 +4,12 @@ import { getAndUpdateModeHandler } from '../../extension';
|
||||
import { Mode } from '../../src/mode/mode';
|
||||
import { ModeHandler } from '../../src/mode/modeHandler';
|
||||
import { TextEditor } from '../../src/textEditor';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { newTest } from '../testSimplifier';
|
||||
import { assertEqualLines, cleanUpWorkspace, setupWorkspace } from './../testUtils';
|
||||
|
||||
suite('Mode Visual Line', () => {
|
||||
let modeHandler: ModeHandler;
|
||||
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
modeHandler = await getAndUpdateModeHandler();
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { Mode } from '../../../src/mode/mode';
|
||||
import { getTestingFunctions } from '../../testSimplifier';
|
||||
import { newTest } from '../../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from '../../testUtils';
|
||||
|
||||
suite('Mode Normal', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
});
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { Configuration } from '../../testConfiguration';
|
||||
import { getTestingFunctions } from '../../testSimplifier';
|
||||
import { newTest } from '../../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './../../testUtils';
|
||||
|
||||
suite('Dot Operator', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
const configuration = new Configuration();
|
||||
configuration.tabstop = 4;
|
||||
@ -66,8 +64,6 @@ suite('Dot Operator', () => {
|
||||
});
|
||||
|
||||
suite('Repeat content change', () => {
|
||||
const { newTest, newTestOnly } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
const configuration = new Configuration();
|
||||
configuration.tabstop = 4;
|
||||
@ -115,8 +111,6 @@ suite('Repeat content change', () => {
|
||||
});
|
||||
|
||||
suite('Dot Operator repeat with remap', () => {
|
||||
const { newTest, newTestOnly } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
const configuration = new Configuration();
|
||||
configuration.insertModeKeyBindings = [
|
||||
|
@ -1,9 +1,7 @@
|
||||
import { getTestingFunctions } from '../../testSimplifier';
|
||||
import { newTest } from '../../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './../../testUtils';
|
||||
|
||||
suite('Matching Bracket (%)', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
});
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { getTestingFunctions } from '../../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './../../testUtils';
|
||||
import { Mode } from '../../../src/mode/mode';
|
||||
import { newTest, newTestSkip } from '../../testSimplifier';
|
||||
|
||||
suite('Motions in Normal Mode', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
});
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { Configuration } from './testConfiguration';
|
||||
import { getTestingFunctions } from './testSimplifier';
|
||||
import { newTest } from './testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './testUtils';
|
||||
|
||||
suite('motion line wrapping', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
teardown(cleanUpWorkspace);
|
||||
|
||||
suite('whichwrap enabled', () => {
|
||||
|
@ -2,8 +2,8 @@ import * as assert from 'assert';
|
||||
import { getAndUpdateModeHandler } from '../extension';
|
||||
import { ModeHandler } from '../src/mode/modeHandler';
|
||||
import { assertEqualLines, cleanUpWorkspace, setupWorkspace } from './testUtils';
|
||||
import { getTestingFunctions } from './testSimplifier';
|
||||
import { Configuration } from './testConfiguration';
|
||||
import { newTest } from './testSimplifier';
|
||||
|
||||
suite('Multicursor', () => {
|
||||
let modeHandler: ModeHandler;
|
||||
@ -107,8 +107,6 @@ suite('Multicursor', () => {
|
||||
});
|
||||
|
||||
suite('Multicursor with remaps', () => {
|
||||
const { newTest, newTestOnly } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
const configuration = new Configuration();
|
||||
configuration.insertModeKeyBindings = [
|
||||
@ -132,8 +130,6 @@ suite('Multicursor with remaps', () => {
|
||||
});
|
||||
|
||||
suite('Multicursor selections', () => {
|
||||
const { newTest, newTestOnly } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
const configuration = new Configuration();
|
||||
configuration.normalModeKeyBindings = [
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { Mode } from '../../src/mode/mode';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { newTest } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './../testUtils';
|
||||
|
||||
suite('comment operator', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace(undefined, '.js');
|
||||
});
|
||||
|
@ -1,9 +1,7 @@
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { newTest } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from '../testUtils';
|
||||
|
||||
suite('filter operator', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
});
|
||||
|
@ -1,9 +1,7 @@
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { newTest } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './../testUtils';
|
||||
|
||||
suite('format operator', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace(undefined, '.ts');
|
||||
});
|
||||
|
@ -1,9 +1,7 @@
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { newTest } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from '../testUtils';
|
||||
|
||||
suite('put operator', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
});
|
||||
|
@ -1,13 +1,10 @@
|
||||
import * as assert from 'assert';
|
||||
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
|
||||
import { setupWorkspace, cleanUpWorkspace } from '../testUtils';
|
||||
import { ROT13Operator } from '../../src/actions/operator';
|
||||
import { newTest } from '../testSimplifier';
|
||||
|
||||
suite('rot13 operator', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
});
|
||||
|
@ -1,9 +1,7 @@
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { newTest } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from '../testUtils';
|
||||
|
||||
suite('shift operator', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
});
|
||||
|
@ -1,8 +1,6 @@
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './../testUtils';
|
||||
import { Configuration } from '../testConfiguration';
|
||||
|
||||
const { newTest } = getTestingFunctions();
|
||||
import { newTest } from '../testSimplifier';
|
||||
|
||||
suite('camelCaseMotion plugin if not enabled', () => {
|
||||
setup(async () => {
|
||||
|
@ -3,7 +3,7 @@ import {
|
||||
EasymotionTrigger,
|
||||
} from '../../src/actions/plugins/easymotion/easymotion.cmd';
|
||||
import { Configuration } from '../testConfiguration';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { newTest } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './../testUtils';
|
||||
|
||||
function easymotionCommand(trigger: EasymotionTrigger, searchWord: string, jumpKey: string) {
|
||||
@ -11,8 +11,6 @@ function easymotionCommand(trigger: EasymotionTrigger, searchWord: string, jumpK
|
||||
}
|
||||
|
||||
suite('easymotion plugin', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
const configuration = new Configuration();
|
||||
configuration.easymotion = true;
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { Globals } from '../../src/globals';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { newTest } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace, reloadConfiguration } from '../testUtils';
|
||||
|
||||
suite('replaceWithRegister plugin', () => {
|
||||
const { newTest } = getTestingFunctions();
|
||||
const YankInnerWord = 'yiw';
|
||||
const ReplaceOperator = 'gr';
|
||||
|
||||
|
@ -1,9 +1,7 @@
|
||||
import { Globals } from '../../src/globals';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { newTest } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace, reloadConfiguration } from './../testUtils';
|
||||
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
suite('sneak plugin', () => {
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './../testUtils';
|
||||
import { Configuration } from '../testConfiguration';
|
||||
import { newTest } from '../testSimplifier';
|
||||
|
||||
suite('surround plugin', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
const configuration = new Configuration();
|
||||
configuration.surround = true;
|
||||
|
@ -3,18 +3,16 @@ import * as vscode from 'vscode';
|
||||
|
||||
import { getAndUpdateModeHandler } from '../../extension';
|
||||
import { ModeHandler } from '../../src/mode/modeHandler';
|
||||
import { IRegisterContent, Register } from '../../src/register/register';
|
||||
import { Register } from '../../src/register/register';
|
||||
import { VimState } from '../../src/state/vimState';
|
||||
import { Clipboard } from '../../src/util/clipboard';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { assertEqualLines, cleanUpWorkspace, setupWorkspace } from '../testUtils';
|
||||
import { RecordedState } from '../../src/state/recordedState';
|
||||
import { newTest } from '../testSimplifier';
|
||||
|
||||
suite('register', () => {
|
||||
let modeHandler: ModeHandler;
|
||||
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
modeHandler = await getAndUpdateModeHandler();
|
||||
|
@ -1,9 +1,7 @@
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { newTest } from '../testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from '../testUtils';
|
||||
|
||||
suite('Repeatable movements with f and t', () => {
|
||||
const { newTest, newTestOnly, newTestSkip } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
});
|
||||
|
@ -1,9 +1,7 @@
|
||||
import { getTestingFunctions } from './testSimplifier';
|
||||
import { newTest } from './testSimplifier';
|
||||
import { cleanUpWorkspace, setupWorkspace } from './testUtils';
|
||||
|
||||
suite('sentence motion', () => {
|
||||
const { newTest } = getTestingFunctions();
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace(undefined, '.js');
|
||||
});
|
||||
|
@ -15,73 +15,62 @@ import { vimrcKeyRemappingBuilder } from '../src/configuration/vimrcKeyRemapping
|
||||
import { IConfiguration } from '../src/configuration/iconfiguration';
|
||||
import { Position } from 'vscode';
|
||||
|
||||
export function getTestingFunctions() {
|
||||
function getNiceStack(stack: string | undefined): string {
|
||||
return stack ? stack.split('\n').splice(2, 1).join('\n') : 'no stack available :(';
|
||||
}
|
||||
|
||||
function newTestGeneric<T extends ITestObject | ITestWithRemapsObject>(
|
||||
testObj: T,
|
||||
testFunc: Mocha.TestFunction | Mocha.ExclusiveTestFunction | Mocha.PendingTestFunction,
|
||||
innerTest: (modeHandler: ModeHandler, testObj: T) => Promise<void>
|
||||
): void {
|
||||
const stack = new Error().stack;
|
||||
const niceStack = getNiceStack(stack);
|
||||
|
||||
testFunc(testObj.title, async () => {
|
||||
const prevConfig = { ...Globals.mockConfiguration };
|
||||
try {
|
||||
if (testObj.config) {
|
||||
for (const key in testObj.config) {
|
||||
if (testObj.config.hasOwnProperty(key)) {
|
||||
const value = testObj.config[key];
|
||||
Globals.mockConfiguration[key] = value;
|
||||
}
|
||||
}
|
||||
await reloadConfiguration();
|
||||
}
|
||||
const mh = await getAndUpdateModeHandler();
|
||||
await innerTest(mh, testObj);
|
||||
} catch (reason) {
|
||||
reason.stack = niceStack;
|
||||
throw reason;
|
||||
} finally {
|
||||
if (testObj.config) {
|
||||
Globals.mockConfiguration = prevConfig;
|
||||
await reloadConfiguration();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const newTest = (testObj: ITestObject) => newTestGeneric(testObj, test, testIt);
|
||||
|
||||
const newTestOnly = (testObj: ITestObject) => {
|
||||
console.warn('!!! Running single test !!!');
|
||||
return newTestGeneric(testObj, test.only, testIt);
|
||||
};
|
||||
|
||||
const newTestSkip = (testObj: ITestObject) => newTestGeneric(testObj, test.skip, testIt);
|
||||
|
||||
const newTestWithRemaps = (testObj: ITestWithRemapsObject) =>
|
||||
newTestGeneric(testObj, test, testItWithRemaps);
|
||||
const newTestWithRemapsOnly = (testObj: ITestWithRemapsObject) => {
|
||||
console.warn('!!! Running single test !!!');
|
||||
return newTestGeneric(testObj, test.only, testItWithRemaps);
|
||||
};
|
||||
const newTestWithRemapsSkip = (testObj: ITestWithRemapsObject) =>
|
||||
newTestGeneric(testObj, test.skip, testItWithRemaps);
|
||||
|
||||
return {
|
||||
newTest,
|
||||
newTestOnly,
|
||||
newTestSkip,
|
||||
newTestWithRemaps,
|
||||
newTestWithRemapsOnly,
|
||||
newTestWithRemapsSkip,
|
||||
};
|
||||
function getNiceStack(stack: string | undefined): string {
|
||||
return stack ? stack.split('\n').splice(2, 1).join('\n') : 'no stack available :(';
|
||||
}
|
||||
|
||||
function newTestGeneric<T extends ITestObject | ITestWithRemapsObject>(
|
||||
testObj: T,
|
||||
testFunc: Mocha.TestFunction | Mocha.ExclusiveTestFunction | Mocha.PendingTestFunction,
|
||||
innerTest: (modeHandler: ModeHandler, testObj: T) => Promise<void>
|
||||
): void {
|
||||
const stack = new Error().stack;
|
||||
const niceStack = getNiceStack(stack);
|
||||
|
||||
testFunc(testObj.title, async () => {
|
||||
const prevConfig = { ...Globals.mockConfiguration };
|
||||
try {
|
||||
if (testObj.config) {
|
||||
for (const key in testObj.config) {
|
||||
if (testObj.config.hasOwnProperty(key)) {
|
||||
const value = testObj.config[key];
|
||||
Globals.mockConfiguration[key] = value;
|
||||
}
|
||||
}
|
||||
await reloadConfiguration();
|
||||
}
|
||||
const mh = await getAndUpdateModeHandler();
|
||||
await innerTest(mh, testObj);
|
||||
} catch (reason) {
|
||||
reason.stack = niceStack;
|
||||
throw reason;
|
||||
} finally {
|
||||
if (testObj.config) {
|
||||
Globals.mockConfiguration = prevConfig;
|
||||
await reloadConfiguration();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const newTest = (testObj: ITestObject) => newTestGeneric(testObj, test, testIt);
|
||||
|
||||
export const newTestOnly = (testObj: ITestObject) => {
|
||||
console.warn('!!! Running single test !!!');
|
||||
return newTestGeneric(testObj, test.only, testIt);
|
||||
};
|
||||
|
||||
export const newTestSkip = (testObj: ITestObject) => newTestGeneric(testObj, test.skip, testIt);
|
||||
|
||||
export const newTestWithRemaps = (testObj: ITestWithRemapsObject) =>
|
||||
newTestGeneric(testObj, test, testItWithRemaps);
|
||||
export const newTestWithRemapsOnly = (testObj: ITestWithRemapsObject) => {
|
||||
console.warn('!!! Running single test !!!');
|
||||
return newTestGeneric(testObj, test.only, testItWithRemaps);
|
||||
};
|
||||
export const newTestWithRemapsSkip = (testObj: ITestWithRemapsObject) =>
|
||||
newTestGeneric(testObj, test.skip, testItWithRemaps);
|
||||
|
||||
interface ITestObject {
|
||||
title: string;
|
||||
config?: Partial<IConfiguration>;
|
||||
|
Loading…
Reference in New Issue
Block a user