Skip to content

Commit

Permalink
eslint-module-utils: In tests move require stub parser to the top.
Browse files Browse the repository at this point in the history
  • Loading branch information
sompylasar committed May 29, 2017
1 parent d397b9b commit 5732742
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tests/src/core/parse.js
Expand Up @@ -7,6 +7,8 @@ import { getFilename } from '../utils'

describe('parse(content, { settings, ecmaFeatures })', function () {
const path = getFilename('jsx.js')
const parseStubParser = require('./parseStubParser')
const parseStubParserPath = require.resolve('./parseStubParser')
let content

before((done) =>
Expand All @@ -25,8 +27,8 @@ describe('parse(content, { settings, ecmaFeatures })', function () {
it('passes expected parserOptions to custom parser', function () {
const parseSpy = sinon.spy()
const parserOptions = { ecmaFeatures: { jsx: true } }
require('./parseStubParser').parse = parseSpy
parse(path, content, { settings: {}, parserPath: require.resolve('./parseStubParser'), parserOptions: parserOptions })
parseStubParser.parse = parseSpy
parse(path, content, { settings: {}, parserPath: parseStubParserPath, parserOptions: parserOptions })
expect(parseSpy.callCount, 'custom parser to be called once').to.equal(1)
expect(parseSpy.args[0][0], 'custom parser to get content as its first argument').to.equal(content)
expect(parseSpy.args[0][1], 'custom parser to get an object as its second argument').to.be.an('object')
Expand All @@ -50,8 +52,8 @@ describe('parse(content, { settings, ecmaFeatures })', function () {
it('should take the alternate parser specified in settings', function () {
const parseSpy = sinon.spy()
const parserOptions = { ecmaFeatures: { jsx: true } }
require('./parseStubParser').parse = parseSpy
expect(parse.bind(null, path, content, { settings: { 'import/parsers': { [require.resolve('./parseStubParser')]: [ '.js' ] } }, parserPath: null, parserOptions: parserOptions })).not.to.throw(Error)
parseStubParser.parse = parseSpy
expect(parse.bind(null, path, content, { settings: { 'import/parsers': { [parseStubParserPath]: [ '.js' ] } }, parserPath: null, parserOptions: parserOptions })).not.to.throw(Error)
expect(parseSpy.callCount, 'custom parser to be called once').to.equal(1)
})

Expand Down

0 comments on commit 5732742

Please sign in to comment.