forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule_migration.test.js
81 lines (75 loc) · 1.74 KB
/
module_migration.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
const { RuleTester } = require('eslint');
const rule = require('./module_migration');
const dedent = require('dedent');
const ruleTester = new RuleTester({
parser: require.resolve('@babel/eslint-parser'),
parserOptions: {
ecmaVersion: 2018,
requireConfigFile: false,
},
});
ruleTester.run('@kbn/eslint/module-migration', rule, {
valid: [
{
code: dedent`
import "bar"
require('bar')
export { foo } from "bar"
export const foo2 = 'bar'
`,
options: [
[
{
from: 'foo',
to: 'bar',
},
],
],
},
],
invalid: [
{
code: dedent`
import "foo"
require('foo/foo2')
export { foo } from 'foo'
export const foo2 = 'bar'
`,
options: [
[
{
from: 'foo',
to: 'bar',
},
],
],
errors: [
{
line: 1,
message: 'Imported module "foo" should be "bar"',
},
{
line: 2,
message: 'Imported module "foo/foo2" should be "bar/foo2"',
},
{
line: 3,
message: 'Re-exported module "foo" should be "bar"',
},
],
output: dedent`
import 'bar'
require('bar/foo2')
export { foo } from 'bar'
export const foo2 = 'bar'
`,
},
],
});