Skip to content

Commit 5a3fc9a

Browse files
Refactored all tests to use CommonJS requires rather than globals
1 parent 48ae6e6 commit 5a3fc9a

82 files changed

Lines changed: 1206 additions & 905 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

test/fixtures/globals.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

test/fixtures/helper.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
(function () {
2-
"use strict";
1+
"use strict";
32

4-
host.global.helper = {};
3+
const $RefParser = require("../..");
4+
const host = require("host-environment");
5+
const { expect } = require("chai");
56

7+
const helper = module.exports = {
68
/**
79
* Parsed JSON schemas
810
*/
9-
helper.parsed = {};
11+
parsed: {},
1012

1113
/**
1214
* Dereferenced JSON schemas
1315
*/
14-
helper.dereferenced = {};
16+
dereferenced: {},
1517

1618
/**
1719
* Bundled JSON schemas
1820
*/
19-
helper.bundled = {};
21+
bundled: {},
2022

2123
/**
2224
* Throws an error if called.
2325
*/
24-
helper.shouldNotGetCalled = function shouldNotGetCalled (done) {
26+
shouldNotGetCalled (done) {
2527
let err = new Error("This function should not have gotten called.");
2628
if (typeof done === "function") {
2729
return function (err2) {
@@ -36,7 +38,7 @@
3638
else {
3739
throw err;
3840
}
39-
};
41+
},
4042

4143
/**
4244
* Tests the {@link $RefParser.resolve} method,
@@ -46,7 +48,7 @@
4648
* @param {...*} [params] - The expected resolved file paths and values
4749
* @returns {Function}
4850
*/
49-
helper.testResolve = function testResolve (filePath, params) {
51+
testResolve (filePath, params) {
5052
let parsedSchema = arguments[2];
5153
let expectedFiles = [], expectedValues = [], actualFiles;
5254

@@ -94,12 +96,12 @@
9496
})
9597
.catch(helper.shouldNotGetCalled(done));
9698
};
97-
};
99+
},
98100

99101
/**
100102
* Converts Buffer objects to POJOs, so they can be compared using Chai
101103
*/
102-
helper.convertNodeBuffersToPOJOs = function convertNodeBuffersToPOJOs (value) {
104+
convertNodeBuffersToPOJOs (value) {
103105
if (value && (value._isBuffer || (value.constructor && value.constructor.name === "Buffer"))) {
104106
// Convert Buffers to POJOs for comparison
105107
value = value.toJSON();
@@ -110,12 +112,12 @@
110112
}
111113
}
112114
return value;
113-
};
115+
},
114116

115117
/**
116118
* Creates a deep clone of the given value.
117119
*/
118-
helper.cloneDeep = function cloneDeep (value) {
120+
cloneDeep (value) {
119121
let clone = value;
120122
if (value && typeof (value) === "object") {
121123
clone = value instanceof Array ? [] : {};
@@ -125,6 +127,5 @@
125127
}
126128
}
127129
return clone;
128-
};
129-
130-
}());
130+
},
131+
};

test/fixtures/mocha.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
// Mocha configuration
2-
(function () {
3-
"use strict";
1+
"use strict";
42

5-
if (host.browser) {
6-
mocha.setup("bdd");
7-
mocha.fullTrace();
8-
mocha.asyncOnly();
9-
mocha.checkLeaks();
10-
mocha.globals(["$0", "$1", "$2", "$3", "$4", "$5"]);
11-
}
3+
const host = require("host-environment");
124

13-
beforeEach(function () {
14-
// Flag TravisCI and SauceLabs as being very slow environments
15-
let isSlowEnvironment = host.env.CI || host.karma;
5+
// Mocha configuration
6+
if (host.browser) {
7+
mocha.setup("bdd");
8+
mocha.fullTrace();
9+
mocha.asyncOnly();
10+
mocha.checkLeaks();
11+
mocha.globals(["$0", "$1", "$2", "$3", "$4", "$5"]);
12+
}
1613

17-
// Most of our tests perform multiple AJAX requests,
18-
// so we need to increase the timeouts to allow for that
19-
this.currentTest.timeout(isSlowEnvironment ? 20000 : 4000);
20-
this.currentTest.slow(1000);
21-
});
14+
beforeEach(function () {
15+
// Flag TravisCI and SauceLabs as being very slow environments
16+
let isSlowEnvironment = host.env.CI || host.karma;
2217

23-
}());
18+
// Most of our tests perform multiple AJAX requests,
19+
// so we need to increase the timeouts to allow for that
20+
this.currentTest.timeout(isSlowEnvironment ? 20000 : 4000);
21+
this.currentTest.slow(1000);
22+
});

0 commit comments

Comments
 (0)