Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stropho committed Sep 5, 2022
1 parent 00f2122 commit cd777a9
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions tests/src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@ import { RuleTester } from 'eslint';
import eslintPkg from 'eslint/package.json';
import semver from 'semver';
import flatMap from 'array.prototype.flatmap';
import { resolve } from 'path';
import { default as babelPresetFlow } from 'babel-preset-flow';


const ruleTester = new RuleTester();
const flowRuleTester = new RuleTester({
parser: resolve(__dirname, '../../../node_modules/babel-eslint'),
parserOptions: {
babelOptions: {
configFile: false,
babelrc: false,
presets: [babelPresetFlow],
},
},
});
const rule = require('rules/order');

function withoutAutofixOutput(test) {
Expand Down Expand Up @@ -1080,6 +1093,19 @@ ruleTester.run('order', rule, {
},
],
}),
// orderImportKind option that is not used
test({
code: `
import B from './B';
import b from './b';
`,
options: [
{
'alphabetize': { order: 'asc', orderImportKind: 'asc', 'caseInsensitive': true },
},
],
}),

],
invalid: [
// builtin before external module (require)
Expand Down Expand Up @@ -3128,3 +3154,83 @@ context('TypeScript', function () {
});
});
});

flowRuleTester.run('order', rule, {
valid: [
test({
options: [
{
alphabetize: { order: 'asc', orderImportKind: 'asc' },
},
],
code: `
import type {Bar} from 'common';
import typeof {foo} from 'common';
import {bar} from 'common';
`,
})],
invalid: [
test({
options: [
{
alphabetize: { order: 'asc', orderImportKind: 'asc' },
},
],
code: `
import type {Bar} from 'common';
import {bar} from 'common';
import typeof {foo} from 'common';
`,
output: `
import type {Bar} from 'common';
import typeof {foo} from 'common';
import {bar} from 'common';
`,
errors: [{
message: '`common` typeof import should occur before import of `common`',
}],
}),
test({
options: [
{
alphabetize: { order: 'asc', orderImportKind: 'desc' },
},
],
code: `
import type {Bar} from 'common';
import {bar} from 'common';
import typeof {foo} from 'common';
`,
output: `
import {bar} from 'common';
import typeof {foo} from 'common';
import type {Bar} from 'common';
`,
errors: [{
message: '`common` type import should occur after typeof import of `common`',
}],
}),
test({
options: [
{
alphabetize: { order: 'asc', orderImportKind: 'asc' },
},
],
code: `
import type {Bar} from './local/sub';
import {bar} from './local/sub';
import {baz} from './local-sub';
import typeof {foo} from './local/sub';
`,
output: `
import type {Bar} from './local/sub';
import typeof {foo} from './local/sub';
import {bar} from './local/sub';
import {baz} from './local-sub';
`,
errors: [{
message: '`./local/sub` typeof import should occur before import of `./local/sub`',
}],
}),
],
});

0 comments on commit cd777a9

Please sign in to comment.