Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tests] named: Run all TypeScript tests #2427

Merged
merged 1 commit into from Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

## [Unreleased]

### Changed
- [Tests] `named`: Run all TypeScript test ([#2427], thanks [@ProdigySim])

## [2.26.0] - 2022-04-05

### Added
Expand Down Expand Up @@ -977,6 +980,7 @@ for info on changes for earlier releases.

[`memo-parser`]: ./memo-parser/README.md

[#2427]: https://github.com/import-js/eslint-plugin-import/pull/2427
[#2417]: https://github.com/import-js/eslint-plugin-import/pull/2417
[#2411]: https://github.com/import-js/eslint-plugin-import/pull/2411
[#2393]: https://github.com/import-js/eslint-plugin-import/pull/2393
Expand Down Expand Up @@ -1624,6 +1628,7 @@ for info on changes for earlier releases.
[@Pessimistress]: https://github.com/Pessimistress
[@pmcelhaney]: https://github.com/pmcelhaney
[@preco21]: https://github.com/preco21
[@ProdigySim]: https://github.com/ProdigySim
[@pzhine]: https://github.com/pzhine
[@ramasilveyra]: https://github.com/ramasilveyra
[@randallreedjr]: https://github.com/randallreedjr
Expand Down
42 changes: 29 additions & 13 deletions tests/src/rules/named.js
Expand Up @@ -388,14 +388,18 @@ context('TypeScript', function () {
'import/resolver': { 'eslint-import-resolver-typescript': true },
};

const valid = [];
let valid = [];
const invalid = [
test({
code: `import {a} from './export-star-3/b';`,
filename: testFilePath('./export-star-3/a.js'),
parser,
settings,
}),
// TODO: uncomment this test
// test({
// code: `import {a} from './export-star-3/b';`,
// filename: testFilePath('./export-star-3/a.js'),
// parser,
// settings,
// errors: [
// { message: 'a not found in ./export-star-3/b' },
// ],
// }),
];

[
Expand All @@ -404,7 +408,7 @@ context('TypeScript', function () {
'typescript-export-assign-namespace',
'typescript-export-assign-namespace-merged',
].forEach((source) => {
valid.push(
valid = valid.concat(
test({
code: `import { MyType } from "./${source}"`,
parser,
Expand All @@ -420,11 +424,18 @@ context('TypeScript', function () {
parser,
settings,
}),
test({
code: `import { getFoo } from "./${source}"`,
parser,
settings,
}),
(source === 'typescript-declare'
? testVersion('> 5', () => ({
code: `import { getFoo } from "./${source}"`,
parser,
settings,
}))
: test({
code: `import { getFoo } from "./${source}"`,
parser,
settings,
})
),
test({
code: `import { MyEnum } from "./${source}"`,
parser,
Expand Down Expand Up @@ -469,5 +480,10 @@ context('TypeScript', function () {
}),
);
});

ruleTester.run(`named [TypeScript]`, rule, {
valid,
invalid,
});
});
});
4 changes: 2 additions & 2 deletions tests/src/rules/no-unused-modules.js
Expand Up @@ -7,8 +7,8 @@ import fs from 'fs';
import eslintPkg from 'eslint/package.json';
import semver from 'semver';

// TODO: figure out why these tests fail in eslint 4
const isESLint4TODO = semver.satisfies(eslintPkg.version, '^4');
// TODO: figure out why these tests fail in eslint 4 and 5
const isESLint4TODO = semver.satisfies(eslintPkg.version, '^4 || ^5');

const ruleTester = new RuleTester();
const typescriptRuleTester = new RuleTester(typescriptConfig);
Expand Down
22 changes: 13 additions & 9 deletions tests/src/rules/prefer-default-export.js
Expand Up @@ -170,26 +170,30 @@ context('TypeScript', function () {
// Exporting types
semver.satisfies(tsEslintVersion, '>= 22') ? test({
code: `
export type foo = string;
export type bar = number;`,
export type foo = string;
export type bar = number;
/* ${parser.replace(process.cwd(), '$$PWD')} */
`,
...parserConfig,
}) : [],
test({
code: `
export type foo = string;
export type bar = number;`,
export type foo = string;
export type bar = number;
/* ${parser.replace(process.cwd(), '$$PWD')} */
`,
...parserConfig,
}),
semver.satisfies(tsEslintVersion, '>= 22') ? test({
code: 'export type foo = string',
code: 'export type foo = string /* ' + parser.replace(process.cwd(), '$$PWD') + '*/',
...parserConfig,
}) : [],
test({
code: 'export interface foo { bar: string; }',
semver.satisfies(tsEslintVersion, '> 20') ? test({
code: 'export interface foo { bar: string; } /* ' + parser.replace(process.cwd(), '$$PWD') + '*/',
...parserConfig,
}),
}) : [],
test({
code: 'export interface foo { bar: string; }; export function goo() {}',
code: 'export interface foo { bar: string; }; export function goo() {} /* ' + parser.replace(process.cwd(), '$$PWD') + '*/',
...parserConfig,
}),
),
Expand Down
2 changes: 1 addition & 1 deletion tests/src/utils.js
Expand Up @@ -8,7 +8,7 @@ import 'babel-eslint';
export const parsers = {
ESPREE: require.resolve('espree'),
TS_OLD: semver.satisfies(eslintPkg.version, '>=4.0.0 <6.0.0') && require.resolve('typescript-eslint-parser'),
TS_NEW: semver.satisfies(eslintPkg.version, '>5.0.0') && require.resolve('@typescript-eslint/parser'),
TS_NEW: semver.satisfies(eslintPkg.version, '> 5') && require.resolve('@typescript-eslint/parser'),
BABEL_OLD: require.resolve('babel-eslint'),
};

Expand Down