feat: export e2e tests for a chosen scenario version
- GET /scenarios/:id/export-e2e and the export_e2e_test MCP tool take an optional version, defaulting to the latest - build the test project from that version's steps, name and timeout - put the version in the zip name (<scenario>-vN-e2e-test.zip), the generated package name and the README heading - the Export e2e test button exports the version being viewed - document the e2e export in scenario.md and mcp.md
This commit is contained in:
8 files changed
+102
-17
No files matched your search
@@ -4,6 +4,7 @@
|
||||
* - runs record and execute the scenario version they were created with
|
||||
* - runSnippet("alias@N") pins a snippet version
|
||||
* - export/import carry and restore exact versions
|
||||
* - e2e test exports build the requested version
|
||||
*/
|
||||
|
||||
import { INestApplication } from "@nestjs/common";
|
||||
@@ -12,6 +13,7 @@ import { DataSource } from "typeorm";
|
||||
import { buildTestApp } from "./app.harness";
|
||||
import { CredentialEntity } from "../src/credential/credential.entity";
|
||||
import { EnvironmentEntity } from "../src/environment/environment.entity";
|
||||
import { E2eExportService } from "../src/scenario/e2e-export.service";
|
||||
import { ScenarioSchedulerService } from "../src/scenario/scenario-scheduler.service";
|
||||
import { ScenarioService } from "../src/scenario/scenario.service";
|
||||
import { SnippetService } from "../src/snippet/snippet.service";
|
||||
@@ -367,6 +369,62 @@ describe("Versioning", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("e2e test export", () => {
|
||||
/** Captures the files the next e2e export zips. */
|
||||
function captureZippedFiles() {
|
||||
const service = app.get(E2eExportService) as unknown as {
|
||||
zip: (files: Record<string, string | Buffer>) => Promise<Buffer>;
|
||||
};
|
||||
const spy = jest.spyOn(service, "zip");
|
||||
return () => {
|
||||
const files = spy.mock.calls[0][0];
|
||||
spy.mockRestore();
|
||||
return files;
|
||||
};
|
||||
}
|
||||
|
||||
it("exports the latest version, or the one asked for", async () => {
|
||||
const name = `E2e ${uniq()}`;
|
||||
const slug = name.toLowerCase().replace(" ", "-");
|
||||
const sc = await scenarioService.create({ name });
|
||||
await scenarioService.createStep(sc.id, { execCode: "return 'v2';" });
|
||||
|
||||
let files = captureZippedFiles();
|
||||
const latest = await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/export-e2e`)
|
||||
.expect(200);
|
||||
expect(latest.headers["content-disposition"]).toBe(
|
||||
`attachment; filename="${slug}-v2-e2e-test.zip"`,
|
||||
);
|
||||
let zipped = files();
|
||||
expect(zipped["test.spec.ts"]).toContain("return 'v2';");
|
||||
expect(JSON.parse(zipped["package.json"] as string).name).toBe(
|
||||
`${slug}-v2-e2e-test`,
|
||||
);
|
||||
expect(zipped["README.md"]).toContain(`# ${name} (v2)`);
|
||||
|
||||
files = captureZippedFiles();
|
||||
const first = await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/export-e2e?version=1`)
|
||||
.expect(200);
|
||||
expect(first.headers["content-disposition"]).toBe(
|
||||
`attachment; filename="${slug}-v1-e2e-test.zip"`,
|
||||
);
|
||||
zipped = files();
|
||||
expect(zipped["test.spec.ts"]).not.toContain("return 'v2';");
|
||||
});
|
||||
|
||||
it("rejects a missing or invalid version", async () => {
|
||||
const sc = await scenarioService.create({ name: `e2e-${uniq()}` });
|
||||
await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/export-e2e?version=9`)
|
||||
.expect(404);
|
||||
await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/export-e2e?version=abc`)
|
||||
.expect(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe("snippet export/import", () => {
|
||||
it("export includes the version and import requires it", async () => {
|
||||
const alias = `sexp-${uniq()}`;
|
||||
|
||||
Reference in new issue
Block a user