Skip to content

Commit db6cb5d

Browse files
committed
[Tech Debt] Replace done() with async/await
1 parent c6c5b62 commit db6cb5d

File tree

7 files changed

+73
-104
lines changed

7 files changed

+73
-104
lines changed

test/actions/action.test.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ describe("Action", () => {
4141
}
4242
}
4343

44-
beforeEach((done) => {
44+
beforeEach(async () => {
4545
promiseExecuted = false;
4646
subject = new SuccessfulTestAction();
47-
subject.execute(context).then(() => {
48-
done();
49-
});
47+
await subject.execute(context);
5048
});
5149

5250
it("executes the strategy and awaits", () => {
@@ -66,13 +64,11 @@ describe("Action", () => {
6664
}
6765
}
6866

69-
beforeEach((done) => {
67+
beforeEach(async () => {
7068
promiseExecuted = false;
7169
errorlogSpy.resetHistory();
7270
subject = new UnsuccessfulTestAction();
73-
subject.execute(context).catch(() => {
74-
done();
75-
});
71+
await subject.execute(context).catch(() => {});
7672
});
7773

7874
it("executes the strategy and awaits", () => {

test/google_analytics/query_authorizer.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,42 +39,42 @@ describe("GoogleAnalyticsQueryAuthorizer", () => {
3939
appConfig.key_file = undefined;
4040
});
4141

42-
it("should resolve a query with the auth prop set to an authorized JWT", () => {
43-
return subject.authorizeQuery(query, appConfig).then((query) => {
42+
it("should resolve a query with the auth prop set to an authorized JWT", async () => {
43+
await subject.authorizeQuery(query, appConfig).then((query) => {
4444
expect(query.abc).to.equal(123);
4545
expect(query.auth).to.not.be.undefined;
4646
expect(query.auth).to.be.an.instanceof(googleapis.Auth.JWT);
4747
});
4848
});
4949

50-
it("should create a JWT with the proper scopes", () => {
51-
return subject.authorizeQuery({}, appConfig).then((query) => {
50+
it("should create a JWT with the proper scopes", async () => {
51+
await subject.authorizeQuery({}, appConfig).then((query) => {
5252
expect(query.auth.initArguments[3]).to.deep.equal([
5353
"https://www.googleapis.com/auth/analytics.readonly",
5454
]);
5555
});
5656
});
5757

58-
it("should authorize the JWT and resolve if it is valid", () => {
58+
it("should authorize the JWT and resolve if it is valid", async () => {
5959
let jwtAuthorized = false;
6060
googleapis.Auth.JWT.prototype.authorize = (callback) => {
6161
jwtAuthorized = true;
6262
callback(null, {});
6363
};
6464

65-
return subject.authorizeQuery({}, appConfig).then(() => {
65+
await subject.authorizeQuery({}, appConfig).then(() => {
6666
expect(jwtAuthorized).to.equal(true);
6767
});
6868
});
6969

70-
it("should authorize the JWT and reject if it is invalid", () => {
70+
it("should authorize the JWT and reject if it is invalid", async () => {
7171
let jwtAuthorized = false;
7272
googleapis.Auth.JWT.prototype.authorize = (callback) => {
7373
jwtAuthorized = true;
7474
callback(new Error("Failed to authorize"));
7575
};
7676

77-
return subject.authorizeQuery({}, appConfig).catch((err) => {
77+
await subject.authorizeQuery({}, appConfig).catch((err) => {
7878
expect(jwtAuthorized).to.equal(true);
7979
expect(err.message).to.equal("Failed to authorize");
8080
});

test/process_results/result_formatter.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ describe("ResultFormatter", () => {
2525
});
2626
});
2727

28-
it("should format results into JSON if the format is 'json'", () => {
28+
it("should format results into JSON if the format is 'json'", async () => {
2929
const result = analyticsDataProcessor.processData({ report, data });
3030

31-
return ResultFormatter.formatResult(result, { format: "json" }).then(
31+
await ResultFormatter.formatResult(result, { format: "json" }).then(
3232
(formattedResult) => {
3333
const json = JSON.parse(formattedResult);
3434
json.data.forEach((row, index) => {
@@ -46,10 +46,10 @@ describe("ResultFormatter", () => {
4646
);
4747
});
4848

49-
it("should remove the data attribute for JSON if options.slim is true", () => {
49+
it("should remove the data attribute for JSON if options.slim is true", async () => {
5050
const result = analyticsDataProcessor.processData({ report, data });
5151

52-
return ResultFormatter.formatResult(result, {
52+
await ResultFormatter.formatResult(result, {
5353
format: "json",
5454
slim: true,
5555
}).then((formattedResult) => {
@@ -58,19 +58,19 @@ describe("ResultFormatter", () => {
5858
});
5959
});
6060

61-
it("should reject if the data cannot be JSON stringified", () => {
61+
it("should reject if the data cannot be JSON stringified", async () => {
6262
const array = [];
6363
array[0] = array;
6464

65-
return ResultFormatter.formatResult(array).catch((e) => {
65+
await ResultFormatter.formatResult(array).catch((e) => {
6666
expect(e).to.match(/TypeError: Converting circular structure to JSON/);
6767
});
6868
});
6969

70-
it("should format results into CSV if the format is 'csv'", () => {
70+
it("should format results into CSV if the format is 'csv'", async () => {
7171
const result = analyticsDataProcessor.processData({ report, data });
7272

73-
return ResultFormatter.formatResult(result, {
73+
await ResultFormatter.formatResult(result, {
7474
format: "csv",
7575
slim: true,
7676
}).then((formattedResult) => {
@@ -89,10 +89,10 @@ describe("ResultFormatter", () => {
8989
});
9090
});
9191

92-
it("should throw an error if the format is unsupported", () => {
92+
it("should throw an error if the format is unsupported", async () => {
9393
const result = analyticsDataProcessor.processData({ report, data });
9494

95-
return ResultFormatter.formatResult(result, {
95+
await ResultFormatter.formatResult(result, {
9696
format: "xml",
9797
slim: true,
9898
}).catch((e) => {

test/processor.test.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ describe("Processor", () => {
1919
};
2020
const context = {};
2121

22-
beforeEach((done) => {
22+
beforeEach(async () => {
2323
subject = new Processor([action]);
24-
subject.processChain(context).then(() => {
25-
done();
26-
});
24+
await subject.processChain(context);
2725
});
2826

2927
it("calls execute on the action", () => {
@@ -40,11 +38,9 @@ describe("Processor", () => {
4038
};
4139
const context = {};
4240

43-
beforeEach((done) => {
41+
beforeEach(async () => {
4442
subject = new Processor([action]);
45-
subject.processChain(context).then(() => {
46-
done();
47-
});
43+
await subject.processChain(context);
4844
});
4945

5046
it("does not call execute on the action", () => {
@@ -67,11 +63,9 @@ describe("Processor", () => {
6763
};
6864
const context = {};
6965

70-
beforeEach((done) => {
66+
beforeEach(async () => {
7167
subject = new Processor([action1, action2]);
72-
subject.processChain(context).then(() => {
73-
done();
74-
});
68+
await subject.processChain(context);
7569
});
7670

7771
it("calls execute on each action", () => {

test/publish/disk.test.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe("DiskPublisher", () => {
1818

1919
describe(".publish({ name, data, format, directory })", () => {
2020
context("when the format is json", () => {
21-
it("should write the results to <output>/<report name>.json", (done) => {
21+
it("should write the results to <output>/<report name>.json", async () => {
2222
const options = { output: "path/to/output", formats: ["json"] };
2323
const report = { name: "report-name" };
2424
const results = "I'm the results";
@@ -31,22 +31,19 @@ describe("DiskPublisher", () => {
3131
return null;
3232
};
3333

34-
DiskPublisher.publish({
34+
await DiskPublisher.publish({
3535
name: report.name,
3636
data: results,
3737
format: options.formats[0],
3838
directory: options.output,
39-
})
40-
.then(() => {
41-
expect(fileWritten).to.be.true;
42-
done();
43-
})
44-
.catch(done);
39+
}).then(() => {
40+
expect(fileWritten).to.be.true;
41+
});
4542
});
4643
});
4744

4845
context("when the format is csv", () => {
49-
it("should write the results to <output>/<report name>.csv", () => {
46+
it("should write the results to <output>/<report name>.csv", async () => {
5047
const options = { output: "path/to/output", formats: ["csv"] };
5148
const report = { name: "report-name" };
5249
const results = "I'm the results";
@@ -59,7 +56,7 @@ describe("DiskPublisher", () => {
5956
return null;
6057
};
6158

62-
return DiskPublisher.publish({
59+
await DiskPublisher.publish({
6360
name: report.name,
6461
data: results,
6562
format: options.formats[0],

0 commit comments

Comments
 (0)