Skip to content

Commit a091842

Browse files
authored
Use @babel/eslint-parser in tests (#961)
1 parent 88a724c commit a091842

File tree

7 files changed

+111
-89
lines changed

7 files changed

+111
-89
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
"devDependencies": {
5353
"@ava/babel": "^1.0.1",
5454
"@babel/code-frame": "7.12.11",
55+
"@babel/core": "7.12.10",
56+
"@babel/eslint-parser": "7.12.1",
5557
"@lubien/fixture-beta-package": "^1.0.0-beta.1",
5658
"@typescript-eslint/parser": "^4.12.0",
5759
"ava": "^3.15.0",

test/custom-error-definition.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -500,17 +500,6 @@ runTest.babel({
500500
}
501501
`,
502502
errors: [invalidNameError('ValidationError')]
503-
},
504-
{
505-
code: outdent`
506-
export class ValidationError extends Error {
507-
'name': SomeType;
508-
constructor(message) {
509-
super(message);
510-
}
511-
}
512-
`,
513-
errors: [invalidNameError('ValidationError')]
514503
}
515504
]
516505
});
@@ -523,5 +512,17 @@ runTest.typescript({
523512
}
524513
`
525514
],
526-
invalid: []
515+
invalid: [
516+
{
517+
code: outdent`
518+
export class ValidationError extends Error {
519+
'name': SomeType;
520+
constructor(message) {
521+
super(message);
522+
}
523+
}
524+
`,
525+
errors: [invalidNameError('ValidationError')]
526+
}
527+
]
527528
});

