diff --git a/package.json b/package.json index 918e3b201af..ef4daf62211 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,7 @@ "recast": "^0.17.6", "regenerator-runtime": "^0.13.2", "shelljs": "^0.8.2", - "sinon": "^3.3.0", + "sinon": "^7.3.2", "temp": "^0.9.0", "webpack": "^4.29.6", "webpack-cli": "^3.3.0", diff --git a/tests/lib/cli-engine/cascading-config-array-factory.js b/tests/lib/cli-engine/cascading-config-array-factory.js index d601ff00ad5..e0ca4f06378 100644 --- a/tests/lib/cli-engine/cascading-config-array-factory.js +++ b/tests/lib/cli-engine/cascading-config-array-factory.js @@ -80,7 +80,6 @@ describe("CascadingConfigArrayFactory", () => { describe("with 'tests/fixtures/config-hierarchy' files", () => { const { CascadingConfigArrayFactory } = require("../../../lib/cli-engine/cascading-config-array-factory"); let fixtureDir; - let sandbox; const DIRECTORY_CONFIG_HIERARCHY = require("../../fixtures/config-hierarchy/file-structure.json"); @@ -100,7 +99,7 @@ describe("CascadingConfigArrayFactory", () => { * @private */ function mockOsHomedir(fakeUserHomePath) { - sandbox.stub(os, "homedir") + sinon.stub(os, "homedir") .returns(fakeUserHomePath); } @@ -155,12 +154,8 @@ describe("CascadingConfigArrayFactory", () => { sh.cp("-r", "./tests/fixtures/rules", fixtureDir); }); - beforeEach(() => { - sandbox = sinon.sandbox.create(); - }); - afterEach(() => { - sandbox.verifyAndRestore(); + sinon.verifyAndRestore(); }); after(() => { @@ -209,7 +204,7 @@ describe("CascadingConfigArrayFactory", () => { const configPath = path.resolve(__dirname, "../../fixtures/configurations/.eslintrc"); const factory = new CascadingConfigArrayFactory(); - sandbox.stub(fs, "readFileSync").throws(new Error()); + sinon.stub(fs, "readFileSync").throws(new Error()); assert.throws(() => { getConfig(factory, configPath); @@ -221,7 +216,7 @@ describe("CascadingConfigArrayFactory", () => { const configPath = ".eslintrc"; const factory = new CascadingConfigArrayFactory(); - sandbox.stub(fs, "readFileSync").throws(new Error()); + sinon.stub(fs, "readFileSync").throws(new Error()); assert.throws(() => { getConfig(factory, configPath); @@ -234,7 +229,7 @@ describe("CascadingConfigArrayFactory", () => { const configArrayFactory = new ConfigArrayFactory(); const factory = new CascadingConfigArrayFactory({ configArrayFactory }); - sandbox.spy(configArrayFactory, "loadInDirectory"); + sinon.spy(configArrayFactory, "loadInDirectory"); // If cached this should be called only once getConfig(factory, configPath); diff --git a/tests/lib/cli-engine/cli-engine.js b/tests/lib/cli-engine/cli-engine.js index 20445af531a..359970eb9f7 100644 --- a/tests/lib/cli-engine/cli-engine.js +++ b/tests/lib/cli-engine/cli-engine.js @@ -2100,7 +2100,6 @@ describe("CLIEngine", () => { }); describe("cache", () => { - let sandbox; /** * helper method to delete a file without caring about exceptions @@ -2131,11 +2130,10 @@ describe("CLIEngine", () => { beforeEach(() => { deleteCache(); - sandbox = sinon.sandbox.create(); }); afterEach(() => { - sandbox.restore(); + sinon.restore(); deleteCache(); }); @@ -2187,7 +2185,7 @@ describe("CLIEngine", () => { assert.isTrue(shell.test("-f", path.resolve(`./tmp/.cacheFileDir/.cache_${hash(process.cwd())}`)), "the cache for eslint was created"); - sandbox.restore(); + sinon.restore(); }); }); @@ -2214,7 +2212,7 @@ describe("CLIEngine", () => { assert.isTrue(shell.test("-f", path.resolve(`./tmp/.cacheFileDir/.cache_${hash(process.cwd())}`)), "the cache for eslint was created"); - sandbox.restore(); + sinon.restore(); }); it("should create the cache file inside cwd when no cacheLocation provided", () => { @@ -2254,7 +2252,7 @@ describe("CLIEngine", () => { ignore: false }); - let spy = sandbox.spy(fs, "readFileSync"); + let spy = sinon.spy(fs, "readFileSync"); let file = getFixturePath("cache/src", "test-file.js"); @@ -2267,7 +2265,7 @@ describe("CLIEngine", () => { assert.isTrue(shell.test("-f", path.resolve(".eslintcache")), "the cache for eslint was created"); // destroy the spy - sandbox.restore(); + sinon.restore(); engine = new CLIEngine({ useEslintrc: false, @@ -2283,7 +2281,7 @@ describe("CLIEngine", () => { }); // create a new spy - spy = sandbox.spy(fs, "readFileSync"); + spy = sinon.spy(fs, "readFileSync"); const cachedResult = engine.executeOnFiles([file]); @@ -2309,7 +2307,7 @@ describe("CLIEngine", () => { ignore: false }); - let spy = sandbox.spy(fs, "readFileSync"); + let spy = sinon.spy(fs, "readFileSync"); let file = getFixturePath("cache/src", "test-file.js"); @@ -2321,7 +2319,7 @@ describe("CLIEngine", () => { assert.isTrue(shell.test("-f", path.resolve(".eslintcache")), "the cache for eslint was created"); // destroy the spy - sandbox.restore(); + sinon.restore(); engine = new CLIEngine({ useEslintrc: false, @@ -2337,7 +2335,7 @@ describe("CLIEngine", () => { }); // create a new spy - spy = sandbox.spy(fs, "readFileSync"); + spy = sinon.spy(fs, "readFileSync"); const cachedResult = engine.executeOnFiles([file]); @@ -3463,15 +3461,12 @@ describe("CLIEngine", () => { }); describe("isPathIgnored", () => { - let sandbox; - beforeEach(() => { - sandbox = sinon.sandbox.create(); - sandbox.stub(console, "info").returns(void 0); + sinon.stub(console, "info").returns(void 0); }); afterEach(() => { - sandbox.restore(); + sinon.restore(); }); it("should check if the given path is ignored", () => { @@ -3730,11 +3725,8 @@ describe("CLIEngine", () => { }); describe("outputFixes()", () => { - - const sandbox = sinon.sandbox.create(); - afterEach(() => { - sandbox.verifyAndRestore(); + sinon.verifyAndRestore(); }); it("should call fs.writeFileSync() for each result with output", () => { @@ -3756,7 +3748,7 @@ describe("CLIEngine", () => { }; fakeFS.writeFileSync = function() {}; - const spy = sandbox.spy(fakeFS, "writeFileSync"); + const spy = sinon.spy(fakeFS, "writeFileSync"); localCLIEngine.outputFixes(report); @@ -3788,7 +3780,7 @@ describe("CLIEngine", () => { }; fakeFS.writeFileSync = function() {}; - const spy = sandbox.spy(fakeFS, "writeFileSync"); + const spy = sinon.spy(fakeFS, "writeFileSync"); localCLIEngine.outputFixes(report); diff --git a/tests/lib/cli-engine/formatters/codeframe.js b/tests/lib/cli-engine/formatters/codeframe.js index 0cdabe6c4fd..398d6b8c7af 100644 --- a/tests/lib/cli-engine/formatters/codeframe.js +++ b/tests/lib/cli-engine/formatters/codeframe.js @@ -42,14 +42,8 @@ const formatter = proxyquire("../../../../lib/cli-engine/formatters/codeframe", //------------------------------------------------------------------------------ describe("formatter:codeframe", () => { - let sandbox; - - beforeEach(() => { - sandbox = sinon.sandbox.create(); - }); - afterEach(() => { - sandbox.verifyAndRestore(); + sinon.verifyAndRestore(); }); describe("when passed no messages", () => { @@ -99,8 +93,8 @@ describe("formatter:codeframe", () => { }); it("should return bold yellow summary when there are only warnings", () => { - sandbox.spy(chalkStub.yellow, "bold"); - sandbox.spy(chalkStub.red, "bold"); + sinon.spy(chalkStub.yellow, "bold"); + sinon.spy(chalkStub.red, "bold"); formatter(code); @@ -160,8 +154,8 @@ describe("formatter:codeframe", () => { }); it("should return bold red summary when there are errors", () => { - sandbox.spy(chalkStub.yellow, "bold"); - sandbox.spy(chalkStub.red, "bold"); + sinon.spy(chalkStub.yellow, "bold"); + sinon.spy(chalkStub.red, "bold"); formatter(code); @@ -230,8 +224,8 @@ describe("formatter:codeframe", () => { }); it("should return bold red summary when at least 1 of the messages is an error", () => { - sandbox.spy(chalkStub.yellow, "bold"); - sandbox.spy(chalkStub.red, "bold"); + sinon.spy(chalkStub.yellow, "bold"); + sinon.spy(chalkStub.red, "bold"); code[0].messages[0].severity = 1; code[0].warningCount = 1; code[0].errorCount = 1; diff --git a/tests/lib/cli-engine/formatters/stylish.js b/tests/lib/cli-engine/formatters/stylish.js index dee58882fde..b336df54b18 100644 --- a/tests/lib/cli-engine/formatters/stylish.js +++ b/tests/lib/cli-engine/formatters/stylish.js @@ -43,18 +43,16 @@ const formatter = proxyquire("../../../../lib/cli-engine/formatters/stylish", { //------------------------------------------------------------------------------ describe("formatter:stylish", () => { - let sandbox; const colorsEnabled = chalk.enabled; beforeEach(() => { chalk.enabled = false; - sandbox = sinon.sandbox.create(); - sandbox.spy(chalkStub.yellow, "bold"); - sandbox.spy(chalkStub.red, "bold"); + sinon.spy(chalkStub.yellow, "bold"); + sinon.spy(chalkStub.red, "bold"); }); afterEach(() => { - sandbox.verifyAndRestore(); + sinon.verifyAndRestore(); chalk.enabled = colorsEnabled; }); diff --git a/tests/lib/cli-engine/lint-result-cache.js b/tests/lib/cli-engine/lint-result-cache.js index d1515f016ff..7c5cc20a1e6 100644 --- a/tests/lib/cli-engine/lint-result-cache.js +++ b/tests/lib/cli-engine/lint-result-cache.js @@ -26,15 +26,12 @@ describe("LintResultCache", () => { let LintResultCache, hashStub, - sandbox, fakeConfig, fakeErrorResults, fakeErrorResultsAutofix; before(() => { - sandbox = sinon.sandbox.create(); - - hashStub = sandbox.stub(); + hashStub = sinon.stub(); let shouldFix = false; @@ -61,7 +58,7 @@ describe("LintResultCache", () => { }); afterEach(done => { - sandbox.reset(); + sinon.reset(); fs.unlink(cacheFileLocation, err => { if (err && err.code !== "ENOENT") { @@ -93,7 +90,7 @@ describe("LintResultCache", () => { lintResultsCache; before(() => { - getFileDescriptorStub = sandbox.stub(); + getFileDescriptorStub = sinon.stub(); fileEntryCacheStubs.create = () => ({ getFileDescriptor: getFileDescriptorStub @@ -187,7 +184,7 @@ describe("LintResultCache", () => { lintResultsCache; before(() => { - getFileDescriptorStub = sandbox.stub(); + getFileDescriptorStub = sinon.stub(); fileEntryCacheStubs.create = () => ({ getFileDescriptor: getFileDescriptorStub @@ -285,7 +282,7 @@ describe("LintResultCache", () => { lintResultsCache; before(() => { - reconcileStub = sandbox.stub(); + reconcileStub = sinon.stub(); fileEntryCacheStubs.create = () => ({ reconcile: reconcileStub diff --git a/tests/lib/cli.js b/tests/lib/cli.js index 92a97a50a6d..0e24b143649 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -18,7 +18,6 @@ const assert = require("chai").assert, CLIEngine = require("../../lib/cli-engine/index").CLIEngine, path = require("path"), sinon = require("sinon"), - leche = require("leche"), fs = require("fs"), os = require("os"), sh = require("shelljs"); @@ -47,14 +46,13 @@ describe("cli", () => { * @returns {void} */ function verifyCLIEngineOpts(cmd, opts) { - const sandbox = sinon.sandbox.create(); // create a fake CLIEngine to test with - const fakeCLIEngine = sandbox.mock().withExactArgs(sinon.match(opts)); + const fakeCLIEngine = sinon.mock().withExactArgs(sinon.match(opts)); - fakeCLIEngine.prototype = leche.fake(CLIEngine.prototype); - sandbox.stub(fakeCLIEngine.prototype, "executeOnFiles").returns({}); - sandbox.stub(fakeCLIEngine.prototype, "getFormatter").returns(sinon.spy()); + Object.defineProperties(fakeCLIEngine.prototype, Object.getOwnPropertyDescriptors(CLIEngine.prototype)); + sinon.stub(fakeCLIEngine.prototype, "executeOnFiles").returns({}); + sinon.stub(fakeCLIEngine.prototype, "getFormatter").returns(sinon.spy()); const localCLI = proxyquire("../../lib/cli", { "./cli-engine/index": { CLIEngine: fakeCLIEngine }, @@ -62,7 +60,7 @@ describe("cli", () => { }); localCLI.execute(cmd); - sandbox.verifyAndRestore(); + sinon.verifyAndRestore(); } // verifyCLIEngineOpts @@ -84,8 +82,8 @@ describe("cli", () => { }); afterEach(() => { - log.info.reset(); - log.error.reset(); + log.info.resetHistory(); + log.error.resetHistory(); }); after(() => { @@ -315,7 +313,7 @@ describe("cli", () => { assert.isTrue(log.info.called, "Log should have been called."); - log.info.reset(); + log.info.resetHistory(); cli.execute(`--no-ignore --rule semi:2 ${passingPath}`); assert.isTrue(log.info.notCalled); @@ -703,21 +701,19 @@ describe("cli", () => { }); describe("when passed --no-inline-config", () => { - - const sandbox = sinon.sandbox.create(); let localCLI; afterEach(() => { - sandbox.verifyAndRestore(); + sinon.verifyAndRestore(); }); it("should pass allowInlineConfig:true to CLIEngine when --no-inline-config is used", () => { // create a fake CLIEngine to test with - const fakeCLIEngine = sandbox.mock().withExactArgs(sinon.match({ allowInlineConfig: false })); + const fakeCLIEngine = sinon.mock().withExactArgs(sinon.match({ allowInlineConfig: false })); - fakeCLIEngine.prototype = leche.fake(CLIEngine.prototype); - sandbox.stub(fakeCLIEngine.prototype, "executeOnFiles").returns({ + Object.defineProperties(fakeCLIEngine.prototype, Object.getOwnPropertyDescriptors(CLIEngine.prototype)); + sinon.stub(fakeCLIEngine.prototype, "executeOnFiles").returns({ errorCount: 1, warningCount: 0, results: [{ @@ -731,8 +727,8 @@ describe("cli", () => { ] }] }); - sandbox.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); - fakeCLIEngine.outputFixes = sandbox.stub(); + sinon.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); + fakeCLIEngine.outputFixes = sinon.stub(); localCLI = proxyquire("../../lib/cli", { "./cli-engine/index": { CLIEngine: fakeCLIEngine }, @@ -745,17 +741,17 @@ describe("cli", () => { it("should not error and allowInlineConfig should be true by default", () => { // create a fake CLIEngine to test with - const fakeCLIEngine = sandbox.mock().withExactArgs(sinon.match({ allowInlineConfig: true })); + const fakeCLIEngine = sinon.mock().withExactArgs(sinon.match({ allowInlineConfig: true })); - fakeCLIEngine.prototype = leche.fake(CLIEngine.prototype); - sandbox.stub(fakeCLIEngine.prototype, "executeOnFiles").returns({ + Object.defineProperties(fakeCLIEngine.prototype, Object.getOwnPropertyDescriptors(CLIEngine.prototype)); + sinon.stub(fakeCLIEngine.prototype, "executeOnFiles").returns({ errorCount: 0, warningCount: 0, results: [] }); - sandbox.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); - sandbox.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); - fakeCLIEngine.outputFixes = sandbox.stub(); + sinon.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); + sinon.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); + fakeCLIEngine.outputFixes = sinon.stub(); localCLI = proxyquire("../../lib/cli", { "./cli-engine/index": { CLIEngine: fakeCLIEngine }, @@ -771,28 +767,26 @@ describe("cli", () => { }); describe("when passed --fix", () => { - - const sandbox = sinon.sandbox.create(); let localCLI; afterEach(() => { - sandbox.verifyAndRestore(); + sinon.verifyAndRestore(); }); it("should pass fix:true to CLIEngine when executing on files", () => { // create a fake CLIEngine to test with - const fakeCLIEngine = sandbox.mock().withExactArgs(sinon.match({ fix: true })); + const fakeCLIEngine = sinon.mock().withExactArgs(sinon.match({ fix: true })); - fakeCLIEngine.prototype = leche.fake(CLIEngine.prototype); - sandbox.stub(fakeCLIEngine.prototype, "executeOnFiles").returns({ + Object.defineProperties(fakeCLIEngine.prototype, Object.getOwnPropertyDescriptors(CLIEngine.prototype)); + sinon.stub(fakeCLIEngine.prototype, "executeOnFiles").returns({ errorCount: 0, warningCount: 0, results: [] }); - sandbox.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); - sandbox.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); - fakeCLIEngine.outputFixes = sandbox.mock().once(); + sinon.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); + sinon.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); + fakeCLIEngine.outputFixes = sinon.mock().once(); localCLI = proxyquire("../../lib/cli", { "./cli-engine/index": { CLIEngine: fakeCLIEngine }, @@ -824,13 +818,13 @@ describe("cli", () => { }; // create a fake CLIEngine to test with - const fakeCLIEngine = sandbox.mock().withExactArgs(sinon.match({ fix: true })); + const fakeCLIEngine = sinon.mock().withExactArgs(sinon.match({ fix: true })); - fakeCLIEngine.prototype = leche.fake(CLIEngine.prototype); - sandbox.stub(fakeCLIEngine.prototype, "executeOnFiles").returns(report); - sandbox.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); - sandbox.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); - fakeCLIEngine.outputFixes = sandbox.mock().withExactArgs(report); + Object.defineProperties(fakeCLIEngine.prototype, Object.getOwnPropertyDescriptors(CLIEngine.prototype)); + sinon.stub(fakeCLIEngine.prototype, "executeOnFiles").returns(report); + sinon.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); + sinon.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); + fakeCLIEngine.outputFixes = sinon.mock().withExactArgs(report); localCLI = proxyquire("../../lib/cli", { "./cli-engine/index": { CLIEngine: fakeCLIEngine }, @@ -861,14 +855,14 @@ describe("cli", () => { }; // create a fake CLIEngine to test with - const fakeCLIEngine = sandbox.mock().withExactArgs(sinon.match({ fix: sinon.match.func })); + const fakeCLIEngine = sinon.mock().withExactArgs(sinon.match({ fix: sinon.match.func })); - fakeCLIEngine.prototype = leche.fake(CLIEngine.prototype); - sandbox.stub(fakeCLIEngine.prototype, "executeOnFiles").returns(report); - sandbox.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); - sandbox.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); - fakeCLIEngine.getErrorResults = sandbox.stub().returns([]); - fakeCLIEngine.outputFixes = sandbox.mock().withExactArgs(report); + Object.defineProperties(fakeCLIEngine.prototype, Object.getOwnPropertyDescriptors(CLIEngine.prototype)); + sinon.stub(fakeCLIEngine.prototype, "executeOnFiles").returns(report); + sinon.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); + sinon.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); + fakeCLIEngine.getErrorResults = sinon.stub().returns([]); + fakeCLIEngine.outputFixes = sinon.mock().withExactArgs(report); localCLI = proxyquire("../../lib/cli", { "./cli-engine/index": { CLIEngine: fakeCLIEngine }, @@ -884,7 +878,7 @@ describe("cli", () => { it("should not call CLIEngine and return 1 when executing on text", () => { // create a fake CLIEngine to test with - const fakeCLIEngine = sandbox.mock().never(); + const fakeCLIEngine = sinon.mock().never(); localCLI = proxyquire("../../lib/cli", { "./cli-engine/index": { CLIEngine: fakeCLIEngine }, @@ -899,27 +893,26 @@ describe("cli", () => { }); describe("when passed --fix-dry-run", () => { - const sandbox = sinon.sandbox.create(); let localCLI; afterEach(() => { - sandbox.verifyAndRestore(); + sinon.verifyAndRestore(); }); it("should pass fix:true to CLIEngine when executing on files", () => { // create a fake CLIEngine to test with - const fakeCLIEngine = sandbox.mock().withExactArgs(sinon.match({ fix: true })); + const fakeCLIEngine = sinon.mock().withExactArgs(sinon.match({ fix: true })); - fakeCLIEngine.prototype = leche.fake(CLIEngine.prototype); - sandbox.stub(fakeCLIEngine.prototype, "executeOnFiles").returns({ + Object.defineProperties(fakeCLIEngine.prototype, Object.getOwnPropertyDescriptors(CLIEngine.prototype)); + sinon.stub(fakeCLIEngine.prototype, "executeOnFiles").returns({ errorCount: 0, warningCount: 0, results: [] }); - sandbox.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); - sandbox.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); - fakeCLIEngine.outputFixes = sandbox.mock().never(); + sinon.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); + sinon.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); + fakeCLIEngine.outputFixes = sinon.mock().never(); localCLI = proxyquire("../../lib/cli", { "./cli-engine/index": { CLIEngine: fakeCLIEngine }, @@ -940,17 +933,17 @@ describe("cli", () => { }; // create a fake CLIEngine to test with - const fakeCLIEngine = sandbox.mock().withExactArgs(sinon.match(expectedCLIEngineOptions)); + const fakeCLIEngine = sinon.mock().withExactArgs(sinon.match(expectedCLIEngineOptions)); - fakeCLIEngine.prototype = leche.fake(CLIEngine.prototype); - sandbox.stub(fakeCLIEngine.prototype, "executeOnFiles").returns({ + Object.defineProperties(fakeCLIEngine.prototype, Object.getOwnPropertyDescriptors(CLIEngine.prototype)); + sinon.stub(fakeCLIEngine.prototype, "executeOnFiles").returns({ errorCount: 0, warningCount: 0, results: [] }); - sandbox.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); - sandbox.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); - fakeCLIEngine.outputFixes = sandbox.stub(); + sinon.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); + sinon.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); + fakeCLIEngine.outputFixes = sinon.stub(); localCLI = proxyquire("../../lib/cli", { "./cli-engine/index": { CLIEngine: fakeCLIEngine }, @@ -980,13 +973,13 @@ describe("cli", () => { }; // create a fake CLIEngine to test with - const fakeCLIEngine = sandbox.mock().withExactArgs(sinon.match({ fix: true })); + const fakeCLIEngine = sinon.mock().withExactArgs(sinon.match({ fix: true })); - fakeCLIEngine.prototype = leche.fake(CLIEngine.prototype); - sandbox.stub(fakeCLIEngine.prototype, "executeOnFiles").returns(report); - sandbox.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); - sandbox.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); - fakeCLIEngine.outputFixes = sandbox.mock().never(); + Object.defineProperties(fakeCLIEngine.prototype, Object.getOwnPropertyDescriptors(CLIEngine.prototype)); + sinon.stub(fakeCLIEngine.prototype, "executeOnFiles").returns(report); + sinon.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); + sinon.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); + fakeCLIEngine.outputFixes = sinon.mock().never(); localCLI = proxyquire("../../lib/cli", { "./cli-engine/index": { CLIEngine: fakeCLIEngine }, @@ -1017,14 +1010,14 @@ describe("cli", () => { }; // create a fake CLIEngine to test with - const fakeCLIEngine = sandbox.mock().withExactArgs(sinon.match({ fix: sinon.match.func })); + const fakeCLIEngine = sinon.mock().withExactArgs(sinon.match({ fix: sinon.match.func })); - fakeCLIEngine.prototype = leche.fake(CLIEngine.prototype); - sandbox.stub(fakeCLIEngine.prototype, "executeOnFiles").returns(report); - sandbox.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); - sandbox.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); - fakeCLIEngine.getErrorResults = sandbox.stub().returns([]); - fakeCLIEngine.outputFixes = sandbox.mock().never(); + Object.defineProperties(fakeCLIEngine.prototype, Object.getOwnPropertyDescriptors(CLIEngine.prototype)); + sinon.stub(fakeCLIEngine.prototype, "executeOnFiles").returns(report); + sinon.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); + sinon.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); + fakeCLIEngine.getErrorResults = sinon.stub().returns([]); + fakeCLIEngine.outputFixes = sinon.mock().never(); localCLI = proxyquire("../../lib/cli", { "./cli-engine/index": { CLIEngine: fakeCLIEngine }, @@ -1055,13 +1048,13 @@ describe("cli", () => { }; // create a fake CLIEngine to test with - const fakeCLIEngine = sandbox.mock().withExactArgs(sinon.match({ fix: true })); + const fakeCLIEngine = sinon.mock().withExactArgs(sinon.match({ fix: true })); - fakeCLIEngine.prototype = leche.fake(CLIEngine.prototype); - sandbox.stub(fakeCLIEngine.prototype, "executeOnText").returns(report); - sandbox.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); - sandbox.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); - fakeCLIEngine.outputFixes = sandbox.mock().never(); + Object.defineProperties(fakeCLIEngine.prototype, Object.getOwnPropertyDescriptors(CLIEngine.prototype)); + sinon.stub(fakeCLIEngine.prototype, "executeOnText").returns(report); + sinon.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); + sinon.stub(fakeCLIEngine.prototype, "getRules").returns(new Map()); + fakeCLIEngine.outputFixes = sinon.mock().never(); localCLI = proxyquire("../../lib/cli", { "./cli-engine/index": { CLIEngine: fakeCLIEngine }, @@ -1076,7 +1069,7 @@ describe("cli", () => { it("should not call CLIEngine and return 1 when used with --fix", () => { // create a fake CLIEngine to test with - const fakeCLIEngine = sandbox.mock().never(); + const fakeCLIEngine = sinon.mock().never(); localCLI = proxyquire("../../lib/cli", { "./cli-engine/index": { CLIEngine: fakeCLIEngine }, diff --git a/tests/lib/init/config-file.js b/tests/lib/init/config-file.js index c90a038f801..45cca55f933 100644 --- a/tests/lib/init/config-file.js +++ b/tests/lib/init/config-file.js @@ -40,12 +40,9 @@ function getFixturePath(filepath) { describe("ConfigFile", () => { describe("write()", () => { - - let sandbox, - config; + let config; beforeEach(() => { - sandbox = sinon.sandbox.create(); config = { env: { browser: true, @@ -59,7 +56,7 @@ describe("ConfigFile", () => { }); afterEach(() => { - sandbox.verifyAndRestore(); + sinon.verifyAndRestore(); }); leche.withData([ @@ -72,7 +69,7 @@ describe("ConfigFile", () => { it(`should write a file through fs when a ${fileType} path is passed`, () => { const fakeFS = leche.fake(fs); - sandbox.mock(fakeFS).expects("writeFileSync").withExactArgs( + sinon.mock(fakeFS).expects("writeFileSync").withExactArgs( filename, sinon.match(value => !!validate(value)), "utf8" @@ -96,7 +93,7 @@ describe("ConfigFile", () => { } }; - sandbox.mock(fakeFS).expects("writeFileSync").withExactArgs( + sinon.mock(fakeFS).expects("writeFileSync").withExactArgs( "test-config.js", sinon.match(value => !value.includes("\"")), "utf8" @@ -111,16 +108,16 @@ describe("ConfigFile", () => { it("should still write a js config file even if linting fails", () => { const fakeFS = leche.fake(fs); - const fakeCLIEngine = sandbox.mock().withExactArgs(sinon.match({ + const fakeCLIEngine = sinon.mock().withExactArgs(sinon.match({ baseConfig: config, fix: true, useEslintrc: false })); - fakeCLIEngine.prototype = leche.fake(CLIEngine.prototype); - sandbox.stub(fakeCLIEngine.prototype, "executeOnText").throws(); + Object.defineProperties(fakeCLIEngine.prototype, Object.getOwnPropertyDescriptors(CLIEngine.prototype)); + sinon.stub(fakeCLIEngine.prototype, "executeOnText").throws(); - sandbox.mock(fakeFS).expects("writeFileSync").once(); + sinon.mock(fakeFS).expects("writeFileSync").once(); const StubbedConfigFile = proxyquire("../../../lib/init/config-file", { fs: fakeFS, diff --git a/tests/lib/init/config-initializer.js b/tests/lib/init/config-initializer.js index 9697d826670..68cd06e1d1a 100644 --- a/tests/lib/init/config-initializer.js +++ b/tests/lib/init/config-initializer.js @@ -96,8 +96,8 @@ describe("configInitializer", () => { }); afterEach(() => { - log.info.reset(); - log.error.reset(); + log.info.resetHistory(); + log.error.resetHistory(); npmInstallStub.restore(); npmCheckStub.restore(); npmFetchPeerDependenciesStub.restore(); @@ -311,7 +311,6 @@ describe("configInitializer", () => { describe("auto", () => { const completeSpy = sinon.spy(); let config; - let sandbox; before(() => { const patterns = [ @@ -327,21 +326,20 @@ describe("configInitializer", () => { format: "JSON" }; - sandbox = sinon.sandbox.create(); - sandbox.stub(console, "log"); // necessary to replace, because of progress bar + sinon.stub(console, "log"); // necessary to replace, because of progress bar process.chdir(fixtureDir); config = init.processAnswers(answers); - sandbox.restore(); + sinon.restore(); }); after(() => { - sandbox.restore(); + sinon.restore(); }); afterEach(() => { process.chdir(originalDir); - sandbox.restore(); + sinon.restore(); }); it("should create a config", () => { @@ -371,7 +369,7 @@ describe("configInitializer", () => { it("should throw on fatal parsing error", () => { const filename = getFixturePath("parse-error"); - sandbox.stub(autoconfig, "extendFromRecommended"); + sinon.stub(autoconfig, "extendFromRecommended"); answers.patterns = filename; process.chdir(fixtureDir); assert.throws(() => { @@ -380,7 +378,7 @@ describe("configInitializer", () => { }); it("should throw if no files are matched from patterns", () => { - sandbox.stub(autoconfig, "extendFromRecommended"); + sinon.stub(autoconfig, "extendFromRecommended"); answers.patterns = "not-a-real-filename"; process.chdir(fixtureDir); assert.throws(() => { diff --git a/tests/lib/init/npm-utils.js b/tests/lib/init/npm-utils.js index ed8dbfe6bbb..d0326bd1330 100644 --- a/tests/lib/init/npm-utils.js +++ b/tests/lib/init/npm-utils.js @@ -38,15 +38,8 @@ function requireNpmUtilsWithInMemoryFileSystem(files) { //------------------------------------------------------------------------------ describe("npmUtils", () => { - - let sandbox; - - beforeEach(() => { - sandbox = sinon.sandbox.create(); - }); - afterEach(() => { - sandbox.verifyAndRestore(); + sinon.verifyAndRestore(); }); describe("checkDevDeps()", () => { @@ -179,7 +172,7 @@ describe("npmUtils", () => { describe("installSyncSaveDev()", () => { it("should invoke npm to install a single desired package", () => { - const stub = sandbox.stub(spawn, "sync").returns({ stdout: "" }); + const stub = sinon.stub(spawn, "sync").returns({ stdout: "" }); npmUtils.installSyncSaveDev("desired-package"); assert(stub.calledOnce); @@ -189,7 +182,7 @@ describe("npmUtils", () => { }); it("should accept an array of packages to install", () => { - const stub = sandbox.stub(spawn, "sync").returns({ stdout: "" }); + const stub = sinon.stub(spawn, "sync").returns({ stdout: "" }); npmUtils.installSyncSaveDev(["first-package", "second-package"]); assert(stub.calledOnce); @@ -199,8 +192,8 @@ describe("npmUtils", () => { }); it("should log an error message if npm throws ENOENT error", () => { - const logErrorStub = sandbox.stub(log, "error"); - const npmUtilsStub = sandbox.stub(spawn, "sync").returns({ error: { code: "ENOENT" } }); + const logErrorStub = sinon.stub(log, "error"); + const npmUtilsStub = sinon.stub(spawn, "sync").returns({ error: { code: "ENOENT" } }); npmUtils.installSyncSaveDev("some-package"); @@ -213,7 +206,7 @@ describe("npmUtils", () => { describe("fetchPeerDependencies()", () => { it("should execute 'npm show --json peerDependencies' command", () => { - const stub = sandbox.stub(spawn, "sync").returns({ stdout: "" }); + const stub = sinon.stub(spawn, "sync").returns({ stdout: "" }); npmUtils.fetchPeerDependencies("desired-package"); assert(stub.calledOnce); @@ -223,7 +216,7 @@ describe("npmUtils", () => { }); it("should return null if npm throws ENOENT error", () => { - const stub = sandbox.stub(spawn, "sync").returns({ error: { code: "ENOENT" } }); + const stub = sinon.stub(spawn, "sync").returns({ error: { code: "ENOENT" } }); const peerDependencies = npmUtils.fetchPeerDependencies("desired-package"); diff --git a/tests/lib/init/source-code-utils.js b/tests/lib/init/source-code-utils.js index 1b4a036b564..a5c9e90a1b2 100644 --- a/tests/lib/init/source-code-utils.js +++ b/tests/lib/init/source-code-utils.js @@ -66,8 +66,8 @@ describe("SourceCodeUtil", () => { }); afterEach(() => { - log.info.reset(); - log.error.reset(); + log.info.resetHistory(); + log.error.resetHistory(); }); after(() => { diff --git a/tests/lib/linter/linter.js b/tests/lib/linter/linter.js index a7cb13ec690..da052b339a7 100644 --- a/tests/lib/linter/linter.js +++ b/tests/lib/linter/linter.js @@ -73,18 +73,16 @@ const ESLINT_ENV = "eslint-env"; describe("Linter", () => { const filename = "filename.js"; - let sandbox; /** @type {InstanceType} */ let linter; beforeEach(() => { linter = new Linter(); - sandbox = sinon.sandbox.create(); }); afterEach(() => { - sandbox.verifyAndRestore(); + sinon.verifyAndRestore(); }); describe("Static Members", () => { @@ -113,7 +111,7 @@ describe("Linter", () => { }); it("does not call rule listeners with a `this` value", () => { - const spy = sandbox.spy(); + const spy = sinon.spy(); linter.defineRule("checker", () => ({ Program: spy })); linter.verify("foo", { rules: { checker: "error" } }); @@ -122,7 +120,7 @@ describe("Linter", () => { }); it("does not allow listeners to use special EventEmitter values", () => { - const spy = sandbox.spy(); + const spy = sinon.spy(); linter.defineRule("checker", () => ({ newListener: spy })); linter.verify("foo", { rules: { checker: "error", "no-undef": "error" } }); @@ -130,7 +128,7 @@ describe("Linter", () => { }); it("has all the `parent` properties on nodes when the rule listeners are created", () => { - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { const ast = context.getSourceCode().ast; assert.strictEqual(ast.body[0].parent, ast); @@ -152,7 +150,7 @@ describe("Linter", () => { it("should get proper lines when using \\n as a line break", () => { const code = "a;\nb;"; - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { assert.deepStrictEqual(context.getSourceLines(), ["a;", "b;"]); return {}; }); @@ -164,7 +162,7 @@ describe("Linter", () => { it("should get proper lines when using \\r\\n as a line break", () => { const code = "a;\r\nb;"; - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { assert.deepStrictEqual(context.getSourceLines(), ["a;", "b;"]); return {}; }); @@ -176,7 +174,7 @@ describe("Linter", () => { it("should get proper lines when using \\r as a line break", () => { const code = "a;\rb;"; - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { assert.deepStrictEqual(context.getSourceLines(), ["a;", "b;"]); return {}; }); @@ -188,7 +186,7 @@ describe("Linter", () => { it("should get proper lines when using \\u2028 as a line break", () => { const code = "a;\u2028b;"; - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { assert.deepStrictEqual(context.getSourceLines(), ["a;", "b;"]); return {}; }); @@ -200,7 +198,7 @@ describe("Linter", () => { it("should get proper lines when using \\u2029 as a line break", () => { const code = "a;\u2029b;"; - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { assert.deepStrictEqual(context.getSourceLines(), ["a;", "b;"]); return {}; }); @@ -247,7 +245,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { assert.strictEqual(context.getSource(), TEST_CODE); }); return { Program: spy }; @@ -262,7 +260,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(node => { + spy = sinon.spy(node => { assert.strictEqual(context.getSource(node), TEST_CODE); }); return { Program: spy }; @@ -277,7 +275,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(node => { + spy = sinon.spy(node => { assert.strictEqual(context.getSource(node, 2, 0), TEST_CODE); }); return { Program: spy }; @@ -292,7 +290,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(node => { + spy = sinon.spy(node => { assert.strictEqual(context.getSource(node), "6 * 7"); }); return { BinaryExpression: spy }; @@ -307,7 +305,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(node => { + spy = sinon.spy(node => { assert.strictEqual(context.getSource(node, 2), "= 6 * 7"); }); return { BinaryExpression: spy }; @@ -322,7 +320,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(node => { + spy = sinon.spy(node => { assert.strictEqual(context.getSource(node, 0, 1), "6 * 7;"); }); return { BinaryExpression: spy }; @@ -337,7 +335,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(node => { + spy = sinon.spy(node => { assert.strictEqual(context.getSource(node, 2, 1), "= 6 * 7;"); }); return { BinaryExpression: spy }; @@ -358,7 +356,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const ancestors = context.getAncestors(); assert.strictEqual(ancestors.length, 3); @@ -375,7 +373,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const ancestors = context.getAncestors(); assert.strictEqual(ancestors.length, 0); @@ -394,7 +392,7 @@ describe("Linter", () => { it("should retrieve a node starting at the given index", () => { const config = { rules: { checker: "error" } }; - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { assert.strictEqual(context.getNodeByRangeIndex(4).type, "Identifier"); return {}; }); @@ -406,7 +404,7 @@ describe("Linter", () => { it("should retrieve a node containing the given index", () => { const config = { rules: { checker: "error" } }; - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { assert.strictEqual(context.getNodeByRangeIndex(6).type, "Identifier"); return {}; }); @@ -418,7 +416,7 @@ describe("Linter", () => { it("should retrieve a node that is exactly the given index", () => { const config = { rules: { checker: "error" } }; - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { const node = context.getNodeByRangeIndex(13); assert.strictEqual(node.type, "Literal"); @@ -433,7 +431,7 @@ describe("Linter", () => { it("should retrieve a node ending with the given index", () => { const config = { rules: { checker: "error" } }; - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { assert.strictEqual(context.getNodeByRangeIndex(9).type, "Identifier"); return {}; }); @@ -445,7 +443,7 @@ describe("Linter", () => { it("should retrieve the deepest node containing the given index", () => { const config = { rules: { checker: "error" } }; - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { const node1 = context.getNodeByRangeIndex(14); assert.strictEqual(node1.type, "BinaryExpression"); @@ -463,7 +461,7 @@ describe("Linter", () => { it("should return null if the index is outside the range of any node", () => { const config = { rules: { checker: "error" } }; - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { const node1 = context.getNodeByRangeIndex(-1); assert.isNull(node1); @@ -489,7 +487,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(scope.type, "global"); @@ -506,7 +504,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(scope.type, "function"); @@ -523,7 +521,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(scope.type, "function"); @@ -541,7 +539,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(scope.type, "function"); @@ -560,7 +558,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(scope.type, "switch"); @@ -579,7 +577,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(scope.type, "block"); @@ -598,7 +596,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(scope.type, "block"); @@ -617,7 +615,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(scope.type, "function"); @@ -636,7 +634,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(scope.type, "function"); @@ -655,7 +653,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(scope.type, "catch"); @@ -674,7 +672,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(scope.type, "module"); @@ -692,7 +690,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(scope.type, "function"); @@ -712,7 +710,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { assert.isTrue(context.markVariableAsUsed("a")); const scope = context.getScope(); @@ -732,7 +730,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { assert.isTrue(context.markVariableAsUsed("a")); const scope = context.getScope(); @@ -752,10 +750,10 @@ describe("Linter", () => { let returnSpy, exitSpy; linter.defineRule("checker", context => { - returnSpy = sandbox.spy(() => { + returnSpy = sinon.spy(() => { assert.isTrue(context.markVariableAsUsed("a")); }); - exitSpy = sandbox.spy(() => { + exitSpy = sinon.spy(() => { const scope = context.getScope(); assert.isTrue(getVariable(scope, "a").eslintUsed); @@ -775,7 +773,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const globalScope = context.getScope(), childScope = globalScope.childScopes[0]; @@ -797,7 +795,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const globalScope = context.getScope(), childScope = globalScope.childScopes[0]; @@ -819,7 +817,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { assert.isFalse(context.markVariableAsUsed("c")); }); @@ -927,7 +925,7 @@ describe("Linter", () => { } }; - linter.defineRule("test-rule", sandbox.mock().withArgs( + linter.defineRule("test-rule", sinon.mock().withArgs( sinon.match({ parserOptions }) ).returns({})); @@ -940,7 +938,7 @@ describe("Linter", () => { const parserOptions = {}; - linter.defineRule("test-rule", sandbox.mock().withArgs( + linter.defineRule("test-rule", sinon.mock().withArgs( sinon.match({ parserOptions }) ).returns({})); @@ -985,7 +983,7 @@ describe("Linter", () => { const alternateParser = "esprima"; linter.defineParser("esprima", esprima); - linter.defineRule("test-rule", sandbox.mock().withArgs( + linter.defineRule("test-rule", sinon.mock().withArgs( sinon.match({ parserPath: alternateParser }) ).returns({})); @@ -1045,7 +1043,7 @@ describe("Linter", () => { }); it("should pass parser as parserPath to all rules when default parser is used", () => { - linter.defineRule("test-rule", sandbox.mock().withArgs( + linter.defineRule("test-rule", sinon.mock().withArgs( sinon.match({ parserPath: "espree" }) ).returns({})); @@ -1142,7 +1140,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); const a = getVariable(scope, "a"), b = getVariable(scope, "b"), @@ -1188,7 +1186,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(), a = getVariable(scope, "a"), b = getVariable(scope, "b"), @@ -1217,7 +1215,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(), exports = getVariable(scope, "exports"), window = getVariable(scope, "window"); @@ -1242,7 +1240,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(), exports = getVariable(scope, "exports"), window = getVariable(scope, "window"); @@ -1274,7 +1272,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(), horse = getVariable(scope, "horse"); @@ -1294,7 +1292,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(), horse = getVariable(scope, "horse"); @@ -1314,7 +1312,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(), horse = getVariable(scope, "horse"); @@ -1334,7 +1332,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(), horse = getVariable(scope, "horse"); @@ -1354,7 +1352,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(), horse = getVariable(scope, "horse"); @@ -1377,7 +1375,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(getVariable(scope, "a"), null); @@ -1399,7 +1397,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(getVariable(scope, "a"), null); @@ -1424,7 +1422,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.notStrictEqual(getVariable(scope, "Object"), null); @@ -1444,7 +1442,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(getVariable(scope, "Promise"), null); @@ -1464,7 +1462,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.notStrictEqual(getVariable(scope, "Promise"), null); @@ -1484,7 +1482,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(() => { + spy = sinon.spy(() => { const scope = context.getScope(); assert.strictEqual(getVariable(scope, "Promise"), null); @@ -2752,7 +2750,7 @@ describe("Linter", () => { it("should have a comment with the shebang in it", () => { const config = { rules: { checker: "error" } }; - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { const comments = context.getAllComments(); assert.strictEqual(comments.length, 1); @@ -3205,7 +3203,7 @@ describe("Linter", () => { let spy; linter.defineRule("checker", context => { - spy = sandbox.spy(node => { + spy = sinon.spy(node => { assert.strictEqual(context.getSource(node), "'123';"); }); return { ExpressionStatement: spy }; @@ -3219,7 +3217,7 @@ describe("Linter", () => { describe("verify()", () => { describe("filenames", () => { it("should allow filename to be passed on options object", () => { - const filenameChecker = sandbox.spy(context => { + const filenameChecker = sinon.spy(context => { assert.strictEqual(context.getFilename(), "foo.js"); return {}; }); @@ -3231,7 +3229,7 @@ describe("Linter", () => { }); it("should allow filename to be passed as third argument", () => { - const filenameChecker = sandbox.spy(context => { + const filenameChecker = sinon.spy(context => { assert.strictEqual(context.getFilename(), "bar.js"); return {}; }); @@ -3242,7 +3240,7 @@ describe("Linter", () => { }); it("should default filename to when options object doesn't have filename", () => { - const filenameChecker = sandbox.spy(context => { + const filenameChecker = sinon.spy(context => { assert.strictEqual(context.getFilename(), ""); return {}; }); @@ -3253,7 +3251,7 @@ describe("Linter", () => { }); it("should default filename to when only two arguments are passed", () => { - const filenameChecker = sandbox.spy(context => { + const filenameChecker = sinon.spy(context => { assert.strictEqual(context.getFilename(), ""); return {}; }); @@ -3615,7 +3613,7 @@ describe("Linter", () => { }); it("should pass 'id' to rule contexts with the rule id", () => { - const spy = sandbox.spy(context => { + const spy = sinon.spy(context => { assert.strictEqual(context.id, "foo-bar-baz"); return {}; }); diff --git a/tests/lib/source-code/source-code.js b/tests/lib/source-code/source-code.js index aee0ab29305..57cc960d2f9 100644 --- a/tests/lib/source-code/source-code.js +++ b/tests/lib/source-code/source-code.js @@ -228,11 +228,8 @@ describe("SourceCode", () => { describe("getJSDocComment()", () => { - - const sandbox = sinon.sandbox.create(); - afterEach(() => { - sandbox.verifyAndRestore(); + sinon.verifyAndRestore(); }); it("should not take a JSDoc comment from a FunctionDeclaration parent node when the node is a FunctionExpression", () => { @@ -255,7 +252,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc, null); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionExpression: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -283,7 +280,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc, null); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionExpression: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -313,7 +310,7 @@ describe("SourceCode", () => { } } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionExpression: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -345,7 +342,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc.value, "* Documentation. "); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionExpression: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -373,7 +370,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc.value, "* Desc"); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionDeclaration: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -402,7 +399,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc.value, "* Desc"); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionDeclaration: spy })); linter.verify(code, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6, sourceType: "module" } }); @@ -433,7 +430,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc.value, "* Desc"); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionDeclaration: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -464,7 +461,7 @@ describe("SourceCode", () => { assert.isNull(jsdoc); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionDeclaration: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -494,7 +491,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc.value, "* Desc"); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionDeclaration: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -526,7 +523,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc.value, "* Desc"); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionDeclaration: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -557,7 +554,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc.value, "* Desc"); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionExpression: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -588,7 +585,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc.value, "* Desc"); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ ArrowFunctionExpression: spy })); linter.verify(code, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); @@ -617,7 +614,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc.value, "* Desc"); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionExpression: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -650,7 +647,7 @@ describe("SourceCode", () => { } } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionExpression: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -682,7 +679,7 @@ describe("SourceCode", () => { } } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionExpression: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -712,7 +709,7 @@ describe("SourceCode", () => { } } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionExpression: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -750,7 +747,7 @@ describe("SourceCode", () => { } } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionExpression: spy })); linter.verify(code, { rules: { checker: "error" } }); @@ -779,7 +776,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc.value, "* Merges two objects together."); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ ClassExpression: spy })); linter.verify(code, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); @@ -808,7 +805,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc.value, "* Merges two objects together."); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ ClassDeclaration: spy })); linter.verify(code, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); @@ -837,7 +834,7 @@ describe("SourceCode", () => { assert.isNull(jsdoc); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionExpression: spy })); linter.verify(code, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); @@ -870,7 +867,7 @@ describe("SourceCode", () => { assert.strictEqual(jsdoc.value, "* Merges two objects together."); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionExpression: spy })); linter.verify(code, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); @@ -901,7 +898,7 @@ describe("SourceCode", () => { assert.isNull(jsdoc); } - const spy = sandbox.spy(assertJSDoc); + const spy = sinon.spy(assertJSDoc); linter.defineRule("checker", () => ({ FunctionDeclaration: spy })); linter.verify(code, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } });