Skip to content

Commit

Permalink
Upgrade: sinon (#11855)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jun 19, 2019
1 parent 167ce87 commit 41f6304
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 274 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
15 changes: 5 additions & 10 deletions tests/lib/cli-engine/cascading-config-array-factory.js
Expand Up @@ -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");

Expand All @@ -100,7 +99,7 @@ describe("CascadingConfigArrayFactory", () => {
* @private
*/
function mockOsHomedir(fakeUserHomePath) {
sandbox.stub(os, "homedir")
sinon.stub(os, "homedir")
.returns(fakeUserHomePath);
}

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

beforeEach(() => {
sandbox = sinon.sandbox.create();
});

afterEach(() => {
sandbox.verifyAndRestore();
sinon.verifyAndRestore();
});

after(() => {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
36 changes: 14 additions & 22 deletions tests/lib/cli-engine/cli-engine.js
Expand Up @@ -2100,7 +2100,6 @@ describe("CLIEngine", () => {
});

describe("cache", () => {
let sandbox;

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

beforeEach(() => {
deleteCache();
sandbox = sinon.sandbox.create();
});

afterEach(() => {
sandbox.restore();
sinon.restore();
deleteCache();
});

Expand Down Expand Up @@ -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();
});
});

Expand All @@ -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", () => {
Expand Down Expand Up @@ -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");

Expand All @@ -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,
Expand All @@ -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]);

Expand All @@ -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");

Expand All @@ -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,
Expand All @@ -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]);

Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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", () => {
Expand All @@ -3756,7 +3748,7 @@ describe("CLIEngine", () => {
};

fakeFS.writeFileSync = function() {};
const spy = sandbox.spy(fakeFS, "writeFileSync");
const spy = sinon.spy(fakeFS, "writeFileSync");

localCLIEngine.outputFixes(report);

Expand Down Expand Up @@ -3788,7 +3780,7 @@ describe("CLIEngine", () => {
};

fakeFS.writeFileSync = function() {};
const spy = sandbox.spy(fakeFS, "writeFileSync");
const spy = sinon.spy(fakeFS, "writeFileSync");

localCLIEngine.outputFixes(report);

Expand Down
20 changes: 7 additions & 13 deletions tests/lib/cli-engine/formatters/codeframe.js
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions tests/lib/cli-engine/formatters/stylish.js
Expand Up @@ -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;
});

Expand Down
13 changes: 5 additions & 8 deletions tests/lib/cli-engine/lint-result-cache.js
Expand Up @@ -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;

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

afterEach(done => {
sandbox.reset();
sinon.reset();

fs.unlink(cacheFileLocation, err => {
if (err && err.code !== "ENOENT") {
Expand Down Expand Up @@ -93,7 +90,7 @@ describe("LintResultCache", () => {
lintResultsCache;

before(() => {
getFileDescriptorStub = sandbox.stub();
getFileDescriptorStub = sinon.stub();

fileEntryCacheStubs.create = () => ({
getFileDescriptor: getFileDescriptorStub
Expand Down Expand Up @@ -187,7 +184,7 @@ describe("LintResultCache", () => {
lintResultsCache;

before(() => {
getFileDescriptorStub = sandbox.stub();
getFileDescriptorStub = sinon.stub();

fileEntryCacheStubs.create = () => ({
getFileDescriptor: getFileDescriptorStub
Expand Down Expand Up @@ -285,7 +282,7 @@ describe("LintResultCache", () => {
lintResultsCache;

before(() => {
reconcileStub = sandbox.stub();
reconcileStub = sinon.stub();

fileEntryCacheStubs.create = () => ({
reconcile: reconcileStub
Expand Down

0 comments on commit 41f6304

Please sign in to comment.