test/integration/projects.js

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ module.exports = [
88
},
99
{
1010
repository: 'https://github.com/avajs/ava',
11-
extraArguments: [
12-
'--ignore-pattern',
11+
ignore: [
1312
'test/node_modules'
1413
]
1514
},
@@ -48,53 +47,41 @@ module.exports = [
4847
'https://github.com/sindresorhus/pageres',
4948
{
5049
repository: 'https://github.com/sindresorhus/got',
51-
extraArguments: [
52-
'--ignore-pattern',
53-
'documentation/examples/gh-got.js' // This file use `package` keyword as variable
50+
ignore: [
51+
// This file use `package` keyword as variable
52+
'documentation/examples/gh-got.js'
5453
]
5554
},
5655
'https://github.com/eslint/eslint',
5756
{
5857
repository: 'https://github.com/prettier/prettier',
59-
extraArguments: [
60-
'--ignore-pattern',
58+
ignore: [
6159
'tests/**'
6260
]
6361
},
6462
'https://github.com/facebook/react',
6563
{
6664
repository: 'https://github.com/angular/angular',
67-
extraArguments: [
68-
'--ignore-pattern',
65+
ignore: [
6966
'aio/content/examples/animations/src/app/open-close.component.3.ts',
70-
'--ignore-pattern',
7167
'aio/content/examples/router/src/app/app-routing.module.9.ts',
72-
73-
'--ignore-pattern',
7468
'aio/tools/transforms/templates/data-module.template.js',
75-
'--ignore-pattern',
7669
'aio/tools/transforms/authors-package/index.js', // This file use `package` keyword as variable
77-
78-
'--ignore-pattern',
7970
'packages/compiler-cli/test/**',
80-
81-
'--ignore-pattern',
8271
'tools/**'
8372
]
8473
},
8574
{
8675
repository: 'https://github.com/microsoft/typescript',
87-
extraArguments: [
76+
ignore: [
8877
// These file use `'\033'`
89-
'--ignore-pattern',
9078
'build/**'
9179
]
9280
},
9381
{
9482
repository: 'https://github.com/microsoft/vscode',
95-
extraArguments: [
83+
ignore: [
9684
// This file use `'\033'`
97-
'--ignore-pattern',
9885
'build/**'
9986
]
10087
},
@@ -108,33 +95,28 @@ module.exports = [
10895
'https://github.com/gatsbyjs/gatsby',
10996
{
11097
repository: 'https://github.com/puppeteer/puppeteer',
111-
extraArguments: [
98+
ignore: [
11299
// Parser error on `await page.evaluate(() => delete Node);`
113100
// https://github.com/puppeteer/puppeteer/blob/0b1a9ceee2f05f534f0d50079ece172d627a93c7/test/jshandle.spec.js#L151
114-
'--ignore-pattern',
115101
'test/jshandle.spec.js',
116102

117103
// `package` keyword
118104
// https://github.com/puppeteer/puppeteer/blob/0b1a9ceee2f05f534f0d50079ece172d627a93c7/utils/apply_next_version.js#L17
119-
'--ignore-pattern',
120105
'utils/apply_next_version.js'
121106
]
122107
},
123108
{
124109
repository: 'https://github.com/vercel/next.js',
125-
extraArguments: [
126-
'--ignore-pattern',
110+
ignore: [
127111
'examples/**',
128112

129113
// These files use `>` in jsx
130-
'--ignore-pattern',
131114
'test/integration/**'
132115
]
133116
},
134117
{
135118
repository: 'https://github.com/chakra-ui/chakra-ui',
136-
extraArguments: [
137-
'--ignore-pattern',
119+
ignore: [
138120
'scripts/create-package.js' // This file use `package` keyword as variable
139121
]
140122
},
@@ -144,16 +126,14 @@ module.exports = [
144126
// #912
145127
{
146128
repository: 'https://github.com/microsoft/fluentui',
147-
extraArguments: [
148-
'--ignore-pattern',
129+
ignore: [
149130
'scripts/publish-beta.js' // This file use `package` keyword as variable
150131
]
151132
},
152133
// #902
153134
{
154135
repository: 'https://github.com/reakit/reakit',
155-
extraArguments: [
156-
'--ignore-pattern',
136+
ignore: [
157137
'packages/reakit/jest.config.js' // This file use `package` keyword as variable
158138
]
159139
},
@@ -169,15 +149,13 @@ module.exports = [
169149
const {
170150
repository,
171151
name = repository.split('/').pop(),
172-
path = '',
173-
extraArguments = []
152+
ignore = []
174153
} = project;
175154

176155
return {
177156
...project,
178157
name,
179158
repository,
180-
path,
181-
extraArguments
159+
ignore
182160
};
183161
});

test/integration/test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,21 @@ const enrichErrors = (packageName, cliArguments, f) => async (...arguments_) =>
2727
const makeEslintTask = (project, destination) => {
2828
const arguments_ = [
2929
'eslint',
30+
project.path || '.',
3031
'--fix-dry-run',
3132
'--no-eslintrc',
3233
'--ext',
3334
'.js,.ts,.vue',
3435
'--format',
3536
'json',
3637
'--config',
37-
path.join(__dirname, 'config.js'),
38-
project.path || '.',
39-
...project.extraArguments
38+
path.join(__dirname, 'config.js')
4039
];
4140

41+
for (const pattern of project.ignore) {
42+
arguments_.push('--ignore-pattern', pattern);
43+
}
44+
4245
return enrichErrors(project.name, arguments_, async () => {
4346
let stdout;
4447
let processError;

test/prefer-ternary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ test({
12791279
]
12801280
});
12811281

1282-
test.babel({
1282+
test.babelLegacy({
12831283
valid: [],
12841284
invalid: [
12851285
// https://github.com/facebook/react/blob/7a1691cdff209249b49a4472ba87b542980a5f71/packages/react-dom/src/client/DOMPropertyOperations.js#L183

test/prevent-abbreviations.js

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,42 +1753,6 @@ runTest.babel({
17531753
errors: createErrors()
17541754
},
17551755

1756-
// #347
1757-
{
1758-
code: outdent`
1759-
function onKeyDown(e: KeyboardEvent) {
1760-
if (e.keyCode) {}
1761-
}
1762-
`,
1763-
output: outdent`
1764-
function onKeyDown(event: KeyboardEvent) {
1765-
if (event.keyCode) {}
1766-
}
1767-
`,
1768-
options: [
1769-
{
1770-
extendDefaultReplacements: false,
1771-
replacements: {
1772-
e: {
1773-
event: true
1774-
}
1775-
}
1776-
}
1777-
],
1778-
errors: createErrors()
1779-
},
1780-
1781-
// https://github.com/facebook/relay/blob/597d2a17aa29d401830407b6814a5f8d148f632d/packages/relay-experimental/EntryPointTypes.flow.js#L138
1782-
{
1783-
code: outdent`
1784-
export type PreloadProps<TExtraProps = null> = {}
1785-
`,
1786-
output: outdent`
1787-
export type PreloadProperties<TExtraProperties = null> = {}
1788-
`,
1789-
errors: [...createErrors(), ...createErrors()]
1790-
},
1791-
17921756
noFixingTestCase({
17931757
code: '(class {e = 1})',
17941758
options: checkPropertiesOptions,
@@ -1861,6 +1825,58 @@ runTest.typescript({
18611825
export default Property;
18621826
`,
18631827
errors: 1
1828+
},
1829+
1830+
// #347
1831+
{
1832+
code: outdent`
1833+
function onKeyDown(e: KeyboardEvent) {
1834+
if (e.keyCode) {}
1835+
}
1836+
`,
1837+
output: outdent`
1838+
function onKeyDown(event: KeyboardEvent) {
1839+
if (event.keyCode) {}
1840+
}
1841+
`,
1842+
options: [
1843+
{
1844+
extendDefaultReplacements: false,
1845+
replacements: {
1846+
e: {
1847+
event: true
1848+
}
1849+
}
1850+
}
1851+
],
1852+
errors: createErrors()
1853+
},
1854+
1855+
// https://github.com/facebook/relay/blob/597d2a17aa29d401830407b6814a5f8d148f632d/packages/relay-experimental/EntryPointTypes.flow.js#L138
1856+
{
1857+
code: outdent`
1858+
export type PreloadProps<TExtraProps = null> = {}
1859+
`,
1860+
output: outdent`
1861+
export type PreloadProperties<TExtraProperties = null> = {}
1862+
`,
1863+
errors: [...createErrors(), ...createErrors()]
1864+
}
1865+
]
1866+
});
1867+
1868+
runTest.babelLegacy({
1869+
valid: [],
1870+
invalid: [
1871+
// https://github.com/facebook/relay/blob/597d2a17aa29d401830407b6814a5f8d148f632d/packages/relay-experimental/EntryPointTypes.flow.js#L138
1872+
{
1873+
code: outdent`
1874+
export type PreloadProps<TExtraProps = null> = {};
1875+
`,
1876+
output: outdent`
1877+
export type PreloadProperties<TExtraProperties = null> = {};
1878+
`,
1879+
errors: [...createErrors(), ...createErrors()]
18641880
}
18651881
]
18661882
});

test/utils/test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ runTest.typescript = tests => runTest({
3131
});
3232

3333
runTest.babel = tests => runTest({
34+
...tests,
35+
testerOptions: {
36+
parser: require.resolve('@babel/eslint-parser'),
37+
parserOptions: {
38+
...defaultParserOptions,
39+
40+
requireConfigFile: false,
41+
sourceType: 'module',
42+
allowImportExportEverywhere: true,
43+
babelOptions: {
44+
parserOpts: {
45+
plugins: [
46+
'jsx',
47+
'classProperties'
48+
]
49+
}
50+
}
51+
}
52+
}
53+
});
54+
55+
runTest.babelLegacy = tests => runTest({
3456
...tests,
3557
testerOptions: {parser: require.resolve('babel-eslint')}
3658
});

0 commit comments

Comments
 (0)