Skip to content

Commit

Permalink
fixup: fixing some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 23, 2022
1 parent 7737aa1 commit e2d8e6a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
13 changes: 10 additions & 3 deletions tests/src/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ const disableNewTS = semver.satisfies(tsParserVersion, '>= 4.1') // this rule is

function minEcmaVersion(features, parserOptions) {
const minEcmaVersionForFeatures = {
'export-default-from': 2018,
'class fields': 2022,
'optional chaining': 2020,
'arbitrary-export-names': 2022,
};
const result = Math.max.apply(
Math,
Expand Down Expand Up @@ -102,7 +104,8 @@ const parsers = {
&& typeof testObject.errors !== 'number'
&& {
errors: testObject.errors.map(
(errorObject) => {
(error) => {
const errorObject = typeof error === 'string' ? { message: error } : error;
const nextSuggestions = errorObject.suggestions && {
suggestions: errorObject.suggestions.map((suggestion) => Object.assign({}, suggestion, {
output: suggestion.output + extraComment,
Expand All @@ -125,6 +128,7 @@ const parsers = {

const skipBase = (features.has('class fields') && semver.satisfies(version, '< 8'))
|| (es >= 2020 && semver.satisfies(version, '< 6'))
|| (features.has('arbitrary-export-names') && semver.satisfies(version, '< 8.7'))
|| features.has('no-default')
|| features.has('bind operator')
|| features.has('do expressions')
Expand All @@ -134,13 +138,14 @@ const parsers = {
|| features.has('types')
//if it has fragments use version 5 and higher // create features for export from
|| (features.has('fragment') && semver.satisfies(version, '< 5'))
|| features.has('');
|| features.has('export-default-from');

const skipBabel = features.has('no-babel');
const skipOldBabel = skipBabel || features.has('no-babel-old') || semver.satisfies(version, '>= 8');
const skipNewBabel = skipBabel
|| features.has('no-babel-new')
|| !semver.satisfies(version, '^7.5.0') // require('@babel/eslint-parser/package.json').peerDependencies.eslint
|| features.has('export-default-from') // TODO: figure out how to configure babel for this
|| features.has('flow')
|| features.has('types')
|| features.has('ts');
Expand All @@ -149,7 +154,9 @@ const parsers = {
|| features.has('flow')
|| features.has('jsx namespace')
|| features.has('bind operator')
|| features.has('do expressions');
|| features.has('do expressions')
|| features.has('arbitrary-export-names') // TODO: figure out which TS version starts supporting this
|| features.has('export-default-from'); // TODO: figure out which TS version starts supporting this
const tsOld = !skipTS && !features.has('no-ts-old');
const tsNew = !skipTS && !features.has('no-ts-new');

Expand Down
46 changes: 26 additions & 20 deletions tests/src/rules/default.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// eslint-disable-next-line no-unused-vars
import path from 'path';
// eslint-disable-next-line no-unused-vars
import { test, testVersion, SYNTAX_CASES, parsers as utilsParsers, getTSParsers } from '../utils';
import { test, testVersion, SYNTAX_CASES, getTSParsers } from '../utils';
import parsers from '../parsers';
import { RuleTester } from 'eslint';
import semver from 'semver';
Expand Down Expand Up @@ -45,28 +43,24 @@ ruleTester.run('default', rule, {
// es7 export syntax
test({
code: 'export bar from "./bar"',
parserOptions: {
ecmaVersion: 2018,
ecmaFeatures: {
modules: true,
},
},
features: ['export-default-from'],
}),
test({ code: 'export { default as bar } from "./bar"' }),
test({ code: 'export bar, { foo } from "./bar"' }),
test({
code: 'export bar, { foo } from "./bar"',
features: ['export-default-from'],
}),
test({ code: 'export { default as bar, foo } from "./bar"' }),
test({ code: 'export bar, * as names from "./bar"',
parserOptions: {
ecmaVersion: 2018,
ecmaFeatures: {
modules: true,
},
} }),
test({
code: 'export bar, * as names from "./bar"',
features: ['export-default-from'],
}),

// sanity check
test({ code: 'export {a} from "./named-exports"' }),
test({
code: 'import twofer from "./trampoline"',
features: ['export-default-from'],
parserOptions: {
sourceType: 'module',
ecmaVersion: 2015,
Expand Down Expand Up @@ -96,17 +90,24 @@ ruleTester.run('default', rule, {
}),

// from no-errors
test({ code: "import Foo from './jsx/FooES7.js';" }),
test({
code: "import Foo from './jsx/FooES7.js';",
features: ['types', 'no-ts-old'],
}),

// #545: more ES7 cases
test({ code: "import bar from './default-export-from.js';" }),
test({
code: "import bar from './default-export-from.js';",
features: ['default-export-from'],
}),
test({ code: "import bar from './default-export-from-named.js';" }),
test({
code: "import bar from './default-export-from-ignored.js';",
settings: { 'import/ignore': ['common'] },
}),
test({
code: "export bar from './default-export-from-ignored.js';",
features: ['export-default-from'],
settings: { 'import/ignore': ['common'] },
}),

Expand Down Expand Up @@ -190,9 +191,9 @@ ruleTester.run('default', rule, {
},
}),

// es2022: Arbitrary module namespace identifier names
testVersion('>= 8.7', () => ({
code: 'export { "default" as bar } from "./bar"',
features: ['arbitrary-export-names'],
parserOptions: {
ecmaVersion: 2022,
},
Expand All @@ -210,6 +211,7 @@ ruleTester.run('default', rule, {
invalid: parsers.all([].concat(
test({
code: "import Foo from './jsx/FooES7.js';",
features: ['ts', 'no-ts-new'],
errors: ["Parse errors in imported module './jsx/FooES7.js': Unexpected token = (6:16)"],
}),

Expand All @@ -221,19 +223,23 @@ ruleTester.run('default', rule, {
// es7 export syntax
test({
code: 'export baz from "./named-exports"',
features: ['export-default-from'],
errors: ['No default export found in imported module "./named-exports".'],
}),
test({
code: 'export baz, { bar } from "./named-exports"',
features: ['export-default-from'],
errors: ['No default export found in imported module "./named-exports".'],
}),
test({
code: 'export baz, * as names from "./named-exports"',
features: ['export-default-from'],
errors: ['No default export found in imported module "./named-exports".'],
}),
// exports default from a module with no default
test({
code: 'import twofer from "./broken-trampoline"',
features: ['export-default-from'],
errors: ['No default export found in imported module "./broken-trampoline".'],
}),

Expand Down

0 comments on commit e2d8e6a

Please sign in to comment.