Skip to content

Commit

Permalink
[Tests] named: add passing tests
Browse files Browse the repository at this point in the history
Related to import-js#2199
  • Loading branch information
ljharb committed Aug 24, 2021
1 parent 4aff27c commit 75170fa
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 87 deletions.
1 change: 1 addition & 0 deletions tests/files/export-star-3/b.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as b from './c';
Empty file added tests/files/export-star-3/c.ts
Empty file.
160 changes: 73 additions & 87 deletions tests/src/rules/named.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,105 +352,91 @@ ruleTester.run('named (export *)', rule, {

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

const valid = [];
const invalid = [
test({
code: `import {a} from './export-star-3/b';`,
filename: testFilePath('./export-star-3/a.js'),
parser: parser,
settings: settings,
}),
];

[
'typescript',
'typescript-declare',
'typescript-export-assign-namespace',
'typescript-export-assign-namespace-merged',
].forEach((source) => {
ruleTester.run(`named`, rule, {
valid: [
test({
code: `import { MyType } from "./${source}"`,
parser: parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: `import { Foo } from "./${source}"`,
parser: parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: `import { Bar } from "./${source}"`,
parser: parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: `import { getFoo } from "./${source}"`,
parser: parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: `import { MyEnum } from "./${source}"`,
parser: parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: `
valid.push(
test({
code: `import { MyType } from "./${source}"`,
parser: parser,
settings: settings,
}),
test({
code: `import { Foo } from "./${source}"`,
parser: parser,
settings: settings,
}),
test({
code: `import { Bar } from "./${source}"`,
parser: parser,
settings: settings,
}),
test({
code: `import { getFoo } from "./${source}"`,
parser: parser,
settings: settings,
}),
test({
code: `import { MyEnum } from "./${source}"`,
parser: parser,
settings: settings,
}),
test({
code: `
import { MyModule } from "./${source}"
MyModule.ModuleFunction()
`,
parser: parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: `
parser: parser,
settings: settings,
}),
test({
code: `
import { MyNamespace } from "./${source}"
MyNamespace.NSModule.NSModuleFunction()
`,
parser: parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
],

invalid: [
test({
code: `import { MissingType } from "./${source}"`,
parser: parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
errors: [{
message: `MissingType not found in './${source}'`,
type: 'Identifier',
}],
}),
test({
code: `import { NotExported } from "./${source}"`,
parser: parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
errors: [{
message: `NotExported not found in './${source}'`,
type: 'Identifier',
}],
}),
],
});
parser: parser,
settings: settings,
}),
);

invalid.push(
test({
code: `import { MissingType } from "./${source}"`,
parser: parser,
settings: settings,
errors: [{
message: `MissingType not found in './${source}'`,
type: 'Identifier',
}],
}),
test({
code: `import { NotExported } from "./${source}"`,
parser: parser,
settings: settings,
errors: [{
message: `NotExported not found in './${source}'`,
type: 'Identifier',
}],
}),
);
});
});
});

0 comments on commit 75170fa

Please sign in to comment.