Skip to content

Commit c49de91

Browse files
authored
Take a screenshot when a before() hook fails (#2767)
1 parent 8fb46b5 commit c49de91

17 files changed

+28
-24
lines changed

packages/compass-e2e-tests/helpers/compass.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,20 @@ export async function beforeTests(): Promise<Compass> {
554554
return compass;
555555
}
556556

557-
export async function afterTests(compass?: Compass): Promise<void> {
557+
export async function afterTests(
558+
compass?: Compass,
559+
test?: Mocha.Hook | Mocha.Test
560+
): Promise<void> {
558561
if (!compass) {
559-
console.log('compas is falsey in afterTests');
560562
return;
561563
}
562564

565+
if (test && test.state === undefined) {
566+
// if there's no state, then it is probably because the before() hook failed
567+
const filename = screenshotPathName(`${test.fullTitle()}-hook`);
568+
await compass.capturePage(filename);
569+
}
570+
563571
try {
564572
await compass.stop();
565573
} catch (err) {
@@ -595,7 +603,7 @@ export async function afterTest(
595603
compass: Compass,
596604
test?: Mocha.Hook | Mocha.Test
597605
): Promise<void> {
598-
if (test && test.state == 'failed') {
606+
if (test && test.state === 'failed') {
599607
await compass.capturePage(screenshotPathName(test.fullTitle()));
600608
}
601609
}

packages/compass-e2e-tests/tests/collection-aggregations-tab.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Collection aggregations tab', function () {
2121
});
2222

2323
after(async function () {
24-
await afterTests(compass);
24+
await afterTests(compass, this.currentTest);
2525
});
2626

2727
afterEach(async function () {

packages/compass-e2e-tests/tests/collection-documents-tab.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('Collection documents tab', function () {
2424
});
2525

2626
after(async function () {
27-
await afterTests(compass);
27+
await afterTests(compass, this.currentTest);
2828
await telemetry.stop();
2929
});
3030

packages/compass-e2e-tests/tests/collection-explain-plan-tab.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Collection explain plan tab', function () {
2020
});
2121

2222
after(async function () {
23-
await afterTests(compass);
23+
await afterTests(compass, this.currentTest);
2424
});
2525

2626
afterEach(async function () {

packages/compass-e2e-tests/tests/collection-export.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('Collection export', function () {
3333
});
3434

3535
after(async function () {
36-
await afterTests(compass);
36+
await afterTests(compass, this.currentTest);
3737
await telemetry.stop();
3838
});
3939

packages/compass-e2e-tests/tests/collection-heading.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Collection heading', function () {
2020
});
2121

2222
after(async function () {
23-
await afterTests(compass);
23+
await afterTests(compass, this.currentTest);
2424
});
2525

2626
afterEach(async function () {

packages/compass-e2e-tests/tests/collection-import.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Collection import', function () {
1919
});
2020

2121
after(async function () {
22-
await afterTests(compass);
22+
await afterTests(compass, this.currentTest);
2323
});
2424

2525
afterEach(async function () {

packages/compass-e2e-tests/tests/collection-indexes-tab.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Collection indexes tab', function () {
2020
});
2121

2222
after(async function () {
23-
await afterTests(compass);
23+
await afterTests(compass, this.currentTest);
2424
});
2525

2626
afterEach(async function () {

packages/compass-e2e-tests/tests/collection-schema-tab.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Collection schema tab', function () {
2020
});
2121

2222
after(async function () {
23-
await afterTests(compass);
23+
await afterTests(compass, this.currentTest);
2424
});
2525

2626
afterEach(async function () {

packages/compass-e2e-tests/tests/collection-validation-tab.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Collection validation tab', function () {
1919
});
2020

2121
after(async function () {
22-
await afterTests(compass);
22+
await afterTests(compass, this.currentTest);
2323
});
2424

2525
afterEach(async function () {

0 commit comments

Comments
 (0)