Skip to content

Commit 4a7da2f

Browse files
Converted all of the tests from Promise syntax to async/await
1 parent a41c247 commit 4a7da2f

28 files changed

Lines changed: 1548 additions & 2060 deletions

File tree

test/fixtures/polyfill.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ const { host } = require("host-environment");
55
// Load the Babel Polyfills for old browsers.
66
// NOTE: It's important that we ONLY do this when needed,
77
// to ensure that our code works _without_ polyfills everywhere else
8-
if (host.browser.IE) {
8+
if (host.os.windows) {
99
require("@babel/polyfill");
1010
}

test/specs/__({[ % & $ # @ ` ~ ,)}]__/special-characters.spec.js

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ const parsedSchema = require("./parsed");
88
const dereferencedSchema = require("./dereferenced");
99

1010
describe("File names with special characters", () => {
11-
it("should parse successfully", () => {
11+
it("should parse successfully", async () => {
1212
let parser = new $RefParser();
13-
return parser
14-
.parse(path.rel("specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml"))
15-
.then(function (schema) {
16-
expect(schema).to.equal(parser.schema);
17-
expect(schema).to.deep.equal(parsedSchema.schema);
18-
expect(parser.$refs.paths()).to.deep.equal([path.abs("specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml")]);
19-
});
13+
const schema = await parser.parse(path.rel("specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml"));
14+
expect(schema).to.equal(parser.schema);
15+
expect(schema).to.deep.equal(parsedSchema.schema);
16+
expect(parser.$refs.paths()).to.deep.equal([path.abs("specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml")]);
2017
});
2118

2219
it("should resolve successfully", helper.testResolve(
@@ -25,26 +22,19 @@ describe("File names with special characters", () => {
2522
path.abs("specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.json"), parsedSchema.file
2623
));
2724

28-
it("should dereference successfully", () => {
25+
it("should dereference successfully", async () => {
2926
let parser = new $RefParser();
30-
return parser
31-
.dereference(path.rel("specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml"))
32-
.then(function (schema) {
33-
expect(schema).to.equal(parser.schema);
34-
expect(schema).to.deep.equal(dereferencedSchema);
35-
36-
// The "circular" flag should NOT be set
37-
expect(parser.$refs.circular).to.equal(false);
38-
});
27+
const schema = await parser.dereference(path.rel("specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml"));
28+
expect(schema).to.equal(parser.schema);
29+
expect(schema).to.deep.equal(dereferencedSchema);
30+
// The "circular" flag should NOT be set
31+
expect(parser.$refs.circular).to.equal(false);
3932
});
4033

41-
it("should bundle successfully", () => {
34+
it("should bundle successfully", async () => {
4235
let parser = new $RefParser();
43-
return parser
44-
.bundle(path.rel("specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml"))
45-
.then(function (schema) {
46-
expect(schema).to.equal(parser.schema);
47-
expect(schema).to.deep.equal(dereferencedSchema);
48-
});
36+
const schema = await parser.bundle(path.rel("specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml"));
37+
expect(schema).to.equal(parser.schema);
38+
expect(schema).to.deep.equal(dereferencedSchema);
4939
});
5040
});

test/specs/blank/blank.spec.js

Lines changed: 53 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -25,60 +25,48 @@ describe("Blank files", () => {
2525
});
2626

2727
describe("main file", () => {
28-
it("should throw an error for a blank YAML file", function (done) {
29-
testDone = done;
30-
$RefParser
31-
.parse(path.rel("specs/blank/files/blank.yaml"))
32-
.then(helper.shouldNotGetCalled(done))
33-
.catch(function (err) {
34-
expect(err).to.be.an.instanceOf(SyntaxError);
35-
expect(err.message).to.contain("blank/files/blank.yaml");
36-
expect(err.message).to.contain("is not a valid JSON Schema");
37-
done();
38-
})
39-
.catch(done);
28+
it("should throw an error for a blank YAML file", async () => {
29+
try {
30+
await $RefParser.parse(path.rel("specs/blank/files/blank.yaml"));
31+
helper.shouldNotGetCalled();
32+
}
33+
catch (err) {
34+
expect(err).to.be.an.instanceOf(SyntaxError);
35+
expect(err.message).to.contain("blank/files/blank.yaml");
36+
expect(err.message).to.contain("is not a valid JSON Schema");
37+
}
4038
});
4139

42-
it('should throw a different error if "parse.yaml.allowEmpty" is disabled', function (done) {
43-
testDone = done;
44-
$RefParser
45-
.parse(path.rel("specs/blank/files/blank.yaml"), { parse: { yaml: { allowEmpty: false }}})
46-
.then(helper.shouldNotGetCalled(done))
47-
.catch(function (err) {
48-
expect(err).to.be.an.instanceOf(SyntaxError);
49-
expect(err.message).to.contain("Error parsing ");
50-
expect(err.message).to.contain("blank/files/blank.yaml");
51-
expect(err.message).to.contain("Parsed value is empty");
52-
done();
53-
})
54-
.catch(done);
40+
it('should throw a different error if "parse.yaml.allowEmpty" is disabled', async () => {
41+
try {
42+
await $RefParser.parse(path.rel("specs/blank/files/blank.yaml"), { parse: { yaml: { allowEmpty: false }}});
43+
helper.shouldNotGetCalled();
44+
}
45+
catch (err) {
46+
expect(err).to.be.an.instanceOf(SyntaxError);
47+
expect(err.message).to.contain("Error parsing ");
48+
expect(err.message).to.contain("blank/files/blank.yaml");
49+
expect(err.message).to.contain("Parsed value is empty");
50+
}
5551
});
5652

57-
it("should throw an error for a blank JSON file", function (done) {
58-
testDone = done;
59-
$RefParser
60-
.parse(path.rel("specs/blank/files/blank.json"), { parse: { json: { allowEmpty: false }}})
61-
.then(helper.shouldNotGetCalled(done))
62-
.catch(function (err) {
63-
expect(err).to.be.an.instanceOf(SyntaxError);
64-
expect(err.message).to.contain("Error parsing ");
65-
expect(err.message).to.contain("blank/files/blank.json");
66-
done();
67-
})
68-
.catch(done);
53+
it("should throw an error for a blank JSON file", async () => {
54+
try {
55+
await $RefParser.parse(path.rel("specs/blank/files/blank.json"), { parse: { json: { allowEmpty: false }}});
56+
helper.shouldNotGetCalled();
57+
}
58+
catch (err) {
59+
expect(err).to.be.an.instanceOf(SyntaxError);
60+
expect(err.message).to.contain("Error parsing ");
61+
expect(err.message).to.contain("blank/files/blank.json");
62+
}
6963
});
7064
});
7165

7266
describe("referenced files", () => {
73-
it("should parse successfully", function (done) {
74-
testDone = done;
75-
$RefParser
76-
.parse(path.rel("specs/blank/blank.yaml"))
77-
.then(function (schema) {
78-
expect(schema).to.deep.equal(parsedSchema.schema);
79-
done();
80-
})
81-
.catch(done);
67+
it("should parse successfully", async () => {
68+
let schema = await $RefParser.parse(path.rel("specs/blank/blank.yaml"));
69+
expect(schema).to.deep.equal(parsedSchema.schema);
8270
});
8371

8472
it("should resolve successfully", helper.testResolve(
@@ -91,45 +79,29 @@ describe("Blank files", () => {
9179
path.abs("specs/blank/files/blank.foo"), parsedSchema.unknown
9280
));
9381

94-
it("should dereference successfully", function (done) {
95-
testDone = done;
96-
$RefParser
97-
.dereference(path.rel("specs/blank/blank.yaml"))
98-
.then(function (schema) {
99-
schema.binary = helper.convertNodeBuffersToPOJOs(schema.binary);
100-
expect(schema).to.deep.equal(dereferencedSchema);
101-
done();
102-
})
103-
.catch(done);
82+
it("should dereference successfully", async () => {
83+
let schema = await $RefParser.dereference(path.rel("specs/blank/blank.yaml"));
84+
schema.binary = helper.convertNodeBuffersToPOJOs(schema.binary);
85+
expect(schema).to.deep.equal(dereferencedSchema);
10486
});
10587

106-
it("should bundle successfully", function (done) {
107-
testDone = done;
108-
$RefParser
109-
.bundle(path.rel("specs/blank/blank.yaml"))
110-
.then(function (schema) {
111-
schema.binary = helper.convertNodeBuffersToPOJOs(schema.binary);
112-
expect(schema).to.deep.equal(dereferencedSchema);
113-
done();
114-
})
115-
.catch(done);
88+
it("should bundle successfully", async () => {
89+
let schema = await $RefParser.bundle(path.rel("specs/blank/blank.yaml"));
90+
schema.binary = helper.convertNodeBuffersToPOJOs(schema.binary);
91+
expect(schema).to.deep.equal(dereferencedSchema);
11692
});
11793

118-
it('should throw an error if "allowEmpty" is disabled', function (done) {
119-
testDone = done;
120-
$RefParser
121-
.dereference(path.rel("specs/blank/blank.yaml"), {
122-
parse: { binary: { allowEmpty: false }}
123-
})
124-
.then(helper.shouldNotGetCalled(done))
125-
.catch(function (err) {
126-
expect(err).to.be.an.instanceOf(SyntaxError);
127-
expect(err.message).to.contain("Error parsing ");
128-
expect(err.message).to.contain("blank/files/blank.png");
129-
expect(err.message).to.contain("Parsed value is empty");
130-
done();
131-
})
132-
.catch(done);
94+
it('should throw an error if "allowEmpty" is disabled', async () => {
95+
try {
96+
await $RefParser.dereference(path.rel("specs/blank/blank.yaml"), { parse: { binary: { allowEmpty: false }}});
97+
helper.shouldNotGetCalled();
98+
}
99+
catch (err) {
100+
expect(err).to.be.an.instanceOf(SyntaxError);
101+
expect(err.message).to.contain("Error parsing ");
102+
expect(err.message).to.contain("blank/files/blank.png");
103+
expect(err.message).to.contain("Parsed value is empty");
104+
}
133105
});
134106
});
135107
});

test/specs/callbacks.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const path = require("../utils/path");
77

88
describe("Callback & Promise syntax", () => {
99
["parse", "resolve", "dereference", "bundle"].forEach(function (method) {
10-
describe(method + " method", () => {
10+
describe(method + " method", function () {
1111
it("should call the callback function upon success", testCallbackSuccess(method));
1212
it("should call the callback function upon failure", testCallbackError(method));
1313
it("should resolve the Promise upon success", testPromiseSuccess(method));

0 commit comments

Comments
 (0)