New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to use stack transformation from unit test #4669
Comments
This happens because we do not currently create a root In the meantime, a workaround is to use pulumi.runtime.setMocks({
call: x => {
return {};
},
newResource: x => {
return {id: "", state: {}};
}
})
pulumi.runtime.runInPulumiStack(async () => {
pulumi.runtime.registerStackTransformation(args => {
console.log(`transofming: ${args.name}`)
return {
opts: args.opts,
props: args.props,
}
})
// Create an AWS resource (S3 Bucket)
const bucket = new aws.s3.Bucket("my-bucket");
// Export the name of the bucket
return {
bucketName: bucket.id
};
}) |
This problem scope is bigger than just unit tests. I have common transformations that I want to be able to reuse in all projects as npm package. It also causes problem the other way around, when I register stack transformation, it doesn't apply on resources created by modules from shared npm packages. |
Related - #6214 |
This change initializes a root stack resource when run in mocks mode, fixing #4669. This lets you use, for instance, stack transformations during unit testing. This is effectively the equivalent to what we did for Python in https://github.com/pulumi/pulumi/pull/4670/files, just for Node.js.
I agree with @amichel I get the same traceback when running pulumi up on a project with a stack transformation. |
If I call
pulumi.runtime.registerStackTransformation
from my Pulumi application and run a unit test against my application, the tests fail to run with the errorThe root stack resource was referenced before it was initialized.
The same Pulumi application runs successfully without error withpulumi preview
.Steps to reproduce
git clone https://gist.github.com/20db9640bc9f3c8607f6d67d8390fb45 gh-test && cd gh-test
npm i
pulumi stack init gh-test
npm test
pulumi preview
The text was updated successfully, but these errors were encountered: