Skip to content

Commit

Permalink
normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
athayes committed Jan 26, 2025
1 parent e3bf772 commit 3089c29
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/JestRunnerCodeLensProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { parse, ParsedNode } from './parser';
import { CodeLens, CodeLensProvider, Range, TextDocument, window, workspace } from 'vscode';
import { findFullTestName, escapeRegExp, CodeLensOption } from './util';
import * as fg from 'fast-glob';
import { normalize } from 'path';
import { sync } from 'fast-glob';

function getCodeLensForOption(range: Range, codeLensOption: CodeLensOption, fullTestName: string): CodeLens {
const titleMap: Record<CodeLensOption, string> = {
Expand Down Expand Up @@ -66,25 +67,20 @@ export class JestRunnerCodeLensProvider implements CodeLensProvider {

public async provideCodeLenses(document: TextDocument): Promise<CodeLens[]> {
try {
const filePath = document.fileName;
const config = workspace.getConfiguration('jestrunner');
const include = config.get<string[]>('include', []);
const exclude = config.get<string[]>('exclude', []);
const workspaceRoot = this.currentWorkspaceFolderPath;

// Check include and exclude patterns
if (include && include.length > 0) {
const isIncluded = fg.sync(include, { cwd: workspaceRoot, absolute: true }).includes(filePath);
if (!isIncluded) {
return []; // Exit early if file is not included
}
const exclude = config.get<string[]>('exclude', []);

const filePath = normalize(document.fileName);
const workspaceRoot = normalize(this.currentWorkspaceFolderPath);

const globOptions = { cwd: workspaceRoot, absolute: true };
if (include.length > 0 && !sync(include, globOptions).includes(filePath)) {
return [];
}

if (exclude && exclude.length > 0) {
const isExcluded = fg.sync(exclude, { cwd: '/', absolute: true }).includes(filePath);
if (isExcluded) {
return []; // Exit early if file is excluded
}
if (exclude.length > 0 && sync(exclude, globOptions).includes(filePath)) {
return [];
}

const parseResults = parse(document.fileName, document.getText(), { plugins: { decorators: 'legacy' } }).root
Expand Down

0 comments on commit 3089c29

Please sign in to comment.