I’ve created a reusable Nodejs package `aws-resour...
# typescript
m
I’ve created a reusable Nodejs package
aws-resource
for creating AWS resources. The package
aws-resource
is used inside a Pulumi stack. When I execute the unit tests of the Pulumi stack, it complains with ‘_Error: Program run without the Pulumi engine available; re-run using the
pulumi
CLI_’. Although the unit tests of the stack contain the mocking code for Pulumi resources.
Copy code
pulumi.runtime.setMocks({
  newResource: function(...) { ... }
});
I guess the pulumi API calls inside the Nodejs package
aws-resource
don’t get mocked. What should I do to also have the resources created by the package
aws-resource
mocked?
Alright, I’ve found it. Digging into the source code and some of the issues on github learned me I have to set the environment variable
PULUMI_TEST_MODE=true
.
l
Yes, or you can run your test code inside
pulumi.runtime.runInPulumiStack()
.
Often it is possible to avoid doing either, if you limit your testing to your ComponentResources and avoid testing your index.ts or similar.
So far, the only time I have had to use
runInPulumiStack
in a test was to test
registerStackTransformation
.
m
I wasn’t aware of
pulumi.runtime.runInPulumiStack()
I’ll take a look at that.
Up until now I never tested index.ts. index.ts only does the wiring. I only test the resources created by my classes or functions that kind of do what
ComponentResources
does. I also wasn’t aware of that one 🙄 😄
And it is exactly while testing these functions and classes (that rely on a Node.js package that uses Pulumi) that I got that error message
l
Ok. I use a mono-repo so not quite the same case. I haven't been dependent on that env var. But it looks like it's intended for exactly this purpose 👍
m
Well, at least it solved my problem. But for some reason, nodejs memory usage exploded. I had to increase
--max-old-space-size