From ca1a25362dbd7ae52f90303960e6b541510ee023 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Tue, 4 Feb 2025 00:36:12 -0600 Subject: [PATCH 1/2] fix: address windows path separator issues --- src/build-spec.ts | 5 +++++ src/discover.ts | 19 ++++++++++++++----- src/position.ts | 11 ++++++++++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/build-spec.ts b/src/build-spec.ts index 47348bb..1ff70a8 100644 --- a/src/build-spec.ts +++ b/src/build-spec.ts @@ -28,6 +28,11 @@ export const buildSpec: Adapter['build_spec'] = (args) => { } testFilter = `${pos.path}:${line}`; + + // Windows compatibility + if (vim.fn.has('win32') === 1) { + testFilter = testFilter.replaceAll('\\', '/'); + } } const projects = pos.project_id ? [pos.project_id] : options.projects; diff --git a/src/discover.ts b/src/discover.ts index b7fb2df..44abfac 100644 --- a/src/discover.ts +++ b/src/discover.ts @@ -100,9 +100,9 @@ export const discoverPositions: Adapter['discover_positions'] = ( position_id: 'require("neotest-playwright.discover")._position_id', ...(options.enable_dynamic_test_discovery ? { - build_position: - 'require("neotest-playwright.discover")._build_position', - } + build_position: + 'require("neotest-playwright.discover")._build_position', + } : {}), }); }; @@ -158,11 +158,20 @@ export const _build_position: BuildPosition = ( }; export const _position_id: PositionId = (position, _parent) => { + let positionId = ''; + if (position.id) { - return position.id; + positionId = position.id; } else { - return position.path + '::' + position.name; + positionId = position.path + '::' + position.name; + } + + // Windows compatibility + if (vim.fn.has('win32') === 1) { + positionId = positionId.replaceAll('\\', '/'); } + + return positionId; }; export const populate_data = () => { diff --git a/src/position.ts b/src/position.ts index 3c7b153..0010fe1 100644 --- a/src/position.ts +++ b/src/position.ts @@ -20,7 +20,16 @@ export const buildTestPosition = (basePosition: BasePosition): Position[] => { const specs = data.specs.filter((spec) => { const specAbsolutePath = data.rootDir + '/' + spec.file; - const fileMatch = specAbsolutePath === basePosition.path; + let specPath = specAbsolutePath; + let basePath = basePosition.path; + + // Windows compatibility + if (vim.fn.has('win32') === 1) { + specPath = specPath.replaceAll('\\', '/'); + basePath = basePath.replaceAll('\\', '/'); + } + + const fileMatch = specPath === basePath; if (!fileMatch) { return false; From 801c24f23ee68616bb947357a58a0c2e64aacb55 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Tue, 4 Feb 2025 00:37:20 -0600 Subject: [PATCH 2/2] chore: run build --- lua/neotest-playwright/build-spec.lua | 83 +++++++++++++++++++++++++ lua/neotest-playwright/discover.lua | 89 ++++++++++++++++++++++++++- lua/neotest-playwright/position.lua | 88 +++++++++++++++++++++++++- 3 files changed, 257 insertions(+), 3 deletions(-) diff --git a/lua/neotest-playwright/build-spec.lua b/lua/neotest-playwright/build-spec.lua index 3fbfd22..5feb3c0 100644 --- a/lua/neotest-playwright/build-spec.lua +++ b/lua/neotest-playwright/build-spec.lua @@ -1,5 +1,85 @@ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]] -- Lua Library inline imports +local __TS__StringSplit +do + local sub = string.sub + local find = string.find + function __TS__StringSplit(source, separator, limit) + if limit == nil then + limit = 4294967295 + end + if limit == 0 then + return {} + end + local result = {} + local resultIndex = 1 + if separator == nil or separator == "" then + for i = 1, #source do + result[resultIndex] = sub(source, i, i) + resultIndex = resultIndex + 1 + end + else + local currentPos = 1 + while resultIndex <= limit do + local startPos, endPos = find(source, separator, currentPos, true) + if not startPos then + break + end + result[resultIndex] = sub(source, currentPos, startPos - 1) + resultIndex = resultIndex + 1 + currentPos = endPos + 1 + end + if resultIndex <= limit then + result[resultIndex] = sub(source, currentPos) + end + end + return result + end +end + +local __TS__StringReplaceAll +do + local sub = string.sub + local find = string.find + function __TS__StringReplaceAll(source, searchValue, replaceValue) + if type(replaceValue) == "string" then + local concat = table.concat( + __TS__StringSplit(source, searchValue), + replaceValue + ) + if #searchValue == 0 then + return (replaceValue .. concat) .. replaceValue + end + return concat + end + local parts = {} + local partsIndex = 1 + if #searchValue == 0 then + parts[1] = replaceValue(nil, "", 0, source) + partsIndex = 2 + for i = 1, #source do + parts[partsIndex] = sub(source, i, i) + parts[partsIndex + 1] = replaceValue(nil, "", i, source) + partsIndex = partsIndex + 2 + end + else + local currentPos = 1 + while true do + local startPos, endPos = find(source, searchValue, currentPos, true) + if not startPos then + break + end + parts[partsIndex] = sub(source, currentPos, startPos - 1) + parts[partsIndex + 1] = replaceValue(nil, searchValue, startPos - 1, source) + partsIndex = partsIndex + 2 + currentPos = endPos + 1 + end + parts[partsIndex] = sub(source, currentPos) + end + return table.concat(parts) + end +end + local function __TS__ObjectAssign(target, ...) local sources = {...} for i = 1, #sources do @@ -73,6 +153,9 @@ ____exports.buildSpec = function(args) line = range[1] + 1 end testFilter = (pos.path .. ":") .. tostring(line) + if vim.fn.has("win32") == 1 then + testFilter = __TS__StringReplaceAll(testFilter, "\\", "/") + end end local projects = pos.project_id and ({pos.project_id}) or options.projects local commandOptions = __TS__ObjectAssign( diff --git a/lua/neotest-playwright/discover.lua b/lua/neotest-playwright/discover.lua index afddbf4..b28fc0e 100644 --- a/lua/neotest-playwright/discover.lua +++ b/lua/neotest-playwright/discover.lua @@ -151,6 +151,86 @@ do TypeError = createErrorClass(nil, "TypeError") URIError = createErrorClass(nil, "URIError") end + +local __TS__StringSplit +do + local sub = string.sub + local find = string.find + function __TS__StringSplit(source, separator, limit) + if limit == nil then + limit = 4294967295 + end + if limit == 0 then + return {} + end + local result = {} + local resultIndex = 1 + if separator == nil or separator == "" then + for i = 1, #source do + result[resultIndex] = sub(source, i, i) + resultIndex = resultIndex + 1 + end + else + local currentPos = 1 + while resultIndex <= limit do + local startPos, endPos = find(source, separator, currentPos, true) + if not startPos then + break + end + result[resultIndex] = sub(source, currentPos, startPos - 1) + resultIndex = resultIndex + 1 + currentPos = endPos + 1 + end + if resultIndex <= limit then + result[resultIndex] = sub(source, currentPos) + end + end + return result + end +end + +local __TS__StringReplaceAll +do + local sub = string.sub + local find = string.find + function __TS__StringReplaceAll(source, searchValue, replaceValue) + if type(replaceValue) == "string" then + local concat = table.concat( + __TS__StringSplit(source, searchValue), + replaceValue + ) + if #searchValue == 0 then + return (replaceValue .. concat) .. replaceValue + end + return concat + end + local parts = {} + local partsIndex = 1 + if #searchValue == 0 then + parts[1] = replaceValue(nil, "", 0, source) + partsIndex = 2 + for i = 1, #source do + parts[partsIndex] = sub(source, i, i) + parts[partsIndex + 1] = replaceValue(nil, "", i, source) + partsIndex = partsIndex + 2 + end + else + local currentPos = 1 + while true do + local startPos, endPos = find(source, searchValue, currentPos, true) + if not startPos then + break + end + parts[partsIndex] = sub(source, currentPos, startPos - 1) + parts[partsIndex + 1] = replaceValue(nil, searchValue, startPos - 1, source) + partsIndex = partsIndex + 2 + currentPos = endPos + 1 + end + parts[partsIndex] = sub(source, currentPos) + end + return table.concat(parts) + end +end -- End of Lua Library inline imports local ____exports = {} local shouldRefreshData @@ -237,11 +317,16 @@ ____exports._build_position = function(filePath, source, capturedNodes) end end ____exports._position_id = function(position, _parent) + local positionId = "" if position.id then - return position.id + positionId = position.id else - return (position.path .. "::") .. position.name + positionId = (position.path .. "::") .. position.name + end + if vim.fn.has("win32") == 1 then + positionId = __TS__StringReplaceAll(positionId, "\\", "/") end + return positionId end ____exports.populate_data = function() if shouldRefreshData() then diff --git a/lua/neotest-playwright/position.lua b/lua/neotest-playwright/position.lua index 0817489..3f1b640 100644 --- a/lua/neotest-playwright/position.lua +++ b/lua/neotest-playwright/position.lua @@ -125,6 +125,86 @@ do URIError = createErrorClass(nil, "URIError") end +local __TS__StringSplit +do + local sub = string.sub + local find = string.find + function __TS__StringSplit(source, separator, limit) + if limit == nil then + limit = 4294967295 + end + if limit == 0 then + return {} + end + local result = {} + local resultIndex = 1 + if separator == nil or separator == "" then + for i = 1, #source do + result[resultIndex] = sub(source, i, i) + resultIndex = resultIndex + 1 + end + else + local currentPos = 1 + while resultIndex <= limit do + local startPos, endPos = find(source, separator, currentPos, true) + if not startPos then + break + end + result[resultIndex] = sub(source, currentPos, startPos - 1) + resultIndex = resultIndex + 1 + currentPos = endPos + 1 + end + if resultIndex <= limit then + result[resultIndex] = sub(source, currentPos) + end + end + return result + end +end + +local __TS__StringReplaceAll +do + local sub = string.sub + local find = string.find + function __TS__StringReplaceAll(source, searchValue, replaceValue) + if type(replaceValue) == "string" then + local concat = table.concat( + __TS__StringSplit(source, searchValue), + replaceValue + ) + if #searchValue == 0 then + return (replaceValue .. concat) .. replaceValue + end + return concat + end + local parts = {} + local partsIndex = 1 + if #searchValue == 0 then + parts[1] = replaceValue(nil, "", 0, source) + partsIndex = 2 + for i = 1, #source do + parts[partsIndex] = sub(source, i, i) + parts[partsIndex + 1] = replaceValue(nil, "", i, source) + partsIndex = partsIndex + 2 + end + else + local currentPos = 1 + while true do + local startPos, endPos = find(source, searchValue, currentPos, true) + if not startPos then + break + end + parts[partsIndex] = sub(source, currentPos, startPos - 1) + parts[partsIndex + 1] = replaceValue(nil, searchValue, startPos - 1, source) + partsIndex = partsIndex + 2 + currentPos = endPos + 1 + end + parts[partsIndex] = sub(source, currentPos) + end + return table.concat(parts) + end +end + local function __TS__ArrayFilter(self, callbackfn, thisArg) local result = {} local len = 0 @@ -210,7 +290,13 @@ ____exports.buildTestPosition = function(basePosition) data.specs, function(____, spec) local specAbsolutePath = (tostring(data.rootDir) .. "/") .. spec.file - local fileMatch = specAbsolutePath == basePosition.path + local specPath = specAbsolutePath + local basePath = basePosition.path + if vim.fn.has("win32") == 1 then + specPath = __TS__StringReplaceAll(specPath, "\\", "/") + basePath = __TS__StringReplaceAll(basePath, "\\", "/") + end + local fileMatch = specPath == basePath if not fileMatch then return false end