how do I do these kinds of tests with functional s...
# help
j
how do I do these kinds of tests with functional stacks? https://github.com/serverless-stack/serverless-stack/blob/e46c10609349fe3ab916db11[…]b9f4e20daf8/packages/cli/test/template-app/test/MyStack.test.js e.g.
Copy code
import { Template } from "aws-cdk-lib/assertions";
import * as sst from "@serverless-stack/resources";
import MyStack from "../lib/MyStack";

test("Test Stack", () => {
  const app = new <http://sst.App|sst.App>();
  // WHEN
  const app = app.stack(MyStack)
  // THEN
  try {
    const template = Template.fromStack(stackIsMissingHere);
    template.resourceCountIs("AWS::Lambda::Function", 1);
    // Print out a test string that parent .test.js can catch
    console.log("JESTTESTSUCCESS-----");
  } catch (e) {
    // Ignore any errors
  }
});
t
we do have an app.getStack(MyFunc) now that you can pass into the fromStack func
ultimately though we haven't fully formed our opinions on stack testing, because the main file can set defaults and other things these tests aren't exactly accurate
and also I do wonder what the value of stack tests are if you have a good set of integration tests
j
Mm. I guess there could still be a sense to validating that some properties are set on resources etc, but good integration test should cover most needs
speaking of, do we have any good examples of something like creating a fresh stack for integration testing, performing tests, then tearing it down?
t
we're coming out with some stuff around this next month. I have a pretty good setup but it requires some stuff we need to move into core
my talk on Tuesday will demonstrate some of it
j
sounds good, looking forward to it
a
How are ya'll approaching integration testing with SST? Is there an example repo maybe? (Sorry to hijack your thread, Jimmy.)
f
@Alex Rayo we don’t have an example yet. It’s something we are thinking about, and we will put something out in the coming weeks.
a
Thank you!