Skip to content

Commit

Permalink
Fix TS parsers in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sharmilajesupaul committed Jul 17, 2019
1 parent adf4aaa commit 22c27b9
Showing 1 changed file with 61 additions and 23 deletions.
84 changes: 61 additions & 23 deletions tests/src/rules/prefer-default-export.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { test } from '../utils'

import { RuleTester } from 'eslint'
import eslintPkg from 'eslint/package.json'
import semver from 'semver'

const ruleTester = new RuleTester()
, rule = require('rules/prefer-default-export')
Expand Down Expand Up @@ -83,28 +85,6 @@ ruleTester.run('prefer-default-export', rule, {
code: 'export { a, b } from "foo.js"',
parser: 'babel-eslint',
}),

// Exporting types
test({
code: `
export type foo = string;
export type bar = number;`,
parser: 'typescript-eslint-parser',
}),
test({
code: `
export type foo = string;
export type bar = number;`,
parser: 'babel-eslint',
}),
test({
code: 'export type foo = string',
parser: 'typescript-eslint-parser',
}),
test({
code: 'export type foo = string',
parser: 'babel-eslint',
}),
// ...SYNTAX_CASES,
],
invalid: [
Expand Down Expand Up @@ -150,4 +130,62 @@ ruleTester.run('prefer-default-export', rule, {
}],
}),
],
})
});

context('Typescript', function() {
// Typescript
const parsers = ['typescript-eslint-parser', 'babel-eslint'];

if (semver.satisfies(eslintPkg.version, '>5.0.0')) {
parsers.push('@typescript-eslint/parser');
}

parsers.forEach((parser) => {
const parserConfig = {
parser: parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
};

ruleTester.run('export', rule, {
valid: [
// Exporting types
test(
{
code: `
export type foo = string;
export type bar = number;`,
parser,
},
parserConfig,
),
test(
{
code: `
export type foo = string;
export type bar = number;`,
parser,
},
parserConfig,
),
test(
{
code: 'export type foo = string',
parser,
},
parserConfig,
),
test(
{
code: 'export type foo = string',
parser,
},
parserConfig,
),
],
invalid: [],
});
});
});

0 comments on commit 22c27b9

Please sign in to comment.