Skip to content

Commit

Permalink
update generated tests, use / path sep instead of .
Browse files Browse the repository at this point in the history
  • Loading branch information
luttje committed Dec 1, 2024
1 parent 91acffc commit 02fe22f
Show file tree
Hide file tree
Showing 134 changed files with 2,982 additions and 2,768 deletions.
7 changes: 5 additions & 2 deletions scripts/extract-jest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,10 @@ function main(cacheDirectory) {
fs.mkdirSync(apiDirectory, { recursive: true });

api.methods.forEach(method => {
const { name } = method;
let { name } = method;

// Remove the . from the beginning of the name.
name = name.replace(/^\./, '');

// Not supported due to problems with C - Lua interop. For example 'require' cant be called in an async function.
if (name.endsWith('Async'))
Expand All @@ -370,7 +373,7 @@ function main(cacheDirectory) {
fs.mkdirSync(path.dirname(testsFile), { recursive: true });

fs.writeFileSync(testsFile, `-- ${name}\n\n${tests}`);
fs.appendFileSync(allTestsFilePath, `require "${apiDirectoryPath}.${name}"\n`);
fs.appendFileSync(allTestsFilePath, `require "${apiDirectoryPath}/${name}"\n`);
});
});

Expand Down
26 changes: 14 additions & 12 deletions tests/generated/ExpectAPI/expect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@

local tests = {

(function()
-- It's easier to understand this with an example. Let's say you have a method `bestLaCroixFlavor()` which is supposed to return the string `'grapefruit'`. Here's how you would test that:
-- -- In this case, `toBe` is the matcher function. There are a lot of different matcher functions, documented below, to help you test different things.
test(
"the best flavor is grapefruit",
function()
expect(bestLaCroixFlavor()):toBe("grapefruit")
end
)
end)(),

(function()
-- It's easier to understand this with an example. Let's say you have a method `bestLaCroixFlavor()` which is supposed to return the string `'grapefruit'`. Here's how you would test that:
-- -- In this case, `toBe` is the matcher function. There are a lot of different matcher functions, documented below, to help you test different things.
test(
"the best flavor is grapefruit",
function()
expect(bestLaCroixFlavor()):toBe("grapefruit")
end
)


end)(),


}

return tests
return tests
142 changes: 72 additions & 70 deletions tests/generated/ExpectAPI/expect/addEqualityTesters.lua
Original file line number Diff line number Diff line change
@@ -1,88 +1,90 @@
-- expect.addEqualityTesters

generatedTestPreLoad('Volume_js', function()
-- You can use `expect.addEqualityTesters` to add your own methods to test if two objects are equal. For example, let's say you have a class in your code that represents volume and can determine if two volumes using different units are equal. You may want `toEqual` (and other equality matchers) to use this custom equality method when comparing to Volume classes. You can add a custom equality tester to have `toEqual` detect and apply custom logic when comparing Volume classes:
--
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local ____exports = {}
____exports.Volume = __TS__Class()
local Volume = ____exports.Volume
Volume.name = "Volume"
function Volume.prototype.____constructor(self, amount, unit)
self.amount = amount
self.unit = unit
end

function Volume.prototype.__tostring(self)
return (("[Volume " .. tostring(self.amount)) .. tostring(self.unit)) .. "]"
end

function Volume.prototype.equals(self, other)
if self.unit == other.unit then
return self.amount == other.amount
elseif self.unit == "L" and other.unit == "mL" then
return self.amount * 1000 == other.unit
else
return self.amount == other.unit * 1000
end
end

return ____exports
-- You can use `expect.addEqualityTesters` to add your own methods to test if two objects are equal. For example, let's say you have a class in your code that represents volume and can determine if two volumes using different units are equal. You may want `toEqual` (and other equality matchers) to use this custom equality method when comparing to Volume classes. You can add a custom equality tester to have `toEqual` detect and apply custom logic when comparing Volume classes:
--
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local ____exports = {}
____exports.Volume = __TS__Class()
local Volume = ____exports.Volume
Volume.name = "Volume"
function Volume.prototype.____constructor(self, amount, unit)
self.amount = amount
self.unit = unit
end
function Volume.prototype.__tostring(self)
return (("[Volume " .. tostring(self.amount)) .. tostring(self.unit)) .. "]"
end
function Volume.prototype.equals(self, other)
if self.unit == other.unit then
return self.amount == other.amount
elseif self.unit == "L" and other.unit == "mL" then
return self.amount * 1000 == other.unit
else
return self.amount == other.unit * 1000
end
end
return ____exports

end)

generatedTestPreLoad('areVolumesEqual_js', function()
local ____lualib = require("lualib_bundle")
local __TS__InstanceOf = ____lualib.__TS__InstanceOf
local ____exports = {}
local ____globals = require("@jestronaut_globals")
local expect = ____globals.expect
local ____Volume_2Ejs = require("Volume_js")
local Volume = ____Volume_2Ejs.Volume
local function areVolumesEqual(a, b)
local isAVolume = __TS__InstanceOf(a, Volume)
local isBVolume = __TS__InstanceOf(b, Volume)
if isAVolume and isBVolume then
return a:equals(b)
elseif isAVolume ~= isBVolume then
return false
else
return nil
end
end
expect:addEqualityTesters({ areVolumesEqual })
return ____exports

local ____lualib = require("lualib_bundle")
local __TS__InstanceOf = ____lualib.__TS__InstanceOf
local ____exports = {}
local ____globals = require("@jestronaut_globals")
local expect = ____globals.expect
local ____Volume_2Ejs = require("Volume_js")
local Volume = ____Volume_2Ejs.Volume
local function areVolumesEqual(a, b)
local isAVolume = __TS__InstanceOf(a, Volume)
local isBVolume = __TS__InstanceOf(b, Volume)
if isAVolume and isBVolume then
return a:equals(b)
elseif isAVolume ~= isBVolume then
return false
else
return nil
end
end
expect:addEqualityTesters({areVolumesEqual})
return ____exports

end)

