-
Notifications
You must be signed in to change notification settings - Fork 211
Closed
Labels
Description
Wanted to start a discussion about the option to test the compiler using the sim api.
Here is a small example of how one test can look like (using jest)
code.w
bring cloud;
let bucket = new cloud.Bucket();
inflight my_inflight(a:str): str{
bucket.put("file.txt", a);
};
new cloud.Function(my_inflight);basic.test.ts
import * as sdk from '@winglang/wingsdk';
import * as child from 'child_process';
//TOOD replace this with something that is not quick and dirty
const SIM_FILE = __dirname + "/../app.wx";
const WING_COMMAND = "/Users/eyalkeren/monada-workspace/wing-test-propsal/node_modules/.bin/wing";
const WING_CODE = __dirname + "/code.w"
let simulator : sdk.testing.Simulator
describe('basic compiler tests', () => {
beforeAll(async () => {
child.execSync(WING_COMMAND + " compile --target sim " + WING_CODE )
});
beforeEach(async ()=> {
simulator = new sdk.testing.Simulator({simfile : SIM_FILE}) //TOOD
await simulator.start()
});
afterEach(async () => {
await simulator.stop()
})
test('test function writes to bucket', async () => {
let bucket = simulator.getResourceByPath("root/cloud.Bucket") as sdk.sim.IBucketClient
let fn = simulator.getResourceByPath("root/cloud.Function") as sdk.sim.IFunctionClient
await fn.invoke("somevalue")
let output = await bucket.get('file.txt')
expect(output).toBe('somevalue')
});
});Reactions are currently unavailable