diff --git a/package.json b/package.json index 0edaa58e0..60b53c3cd 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "nyc": "^8.3.0", "redux": "^3.0.4", "rimraf": "2.5.2", + "sinon": "^2.3.2", "typescript": "^2.0.3", "typescript-eslint-parser": "^2.1.0" }, diff --git a/tests/src/core/parse.js b/tests/src/core/parse.js index ab167b692..41c0d9a8c 100644 --- a/tests/src/core/parse.js +++ b/tests/src/core/parse.js @@ -1,8 +1,9 @@ import * as fs from 'fs' import { expect } from 'chai' +import sinon from 'sinon' import parse from 'eslint-module-utils/parse' -import { getFilename, makeNaiveSpy } from '../utils' +import { getFilename } from '../utils' describe('parse(content, { settings, ecmaFeatures })', function () { const path = getFilename('jsx.js') @@ -22,20 +23,20 @@ describe('parse(content, { settings, ecmaFeatures })', function () { }) it('passes expected parserOptions to custom parser', function () { - const parseSpy = makeNaiveSpy() + const parseSpy = sinon.spy() const parserOptions = { ecmaFeatures: { jsx: true } } require('./parseStubParser').parse = parseSpy parse(path, content, { settings: {}, parserPath: require.resolve('./parseStubParser'), parserOptions: parserOptions }) - expect(parseSpy.callCount).to.equal(1) - expect(parseSpy.lastCallArguments[0]).to.equal(content) - expect(parseSpy.lastCallArguments[1]).to.be.an('object') - expect(parseSpy.lastCallArguments[1]).to.not.equal(parserOptions) - expect(parseSpy.lastCallArguments[1]) + expect(parseSpy.callCount, 'parse to be called once').to.equal(1) + expect(parseSpy.args[0][0], 'parse to get content as its first argument').to.equal(content) + expect(parseSpy.args[0][1], 'parse to get an object as its second argument').to.be.an('object') + expect(parseSpy.args[0][1], 'parse to clone the parserOptions object').to.not.equal(parserOptions) + expect(parseSpy.args[0][1], 'parse to get ecmaFeatures in parserOptions which is a clone of ecmaFeatures passed in') .to.have.property('ecmaFeatures') .that.is.eql(parserOptions.ecmaFeatures) .and.is.not.equal(parserOptions.ecmaFeatures) - expect(parseSpy.lastCallArguments[1]).to.have.property('attachComment', true) - expect(parseSpy.lastCallArguments[1]).to.have.property('filePath', path) + expect(parseSpy.args[0][1], 'parse to get parserOptions.attachComment equal to true').to.have.property('attachComment', true) + expect(parseSpy.args[0][1], 'parse to get parserOptions.filePath equal to the full path of the source file').to.have.property('filePath', path) }) }) diff --git a/tests/src/utils.js b/tests/src/utils.js index 877855a94..144ae5498 100644 --- a/tests/src/utils.js +++ b/tests/src/utils.js @@ -28,20 +28,6 @@ export function getFilename(file) { return path.join(__dirname, '..', 'files', file || 'foo.js') } -/** - * naive implementation of a function spy - * for more robust spy, consider replacing with sinon or chai-spies - * @return {function} - */ -export function makeNaiveSpy() { - const spy = function () { - spy.callCount += 1 - spy.lastCallArguments = arguments - } - spy.callCount = 0 - return spy -} - /** * to be added as valid cases just to ensure no nullable fields are going * to crash at runtinme