Skip to content

Commit

Permalink
[Tests] order: group TS tests together
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jun 8, 2020
1 parent 63d2a3f commit 0179440
Showing 1 changed file with 44 additions and 45 deletions.
89 changes: 44 additions & 45 deletions tests/src/rules/order.js
Expand Up @@ -3,6 +3,7 @@ import { test, getTSParsers, getNonDefaultParsers } from '../utils'
import { RuleTester } from 'eslint'
import eslintPkg from 'eslint/package.json'
import semver from 'semver'
import flatMap from 'array.prototype.flatmap'

const ruleTester = new RuleTester()
, rule = require('rules/order')
Expand Down Expand Up @@ -167,8 +168,8 @@ ruleTester.run('order', rule, {
var index = require('./');
`,
}),
// Export equals expressions should be on top alongside with ordinary import-statements.
...getTSParsers().map(parser => (
...flatMap(getTSParsers(), parser => [
// Export equals expressions should be on top alongside with ordinary import-statements.
test({
code: `
import async, {foo1} from 'async';
Expand All @@ -181,8 +182,8 @@ ruleTester.run('order', rule, {
var index = require('./');
`,
parser,
})
)),
}),
]),
// Adding unknown import types (e.g. using a resolver alias via babel) to the groups.
test({
code: `
Expand Down Expand Up @@ -1158,7 +1159,7 @@ ruleTester.run('order', rule, {
message: '`fs` import should occur after import of `../foo/bar`',
}],
}),
...getTSParsers().map(parser => (
...flatMap(getTSParsers(), parser => [
test({
code: `
var fs = require('fs');
Expand All @@ -1174,8 +1175,44 @@ ruleTester.run('order', rule, {
errors: [{
message: '`fs` import should occur after import of `../foo/bar`',
}],
})
)),
}),
{
code: `
var async = require('async');
var fs = require('fs');
`,
output: `
var fs = require('fs');
var async = require('async');
`,
parser,
errors: [{
message: '`fs` import should occur before import of `async`',
}],
},
test({
code: `
import sync = require('sync');
import async, {foo1} from 'async';
import index from './';
`,
output: `
import async, {foo1} from 'async';
import sync = require('sync');
import index from './';
`,
options: [{
groups: ['external', 'index'],
alphabetize: {order: 'asc'},
}],
parser,
errors: [{
message: '`async` import should occur before import of `sync`',
}],
}),
]),
// Default order using import with custom import alias
test({
code: `
Expand Down Expand Up @@ -1909,20 +1946,6 @@ ruleTester.run('order', rule, {
message: '`fs` import should occur before import of `async`',
}],
})),
...getTSParsers().map(parser => ({
code: `
var async = require('async');
var fs = require('fs');
`,
output: `
var fs = require('fs');
var async = require('async');
`,
parser,
errors: [{
message: '`fs` import should occur before import of `async`',
}],
})),
// Option alphabetize: {order: 'asc'}
test({
code: `
Expand All @@ -1947,30 +1970,6 @@ ruleTester.run('order', rule, {
message: '`Bar` import should occur before import of `bar`',
}],
}),
...getTSParsers().map(parser => (
test({
code: `
import sync = require('sync');
import async, {foo1} from 'async';
import index from './';
`,
output: `
import async, {foo1} from 'async';
import sync = require('sync');
import index from './';
`,
options: [{
groups: ['external', 'index'],
alphabetize: {order: 'asc'},
}],
parser,
errors: [{
message: '`async` import should occur before import of `sync`',
}],
})
)),
// Option alphabetize: {order: 'desc'}
test({
code: `
Expand Down

0 comments on commit 0179440

Please sign in to comment.