78 Replies
cc @PepeElToro41
this is my setup
still the same problem?
can you check if your custom loadstring does print
to see if it's actually using it
printn what?
here
the fixLoadModule
also,
loadmodule
asked for a script, but in loadstring it just asks for a string, so, you can remove the script
part, I'd imagine jest would replace it anyway

fenv.require?
that is fine, jest would probably replace that one too
the problem is just the _G table
let me see how jest loads it

OH
why does this happen though?
loadstring resets the current environment
GitHub
jest-lua/src/jest-runtime/src/init.lua at a5d089ab06021a931f9bb3df9...
Delightful testing for Lua. Contribute to jsdotlua/jest-lua development by creating an account on GitHub.
here is the part that loads it
I did this instead?
_G = { NOCOLOR = true },
don't really understannd
so I would need to clear it?
can you print(_G) before the
fixLoadModule
and inside your tests
and check if it's the same _G
use this to check that it is the same address


no address in the first one
same thing
the first one I forgot to turn on
so this is in the story, and inside the test, it prints the same table?
if it does, they you should be fine now
import fixLoadModule from "common/shared/utils/fix-load-module";
import { runTests } from "common/shared/utils/run-tests";
import { FunctionStory } from "@rbxts/ui-labs";
print(_G);
fixLoadModule();
export = (() => {
runTests();
return () => {};
}) satisfies FunctionStory;
no, this is the start
yeah, now in your
.spec
files, print _G toopirror to fix
it doesn't print??

_G doesnt exist?

oh yeah I mean it makes sense, try to print it outside of the test
in fact, you probably want to print it before the roblox-ts imports
so maybe modify the luau files directly
because that's where the error happens
nah
it don't work

try modifying the luau transpiled files
I think roblox-ts will always put the imports on top

true
but only for TS


do not know why it leads to here
do you import
use-hook-state
somewhere in your code by any chance?
like outside of the .spec
testsno

its my custom useHookState
and I only resetHookStorage
remove the
services
import
try doing GetService
manuallyreplace it with game:GetService?
yes

nah
lets see if the transformer is doing its job..
yeah

it is
Im running out of ideas, try just printing
_G
right before doing runCLI
to see what has been imported by roblox-ts before thatsame memory address
but what entries does it have
so the idea is to make different memory addresses?
no, the idea is to have the same address
try commenting the fixLoadModule, the _G table should be different


actually
the addresses are differennt
ya
I think I see what could be happening
_G for use-change.spec.ts
because the first one always passes right?
no tests pass
here
ya
you gotta call it every time??
yeah, so, seems like jest might call
loadstring
everytime or something
try printing the _G table in every test file
and probably do it by editing the luau files
at least the first two that run
dupes
dupes of src.
which is jest?
yeah so I think jest is trying to hot-reload the script everytime
I have an idea, instead of doing fenv._G, do just a new table
{}
hereall tests fail
what is the error?
the same thing
none passes
and how the _G tables are looking?
nvalid module access! Do you have multiple TS runtimes trying to import this? ReplicatedStorage.common.ecs.hooks.use-hook-state
I will go to sleep
gn
I think its probably a duplicate reference
of jest src
so a script that deletes the same instance referennce perchance
but at the same time its not the same reference
(different addresses for the instances)
so the src got duped?
do you only have one src?
that's weird yeah
I'll try to check it later myself, jest is doing some weird stuff with the globals and require
it seems like src is duped right before tests pass

maybe I should make a custom plugin that runs unit tests since loadstring needs plugin security?
yeah thats weird, I dont see how this would work, because, you need plugin security to use loadstring
but it also doesnt work with plugins
duplicate version of src?
but why though?
no like, jest in general
only with run-in-roblox
it might be different packages src's honestly,
I need to check this myself to find a fix
lmk when you fix it and ping me