Skip to content

Commit

Permalink
[Tests] clean up tests, ensure test() is used properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 18, 2021
1 parent 3ff4d77 commit 3977c42
Show file tree
Hide file tree
Showing 5 changed files with 411 additions and 460 deletions.
143 changes: 74 additions & 69 deletions tests/src/rules/first.js
Expand Up @@ -7,60 +7,71 @@ const rule = require('rules/first');

ruleTester.run('first', rule, {
valid: [
test({ code: "import { x } from './foo'; import { y } from './bar';\
export { x, y }" }),
test({
code: "import { x } from './foo'; import { y } from './bar';\
export { x, y }",
}),
test({ code: "import { x } from 'foo'; import { y } from './bar'" }),
test({ code: "import { x } from './foo'; import { y } from 'bar'" }),
test({ code: "import { x } from './foo'; import { y } from 'bar'",
test({
code: "import { x } from './foo'; import { y } from 'bar'",
options: ['disable-absolute-first'],
}),
test({ code: "'use directive';\
import { x } from 'foo';" }),
test({
code: "'use directive';\
import { x } from 'foo';",
}),
],
invalid: [
test({ code: "import { x } from './foo';\
export { x };\
import { y } from './bar';",
errors: 1,
output: "import { x } from './foo';\
import { y } from './bar';\
export { x };",
test({
code: "import { x } from './foo';\
export { x };\
import { y } from './bar';",
errors: 1,
output: "import { x } from './foo';\
import { y } from './bar';\
export { x };",
}),
test({ code: "import { x } from './foo';\
export { x };\
import { y } from './bar';\
import { z } from './baz';",
errors: 2,
output: "import { x } from './foo';\
import { y } from './bar';\
import { z } from './baz';\
export { x };",
test({
code: "import { x } from './foo';\
export { x };\
import { y } from './bar';\
import { z } from './baz';",
errors: 2,
output: "import { x } from './foo';\
import { y } from './bar';\
import { z } from './baz';\
export { x };",
}),
test({ code: "import { x } from './foo'; import { y } from 'bar'",
test({
code: "import { x } from './foo'; import { y } from 'bar'",
options: ['absolute-first'],
errors: 1,
}),
test({ code: "import { x } from 'foo';\
'use directive';\
import { y } from 'bar';",
errors: 1,
output: "import { x } from 'foo';\
import { y } from 'bar';\
'use directive';",
test({
code: "import { x } from 'foo';\
'use directive';\
import { y } from 'bar';",
errors: 1,
output: "import { x } from 'foo';\
import { y } from 'bar';\
'use directive';",
}),
test({ code: "var a = 1;\
import { y } from './bar';\
if (true) { x() };\
import { x } from './foo';\
import { z } from './baz';",
errors: 3,
output: "import { y } from './bar';\
var a = 1;\
if (true) { x() };\
import { x } from './foo';\
import { z } from './baz';",
test({
code: "var a = 1;\
import { y } from './bar';\
if (true) { x() };\
import { x } from './foo';\
import { z } from './baz';",
errors: 3,
output: "import { y } from './bar';\
var a = 1;\
if (true) { x() };\
import { x } from './foo';\
import { z } from './baz';",
}),
test({ code: "if (true) { console.log(1) }import a from 'b'",
test({
code: "if (true) { console.log(1) }import a from 'b'",
errors: 1,
output: "import a from 'b'\nif (true) { console.log(1) }",
}),
Expand All @@ -72,7 +83,7 @@ context('TypeScript', function () {
.filter((parser) => parser !== require.resolve('typescript-eslint-parser'))
.forEach((parser) => {
const parserConfig = {
parser: parser,
parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
Expand All @@ -81,35 +92,29 @@ context('TypeScript', function () {

ruleTester.run('order', rule, {
valid: [
test(
{
code: `
import y = require('bar');
import { x } from 'foo';
import z = require('baz');
`,
parser,
},
parserConfig,
),
test({
code: `
import y = require('bar');
import { x } from 'foo';
import z = require('baz');
`,
...parserConfig,
}),
],
invalid: [
test(
{
code: `
import { x } from './foo';
import y = require('bar');
`,
options: ['absolute-first'],
parser,
errors: [
{
message: 'Absolute imports should come before relative imports.',
},
],
},
parserConfig,
),
test({
code: `
import { x } from './foo';
import y = require('bar');
`,
options: ['absolute-first'],
...parserConfig,
errors: [
{
message: 'Absolute imports should come before relative imports.',
},
],
}),
],
});
});
Expand Down
13 changes: 5 additions & 8 deletions tests/src/rules/no-duplicates.js
Expand Up @@ -420,7 +420,7 @@ context('TypeScript', function() {
.filter((parser) => parser !== require.resolve('typescript-eslint-parser'))
.forEach((parser) => {
const parserConfig = {
parser: parser,
parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
Expand All @@ -430,13 +430,10 @@ context('TypeScript', function() {
ruleTester.run('no-duplicates', rule, {
valid: [
// #1667: ignore duplicate if is a typescript type import
test(
{
code: "import type { x } from './foo'; import y from './foo'",
parser,
},
parserConfig,
),
test({
code: "import type { x } from './foo'; import y from './foo'",
...parserConfig,
}),
],
invalid: [],
});
Expand Down

0 comments on commit 3977c42

Please sign in to comment.