Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function provideLwcTestCodeLens(
document: TextDocument,
token: CancellationToken
): Promise {
const fsPath = document.uri.fsPath;
const parseResults = parse(fsPath, document.getText());
const { itBlocks } = parseResults;
return itBlocks
.map(itBlock => {
const { name, nameRange, start, end } = itBlock;
// VS Code position is zero-based
const range = new Range(
new Position(nameRange.start.line - 1, nameRange.start.column - 1),
new Position(nameRange.end.line - 1, nameRange.end.column - 1)
);
const testExecutionInfo: TestExecutionInfo = {
kind: TestInfoKind.TEST_CASE,
testType: TestType.LWC,
testUri: document.uri,
testName: name
};
export async function findTestInfoFromLwcJestTestFile(testUri: vscode.Uri) {
if (testInfoMap.has(testUri)) {
return testInfoMap.get(testUri);
}
// parse
const { fsPath } = testUri;
const { itBlocks } = parse(fsPath);
const testInfo = itBlocks.map(itBlock => {
const { name, nameRange, start, end } = itBlock;
const testName = name;
const testRange = new vscode.Range(
new vscode.Position(nameRange.start.line - 1, nameRange.start.column - 1),
new vscode.Position(nameRange.end.line - 1, nameRange.end.column)
);
const testLocation = new vscode.Location(testUri, testRange);
return {
testType: TestType.LWC,
testName,
testUri,
testLocation
};
});
testInfoMap.set(testUri, testInfo);
private findCurrentTestName(editor: vscode.TextEditor): string {
// from selection
const { selection, document } = editor;
if (!selection.isEmpty) {
return unquote(document.getText(selection));
}
const selectedLine = selection.active.line + 1;
const filePath = editor.document.fileName;
const testFile = parse(filePath);
return exactRegexMatch(escapeRegExp(findFullTestName(selectedLine, testFile.root.children)));
}
private parseTestFileAndMergeTestResults(
testFileInfo: TestFileInfo
): TestCaseInfo[] {
try {
const { testUri } = testFileInfo;
const { fsPath: testFsPath } = testUri;
const parseResults = parse(testFsPath) as IExtendedParseResults;
populateAncestorTitles(parseResults);
const itBlocks = (parseResults.itBlocksWithAncestorTitles ||
parseResults.itBlocks) as ItBlockWithAncestorTitles[];
const testCasesInfo: TestCaseInfo[] = itBlocks.map(itBlock => {
const { name, nameRange, ancestorTitles } = itBlock;
const testName = name;
const testRange = new vscode.Range(
new vscode.Position(
nameRange.start.line - 1,
nameRange.start.column - 1
),
new vscode.Position(nameRange.end.line - 1, nameRange.end.column)
);
const testLocation = new vscode.Location(testUri, testRange);
const testCaseInfo: TestCaseInfo = {
kind: TestInfoKind.TEST_CASE,
export function parseTest(filePath: string): IParseResults {
return parse(filePath)
}