forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 3
/
helpers.test.js
136 lines (124 loc) · 3.95 KB
/
helpers.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { expect } from 'chai';
import { getDependencies } from './helpers';
describe('docs getDependencies helpers', () => {
const s1 = `
import * as React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Input from '@material-ui/core/Input';
import InputLabel from '@material-ui/core/InputLabel';
import FormControl from '@material-ui/core/FormControl';
import FormHelperText from '@material-ui/core/FormHelperText';
import Select from '@material-ui/core/Select';
import FooBar, { Qux } from '@foo-bar/bip';
const styles = theme => ({
container: {
display: 'flex',
flexWrap: 'wrap',
},
formContro
`;
it('should handle @ dependencies', () => {
expect(getDependencies(s1)).to.deep.equal({
'@foo-bar/bip': 'latest',
'@material-ui/core': 'next',
'prop-types': 'latest',
'react-dom': 'latest',
react: 'latest',
});
});
it('should handle * dependencies', () => {
const source = `
import * as React from 'react';
import PropTypes from 'prop-types';
import * as _ from '@unexisting/thing';
import Draggable from 'react-draggable';
import match from 'autosuggest-highlight/match';
import parse from 'autosuggest-highlight/parse';
import TextField from '@material-ui/core/TextField';
import Paper from '@material-ui/core/Paper';
import MenuItem from '@material-ui/core/MenuItem';
import { withStyles } from '@material-ui/core/styles';
const suggestions = [
`;
expect(getDependencies(source)).to.deep.equal({
'@material-ui/core': 'next',
'@unexisting/thing': 'latest',
'autosuggest-highlight': 'latest',
'prop-types': 'latest',
'react-draggable': 'latest',
'react-dom': 'latest',
react: 'latest',
});
});
it('should support next dependencies', () => {
expect(getDependencies(s1, { reactVersion: 'next' })).to.deep.equal({
'@foo-bar/bip': 'latest',
'@material-ui/core': 'next',
'prop-types': 'latest',
'react-dom': 'next',
react: 'next',
});
});
it('should support direct import', () => {
const source = `
import * as React from 'react';
import PropTypes from 'prop-types';
import Grid from '@material-ui/core/Grid';
import { withStyles } from '@material-ui/core/styles';
import DateFnsAdapter from "@material-ui/pickers/adapter/date-fns";
import { LocalizationProvider as MuiPickersLocalizationProvider, KeyboardTimePicker, KeyboardDatePicker } from '@material-ui/pickers';
`;
expect(getDependencies(source)).to.deep.equal({
'date-fns': 'latest',
'@material-ui/pickers': 'next',
'@material-ui/core': 'next',
'prop-types': 'latest',
'react-dom': 'latest',
react: 'latest',
});
});
it('can collect required @types packages', () => {
expect(getDependencies(s1, { codeLanguage: 'TS' })).to.deep.equal({
'@foo-bar/bip': 'latest',
'@material-ui/core': 'next',
'prop-types': 'latest',
'react-dom': 'latest',
react: 'latest',
'@types/foo-bar__bip': 'latest',
'@types/prop-types': 'latest',
'@types/react-dom': 'latest',
'@types/react': 'latest',
typescript: 'latest',
});
});
it('should handle multilines', () => {
const source = `
import * as React from 'react';
import DateFnsAdapter from '@material-ui/pickers/adapter/date-fns';
import {
LocalizationProvider as MuiPickersLocalizationProvider,
KeyboardTimePicker,
KeyboardDatePicker,
} from '@material-ui/pickers';
`;
expect(getDependencies(source)).to.deep.equal({
'date-fns': 'latest',
'@material-ui/core': 'next',
'@material-ui/pickers': 'next',
react: 'latest',
'react-dom': 'latest',
});
});
it('should always include core', () => {
const source = `
import lab from '@material-ui/lab';
`;
expect(getDependencies(source)).to.deep.equal({
'@material-ui/core': 'next',
'@material-ui/lab': 'next',
react: 'latest',
'react-dom': 'latest',
});
});
});