Skip to content

Commit 41f6304

Browse files
authored
Upgrade: sinon (#11855)
1 parent 167ce87 commit 41f6304

File tree

13 files changed

+226
-274
lines changed

13 files changed

+226
-274
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"recast": "^0.17.6",
122122
"regenerator-runtime": "^0.13.2",
123123
"shelljs": "^0.8.2",
124-
"sinon": "^3.3.0",
124+
"sinon": "^7.3.2",
125125
"temp": "^0.9.0",
126126
"webpack": "^4.29.6",
127127
"webpack-cli": "^3.3.0",

tests/lib/cli-engine/cascading-config-array-factory.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ describe("CascadingConfigArrayFactory", () => {
8080
describe("with 'tests/fixtures/config-hierarchy' files", () => {
8181
const { CascadingConfigArrayFactory } = require("../../../lib/cli-engine/cascading-config-array-factory");
8282
let fixtureDir;
83-
let sandbox;
8483

8584
const DIRECTORY_CONFIG_HIERARCHY = require("../../fixtures/config-hierarchy/file-structure.json");
8685

@@ -100,7 +99,7 @@ describe("CascadingConfigArrayFactory", () => {
10099
* @private
101100
*/
102101
function mockOsHomedir(fakeUserHomePath) {
103-
sandbox.stub(os, "homedir")
102+
sinon.stub(os, "homedir")
104103
.returns(fakeUserHomePath);
105104
}
106105

@@ -155,12 +154,8 @@ describe("CascadingConfigArrayFactory", () => {
155154
sh.cp("-r", "./tests/fixtures/rules", fixtureDir);
156155
});
157156

158-
beforeEach(() => {
159-
sandbox = sinon.sandbox.create();
160-
});
161-
162157
afterEach(() => {
163-
sandbox.verifyAndRestore();
158+
sinon.verifyAndRestore();
164159
});
165160

166161
after(() => {
@@ -209,7 +204,7 @@ describe("CascadingConfigArrayFactory", () => {
209204
const configPath = path.resolve(__dirname, "../../fixtures/configurations/.eslintrc");
210205
const factory = new CascadingConfigArrayFactory();
211206

212-
sandbox.stub(fs, "readFileSync").throws(new Error());
207+
sinon.stub(fs, "readFileSync").throws(new Error());
213208

214209
assert.throws(() => {
215210
getConfig(factory, configPath);
@@ -221,7 +216,7 @@ describe("CascadingConfigArrayFactory", () => {
221216
const configPath = ".eslintrc";
222217
const factory = new CascadingConfigArrayFactory();
223218

224-
sandbox.stub(fs, "readFileSync").throws(new Error());
219+
sinon.stub(fs, "readFileSync").throws(new Error());
225220

226221
assert.throws(() => {
227222
getConfig(factory, configPath);
@@ -234,7 +229,7 @@ describe("CascadingConfigArrayFactory", () => {
234229
const configArrayFactory = new ConfigArrayFactory();
235230
const factory = new CascadingConfigArrayFactory({ configArrayFactory });
236231

237-
sandbox.spy(configArrayFactory, "loadInDirectory");
232+
sinon.spy(configArrayFactory, "loadInDirectory");
238233

239234
// If cached this should be called only once
240235
getConfig(factory, configPath);

tests/lib/cli-engine/cli-engine.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,7 +2100,6 @@ describe("CLIEngine", () => {
21002100
});
21012101

21022102
describe("cache", () => {
2103-
let sandbox;
21042103

21052104
/**
21062105
* helper method to delete a file without caring about exceptions
@@ -2131,11 +2130,10 @@ describe("CLIEngine", () => {
21312130

21322131
beforeEach(() => {
21332132
deleteCache();
2134-
sandbox = sinon.sandbox.create();
21352133
});
21362134

21372135
afterEach(() => {
2138-
sandbox.restore();
2136+
sinon.restore();
21392137
deleteCache();
21402138
});
21412139

@@ -2187,7 +2185,7 @@ describe("CLIEngine", () => {
21872185

21882186
assert.isTrue(shell.test("-f", path.resolve(`./tmp/.cacheFileDir/.cache_${hash(process.cwd())}`)), "the cache for eslint was created");
21892187

2190-
sandbox.restore();
2188+
sinon.restore();
21912189
});
21922190
});
21932191

@@ -2214,7 +2212,7 @@ describe("CLIEngine", () => {
22142212

22152213
assert.isTrue(shell.test("-f", path.resolve(`./tmp/.cacheFileDir/.cache_${hash(process.cwd())}`)), "the cache for eslint was created");
22162214

2217-
sandbox.restore();
2215+
sinon.restore();
22182216
});
22192217

22202218
it("should create the cache file inside cwd when no cacheLocation provided", () => {
@@ -2254,7 +2252,7 @@ describe("CLIEngine", () => {
22542252
ignore: false
22552253
});
22562254

2257-
let spy = sandbox.spy(fs, "readFileSync");
2255+
let spy = sinon.spy(fs, "readFileSync");
22582256

22592257
let file = getFixturePath("cache/src", "test-file.js");
22602258

@@ -2267,7 +2265,7 @@ describe("CLIEngine", () => {
22672265
assert.isTrue(shell.test("-f", path.resolve(".eslintcache")), "the cache for eslint was created");
22682266

22692267
// destroy the spy
2270-
sandbox.restore();
2268+
sinon.restore();
22712269

22722270
engine = new CLIEngine({
22732271
useEslintrc: false,
@@ -2283,7 +2281,7 @@ describe("CLIEngine", () => {
22832281
});
22842282

22852283
// create a new spy
2286-
spy = sandbox.spy(fs, "readFileSync");
2284+
spy = sinon.spy(fs, "readFileSync");
22872285

22882286
const cachedResult = engine.executeOnFiles([file]);
22892287

@@ -2309,7 +2307,7 @@ describe("CLIEngine", () => {
23092307
ignore: false
23102308
});
23112309

2312-
let spy = sandbox.spy(fs, "readFileSync");
2310+
let spy = sinon.spy(fs, "readFileSync");
23132311

23142312
let file = getFixturePath("cache/src", "test-file.js");
23152313

@@ -2321,7 +2319,7 @@ describe("CLIEngine", () => {
23212319
assert.isTrue(shell.test("-f", path.resolve(".eslintcache")), "the cache for eslint was created");
23222320

23232321
// destroy the spy
2324-
sandbox.restore();
2322+
sinon.restore();
23252323

23262324
engine = new CLIEngine({
23272325
useEslintrc: false,
@@ -2337,7 +2335,7 @@ describe("CLIEngine", () => {
23372335
});
23382336

23392337
// create a new spy
2340-
spy = sandbox.spy(fs, "readFileSync");
2338+
spy = sinon.spy(fs, "readFileSync");
23412339

23422340
const cachedResult = engine.executeOnFiles([file]);
23432341

@@ -3463,15 +3461,12 @@ describe("CLIEngine", () => {
34633461
});
34643462

34653463
describe("isPathIgnored", () => {
3466-
let sandbox;
3467-
34683464
beforeEach(() => {
3469-
sandbox = sinon.sandbox.create();
3470-
sandbox.stub(console, "info").returns(void 0);
3465+
sinon.stub(console, "info").returns(void 0);
34713466
});
34723467

34733468
afterEach(() => {
3474-
sandbox.restore();
3469+
sinon.restore();
34753470
});
34763471

34773472
it("should check if the given path is ignored", () => {
@@ -3730,11 +3725,8 @@ describe("CLIEngine", () => {
37303725
});
37313726

37323727
describe("outputFixes()", () => {
3733-
3734-
const sandbox = sinon.sandbox.create();
3735-
37363728
afterEach(() => {
3737-
sandbox.verifyAndRestore();
3729+
sinon.verifyAndRestore();
37383730
});
37393731

37403732
it("should call fs.writeFileSync() for each result with output", () => {
@@ -3756,7 +3748,7 @@ describe("CLIEngine", () => {
37563748
};
37573749

37583750
fakeFS.writeFileSync = function() {};
3759-
const spy = sandbox.spy(fakeFS, "writeFileSync");
3751+
const spy = sinon.spy(fakeFS, "writeFileSync");
37603752

37613753
localCLIEngine.outputFixes(report);
37623754

@@ -3788,7 +3780,7 @@ describe("CLIEngine", () => {
37883780
};
37893781

37903782
fakeFS.writeFileSync = function() {};
3791-
const spy = sandbox.spy(fakeFS, "writeFileSync");
3783+
const spy = sinon.spy(fakeFS, "writeFileSync");
37923784

37933785
localCLIEngine.outputFixes(report);
37943786

tests/lib/cli-engine/formatters/codeframe.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,8 @@ const formatter = proxyquire("../../../../lib/cli-engine/formatters/codeframe",
4242
//------------------------------------------------------------------------------
4343

4444
describe("formatter:codeframe", () => {
45-
let sandbox;
46-
47-
beforeEach(() => {
48-
sandbox = sinon.sandbox.create();
49-
});
50-
5145
afterEach(() => {
52-
sandbox.verifyAndRestore();
46+
sinon.verifyAndRestore();
5347
});
5448

5549
describe("when passed no messages", () => {
@@ -99,8 +93,8 @@ describe("formatter:codeframe", () => {
9993
});
10094

10195
it("should return bold yellow summary when there are only warnings", () => {
102-
sandbox.spy(chalkStub.yellow, "bold");
103-
sandbox.spy(chalkStub.red, "bold");
96+
sinon.spy(chalkStub.yellow, "bold");
97+
sinon.spy(chalkStub.red, "bold");
10498

10599
formatter(code);
106100

@@ -160,8 +154,8 @@ describe("formatter:codeframe", () => {
160154
});
161155

162156
it("should return bold red summary when there are errors", () => {
163-
sandbox.spy(chalkStub.yellow, "bold");
164-
sandbox.spy(chalkStub.red, "bold");
157+
sinon.spy(chalkStub.yellow, "bold");
158+
sinon.spy(chalkStub.red, "bold");
165159

166160
formatter(code);
167161

@@ -230,8 +224,8 @@ describe("formatter:codeframe", () => {
230224
});
231225

232226
it("should return bold red summary when at least 1 of the messages is an error", () => {
233-
sandbox.spy(chalkStub.yellow, "bold");
234-
sandbox.spy(chalkStub.red, "bold");
227+
sinon.spy(chalkStub.yellow, "bold");
228+
sinon.spy(chalkStub.red, "bold");
235229
code[0].messages[0].severity = 1;
236230
code[0].warningCount = 1;
237231
code[0].errorCount = 1;

tests/lib/cli-engine/formatters/stylish.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,16 @@ const formatter = proxyquire("../../../../lib/cli-engine/formatters/stylish", {
4343
//------------------------------------------------------------------------------
4444

4545
describe("formatter:stylish", () => {
46-
let sandbox;
4746
const colorsEnabled = chalk.enabled;
4847

4948
beforeEach(() => {
5049
chalk.enabled = false;
51-
sandbox = sinon.sandbox.create();
52-
sandbox.spy(chalkStub.yellow, "bold");
53-
sandbox.spy(chalkStub.red, "bold");
50+
sinon.spy(chalkStub.yellow, "bold");
51+
sinon.spy(chalkStub.red, "bold");
5452
});
5553

5654
afterEach(() => {
57-
sandbox.verifyAndRestore();
55+
sinon.verifyAndRestore();
5856
chalk.enabled = colorsEnabled;
5957
});
6058

tests/lib/cli-engine/lint-result-cache.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@ describe("LintResultCache", () => {
2626

2727
let LintResultCache,
2828
hashStub,
29-
sandbox,
3029
fakeConfig,
3130
fakeErrorResults,
3231
fakeErrorResultsAutofix;
3332

3433
before(() => {
35-
sandbox = sinon.sandbox.create();
36-
37-
hashStub = sandbox.stub();
34+
hashStub = sinon.stub();
3835

3936
let shouldFix = false;
4037

@@ -61,7 +58,7 @@ describe("LintResultCache", () => {
6158
});
6259

6360
afterEach(done => {
64-
sandbox.reset();
61+
sinon.reset();
6562

6663
fs.unlink(cacheFileLocation, err => {
6764
if (err && err.code !== "ENOENT") {
@@ -93,7 +90,7 @@ describe("LintResultCache", () => {
9390
lintResultsCache;
9491

9592
before(() => {
96-
getFileDescriptorStub = sandbox.stub();
93+
getFileDescriptorStub = sinon.stub();
9794

9895
fileEntryCacheStubs.create = () => ({
9996
getFileDescriptor: getFileDescriptorStub
@@ -187,7 +184,7 @@ describe("LintResultCache", () => {
187184
lintResultsCache;
188185

189186
before(() => {
190-
getFileDescriptorStub = sandbox.stub();
187+
getFileDescriptorStub = sinon.stub();
191188

192189
fileEntryCacheStubs.create = () => ({
193190
getFileDescriptor: getFileDescriptorStub
@@ -285,7 +282,7 @@ describe("LintResultCache", () => {
285282
lintResultsCache;
286283

287284
before(() => {
288-
reconcileStub = sandbox.stub();
285+
reconcileStub = sinon.stub();
289286

290287
fileEntryCacheStubs.create = () => ({
291288
reconcile: reconcileStub

0 commit comments

Comments
 (0)