1
|
|
|
const path = require('path'); |
2
|
|
|
const pluginTester = require('babel-plugin-tester'); |
3
|
|
|
const createBabylonOptions = require('babylon-options'); |
4
|
|
|
|
5
|
|
|
const plugin = require('../src/index.js'); |
6
|
|
|
|
7
|
|
|
const babelOptions = { |
8
|
|
|
filename: 'currentFile.js', |
9
|
|
|
parserOpts: createBabylonOptions({ |
10
|
|
|
stage: 2 |
11
|
|
|
}) |
12
|
|
|
}; |
13
|
|
|
|
14
|
|
|
pluginTester({ |
15
|
|
|
plugin, |
16
|
|
|
babelOptions: babelOptions, |
17
|
|
|
pluginOptions: { |
18
|
|
|
webpackConfig: path.resolve(__dirname + '/webpack.config.js'), |
|
|
|
|
19
|
|
|
}, |
20
|
|
|
snapshot: true, |
21
|
|
|
tests: { |
22
|
|
|
// convert this into a default import that leads to `testmodule/myFunc` |
23
|
|
|
'single named import': |
24
|
|
|
`import { myFunc } from 'testmodule'`, |
25
|
|
|
|
26
|
|
|
// convert this into named import that leads to `testmodule/myOtherFunc` |
27
|
|
|
'nested named import': |
28
|
|
|
`import { myOtherFunc } from 'testmodule'`, |
29
|
|
|
|
30
|
|
|
// convert this into one default import that leads to `testmodule/myFunc` |
31
|
|
|
// and a named import that leads to `testmodule/myOtherFunc` |
32
|
|
|
'multiple named imports': |
33
|
|
|
`import { myFunc, myOtherFunc } from 'testmodule'`, |
34
|
|
|
|
35
|
|
|
// convert this into three imports, one default import for `init` and |
36
|
|
|
// one default import for `myFunc` and a named one for `myOtherFunc` |
37
|
|
|
'default import with multiple named import': |
38
|
|
|
`import init, { myFunc, myOtherFunc } from 'testmodule'`, |
39
|
|
|
|
40
|
|
|
// convert this into a default import with `myAliasFunc` leading to |
41
|
|
|
// `testmodule/myFunc` |
42
|
|
|
'aliased named import': |
43
|
|
|
`import { myFunc as myAliasFunc } from 'testmodule'`, |
44
|
|
|
|
45
|
|
|
// don't change existing default imports like this |
46
|
|
|
'default import': |
47
|
|
|
`import myFunc from 'testmodule/myFunc'`, |
48
|
|
|
|
49
|
|
|
// unresolved default imports should be left alone |
50
|
|
|
'unresolved default import': |
51
|
|
|
`import React from 'reacty'`, |
52
|
|
|
|
53
|
|
|
// unresolved imports should be left alone |
54
|
|
|
'unresolved default import with named import': |
55
|
|
|
`import React, { Component } from 'reacty'`, |
56
|
|
|
|
57
|
|
|
// common js imports should be left alone |
58
|
|
|
'common js default import': |
59
|
|
|
`import React from './commonjsmodule'`, |
60
|
|
|
|
61
|
|
|
// common js imports should be left alone |
62
|
|
|
'common js default with named import': |
63
|
|
|
`import React, { Component } from './commonjsmodule'`, |
64
|
|
|
}, |
65
|
|
|
}); |
66
|
|
|
|