Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions lua/neotest-playwright/build-spec.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand Down
89 changes: 87 additions & 2 deletions lua/neotest-playwright/discover.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
88 changes: 87 additions & 1 deletion lua/neotest-playwright/position.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/build-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 14 additions & 5 deletions src/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
: {}),
});
};
Expand Down Expand Up @@ -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 = () => {
Expand Down
11 changes: 10 additions & 1 deletion src/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down