Skip to content

Commit

Permalink
chore(e2e): surface errors better in e2e test helper (#4195)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Nov 15, 2022
1 parent 7caa548 commit a2098d8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
6 changes: 3 additions & 3 deletions features/ec2/step_definitions/ec2.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Given("I attempt to copy an encrypted snapshot across regions", function (callba
const dstEc2 = new EC2({ region: destRegion });

function teardown() {
if (volId) srcEc2.deleteVolume({ VolumeId: volId }).send();
if (srcSnapId) srcEc2.deleteSnapshot({ SnapshotId: srcSnapId }).send();
if (dstSnapId) dstEc2.deleteSnapshot({ SnapshotId: dstSnapId }).send();
if (volId) srcEc2.deleteVolume({ VolumeId: volId });
if (srcSnapId) srcEc2.deleteSnapshot({ SnapshotId: srcSnapId });
if (dstSnapId) dstEc2.deleteSnapshot({ SnapshotId: dstSnapId });
}

params = {
Expand Down
21 changes: 16 additions & 5 deletions features/extra/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ module.exports = {
world.data = data;

try {
if (typeof next.condition === "function") {
if (next && typeof next.condition === "function") {
const condition = next.condition.call(world, world);
if (!condition) {
next.fail(new Error("Request success condition failed"));
next.fail(new Error("Request success condition failed."));
return;
}
}
Expand All @@ -91,10 +91,16 @@ module.exports = {
} else if (extra !== false && err) {
world.unexpectedError(svc.config.signingName, operation, world.error.name, world.error.message, next);
} else {
next.call(world);
if (typeof next.call === "function") {
next.call(world);
}
}
} catch (err) {
next.fail(err);
if (next && typeof next.fail === "function") {
next.fail(err);
return;
}
throw err;
}
});
},
Expand All @@ -105,7 +111,12 @@ module.exports = {
* operation failed.
*/
unexpectedError: function unexpectedError(svc, op, name, msg, next) {
next.fail(new Error(`Received unexpected error from ${svc}.${op}, ${name}: ${msg}`));
var err = new Error(`Received unexpected error from ${svc}.${op}, ${name}: ${msg}`);
if (next && typeof next.fail === "function") {
next.fail(err);
return;
}
throw err;
},

/**
Expand Down
11 changes: 8 additions & 3 deletions features/s3/step_definitions/buckets.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ Before({ tags: "@buckets" }, function () {

After({ tags: "@buckets" }, function (callback) {
if (this.bucket) {
this.request("s3", "deleteBucket", { Bucket: this.bucket }, callback);
this.bucket = undefined;
this.s3
.deleteBucket({ Bucket: this.bucket })
.catch(() => {})
.then(() => {
this.bucket = undefined;
})
.then(callback);
} else {
callback();
}
Expand All @@ -33,7 +38,7 @@ Given(
);

When("I create a bucket with the location constraint {string}", function (location, callback) {
const bucket = (this.bucket = this.uniqueName("aws-sdk-js-integration"));
this.bucket = this.uniqueName("aws-sdk-js-integration");
const params = {
Bucket: this.bucket,
CreateBucketConfiguration: {
Expand Down

0 comments on commit a2098d8

Please sign in to comment.