wing
wing copied to clipboard
creating an rfc for testing
Use Case
following 25/01/24 team time - we can only make wing's testing framework great if someone owns it, I'll collect the relevant issues and try my best to create a solid rfc out of them 💪
Proposed Solution
No response
Implementation Notes
No response
Component
No response
Community Notes
- Please vote by adding a 👍 reaction to the issue to help us prioritize.
- If you are interested to work on this issue, please leave a comment.
- If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Slack.
Here are my two cents:
-
testis for preflight code blocks, this keyword is only available in*.test.wfiles and it creates an isolated environment that can run checks -
check(or maybemonitor) is for inflight code, nested inside atestblock or inside any*.main.wfile
test runs in isolation (a test doesn't interfere another test) while check run on the same INFA, and there is no guarantee on order and parallelism .
// *.main.w
bring cloud;
bring util;
bring expect;
let b = new cloud.Bucket();
check "bucket put and get" {
// check doesn't run in isolation, so a unique file is required
let file = util.uuidv4();
b.put(file, "1234");
expect.equal(b.get(file), "1234");
}
check "list bucket" {
let file = util.uuidv4();
b.put(file, "1234");
let files = b.list(); // will return a list of more then this file
assert(files.contains(file));
}
check "this is a bad test" {
// this check will fail in some cases, depending which check will run first
expect.equal(b.list().length, 0);
}
// *.test.w
bring cloud;
bring util;
bring expect;
test "empty bucket" {
let b = new cloud.Bucket();
check "list is empty" {
expect.equal(b.list().length, 0);
}
}
test "bucket addObject" {
let b = new cloud.Bucket();
let file = "file";
b.addObject(file ,"xyz");
check "list return 1" {
expect.equal(b.list().length, 1);
expect.equal(b.list().at(0), file);
}
check "add object returns right content" {
expect.equal(b.get(file), "xyz");
}
}