generatedTestPreLoad('__tests__/Volume_test_js', function()
local ____lualib = require("lualib_bundle")
local __TS__New = ____lualib.__TS__New
local ____exports = {}
local ____globals = require("@jestronaut_globals")
local expect = ____globals.expect
local test = ____globals.test
local ____Volume_2Ejs = require("Volume_js")
local Volume = ____Volume_2Ejs.Volume
require("areVolumesEqual_js")
test(
"are equal with different units",
function()
expect(__TS__New(Volume, 1, "L")):toEqual(__TS__New(Volume, 1000, "mL"))
end
)
return ____exports

local ____lualib = require("lualib_bundle")
local __TS__New = ____lualib.__TS__New
local ____exports = {}
local ____globals = require("@jestronaut_globals")
local expect = ____globals.expect
local test = ____globals.test
local ____Volume_2Ejs = require("Volume_js")
local Volume = ____Volume_2Ejs.Volume
require("areVolumesEqual_js")
test(
"are equal with different units",
function()
expect(__TS__New(Volume, 1, "L")):toEqual(__TS__New(Volume, 1000, "mL"))
end
)
return ____exports

end)



local tests = {







}

return tests
return tests
29 changes: 15 additions & 14 deletions tests/generated/ExpectAPI/expect/addSnapshotSerializer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@

local tests = {

(function()
-- If you add a snapshot serializer in individual test files instead of adding it to `snapshotSerializers` configuration:
--
-- - You make the dependency explicit instead of implicit.
-- - You avoid limits to configuration that might cause you to eject from [create-react-app](https://github.com/facebookincubator/create-react-app).
local ____exports = {}
local ____my_2Dserializer_2Dmodule = require("my-serializer-module")
local serializer = ____my_2Dserializer_2Dmodule.default
expect:addSnapshotSerializer(serializer)
return ____exports
end)(),


(function()
-- If you add a snapshot serializer in individual test files instead of adding it to `snapshotSerializers` configuration:
--
-- - You make the dependency explicit instead of implicit.
-- - You avoid limits to configuration that might cause you to eject from [create-react-app](https://github.com/facebookincubator/create-react-app).
local ____exports = {}
local ____my_2Dserializer_2Dmodule = require("my-serializer-module")
local serializer = ____my_2Dserializer_2Dmodule.default
expect:addSnapshotSerializer(serializer)
return ____exports

end)(),



}

return tests
return tests
73 changes: 37 additions & 36 deletions tests/generated/ExpectAPI/expect/any.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,43 @@

local tests = {

(function()
-- `expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number:
--
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__New = ____lualib.__TS__New
local Cat = __TS__Class()
Cat.name = "Cat"
function Cat.prototype.____constructor(self)
end

local function getCat(fn)
return fn(__TS__New(Cat))
end
test(
"randocall calls its callback with a class instance",
function()
local mock = jestronaut:fn()
getCat(mock)
expect(mock):toHaveBeenCalledWith(expect:any(Cat))
end
)
local function randocall(fn)
return fn(math.floor(math.random() * 6 + 1))
end
test(
"randocall calls its callback with a number",
function()
local mock = jestronaut:fn()
randocall(mock)
expect(mock):toHaveBeenCalledWith(expect:any(Number))
end
)
end)(),

(function()
-- `expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number:
--
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__New = ____lualib.__TS__New
local Cat = __TS__Class()
Cat.name = "Cat"
function Cat.prototype.____constructor(self)
end
local function getCat(fn)
return fn(__TS__New(Cat))
end
test(
"randocall calls its callback with a class instance",
function()
local mock = jestronaut:fn()
getCat(mock)
expect(mock):toHaveBeenCalledWith(expect:any(Cat))
end
)
local function randocall(fn)
return fn(math.floor(math.random() * 6 + 1))
end
test(
"randocall calls its callback with a number",
function()
local mock = jestronaut:fn()
randocall(mock)
expect(mock):toHaveBeenCalledWith(expect:any(Number))
end
)


end)(),


}

return tests
return tests
40 changes: 21 additions & 19 deletions tests/generated/ExpectAPI/expect/anything.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@

local tests = {

(function()
-- `expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument:
--
local ____lualib = require("lualib_bundle")
local __TS__ArrayMap = ____lualib.__TS__ArrayMap
test(
"map calls its argument with a non-null argument",
function()
local mock = jestronaut:fn()
__TS__ArrayMap(
{ 1 },
function(____, x) return mock(x) end
)
expect(mock):toHaveBeenCalledWith(expect:anything())
end
)
end)(),

(function()
-- `expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument:
--
local ____lualib = require("lualib_bundle")
local __TS__ArrayMap = ____lualib.__TS__ArrayMap
test(
"map calls its argument with a non-null argument",
function()
local mock = jestronaut:fn()
__TS__ArrayMap(
{1},
function(____, x) return mock(x) end
)
expect(mock):toHaveBeenCalledWith(expect:anything())
end
)


end)(),


}

return tests
return tests
Loading

0 comments on commit 02fe22f

Please sign in to comment.