Skip to content

Commit d776d63

Browse files
committed
accept suite snapshot
1 parent 501ef3e commit d776d63

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/selianize/__tests__/suite.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,18 @@ describe("suite emitter", () => {
153153
}
154154
});
155155
});
156+
it("should append the snapshot to the normal hooks", () => {
157+
const suite = {
158+
id: "1",
159+
name: "example suite",
160+
timeout: "30",
161+
tests: []
162+
};
163+
const snapshot = {
164+
hook: "hook results"
165+
};
166+
return expect(SuiteEmitter.emit(suite, {}, undefined, snapshot)).resolves.toEqual({
167+
code: "jest.setTimeout(30000);describe(\"example suite\", () => {beforeAll(async () => {beforeAll code});beforeEach(async () => {before code});afterEach(async () => {after code});afterAll(async () => {afterAll code});hook results});"
168+
});
169+
});
156170
});

packages/selianize/src/suite.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const hooks = [];
1919

2020
import config from "./config";
2121

22-
export function emit(suite, tests, options = config) {
22+
export function emit(suite, tests, options = config, snapshot) {
2323
return new Promise(async (res, rej) => { // eslint-disable-line no-unused-vars
2424
const hookResults = (await Promise.all(hooks.map((hook) => hook({ name: suite.name })))).reduce((code, result) => (
2525
code
@@ -42,7 +42,7 @@ export function emit(suite, tests, options = config) {
4242
return res(testsCode);
4343
}
4444

45-
let result = `jest.setTimeout(${suite.timeout * 1000});describe("${suite.name}", () => {${hookResults}`;
45+
let result = `jest.setTimeout(${suite.timeout * 1000});describe("${suite.name}", () => {${hookResults}${snapshot ? snapshot.hook : ""}`;
4646

4747
result += testsCode.join("");
4848

0 commit comments

Comments
 (0)