Skip to content

Commit dfd4d97

Browse files
committed
update remaining dependencies
1 parent f8f7314 commit dfd4d97

11 files changed

+2593
-3631
lines changed

.eslintrc

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
{
2-
"extends": ["airbnb", "plugin:prettier/recommended"],
3-
2+
"extends": ["prettier"],
43
"env": {
54
"jest": true
65
},
7-
8-
"rules": {
9-
"global-require": "off",
10-
"no-cond-assign": ["error", "except-parens"],
11-
"no-param-reassign": "off",
12-
"no-plusplus": "off",
13-
"no-underscore-dangle": ["error", {
14-
"allow": ["__DO_NOT_USE_OR_YOU_WILL_BE_HAUNTED_BY_SPOOKY_GHOSTS"]
15-
}],
16-
"prettier/prettier": ["error", {
17-
"semi": false,
18-
"singleQuote": true,
19-
"trailingComma": "es5"
20-
}],
21-
"react/jsx-filename-extension": ["error", { "extensions": [".js"] }],
22-
"react/prop-types": ["error", { "skipUndeclared": true }],
23-
}
6+
"parser": "babel-eslint"
247
}

.jest.native.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"preset": "react-native",
3-
"testRegex": "test/native/.*\\.spec\\.js$"
3+
"testRegex": "test/native/.*\\.spec\\.js$",
4+
"transform": {
5+
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
6+
}
47
}

package.json

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"author": "Michele Bertoli",
1515
"license": "MIT",
1616
"scripts": {
17-
"precommit": "lint-staged",
1817
"test": "yarn test:web && yarn test:native && yarn test:preact && yarn test:ts",
1918
"test:web": "jest",
2019
"test:web:watch": "jest --watch",
@@ -28,31 +27,28 @@
2827
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
2928
"@babel/preset-env": "^7.0.0",
3029
"@babel/preset-react": "^7.0.0",
30+
"@testing-library/react": "^8.0.1",
3131
"babel-core": "^7.0.0-bridge.0",
32+
"babel-eslint": "^10.0.1",
3233
"babel-jest": "^24.8.0",
3334
"enzyme": "^3.6.0",
3435
"enzyme-adapter-react-16": "^1.5.0",
3536
"enzyme-to-json": "^3.3.1",
36-
"eslint": "^3.17.1",
37-
"eslint-config-airbnb": "^14.1.0",
38-
"eslint-config-prettier": "^2.9.0",
39-
"eslint-plugin-import": "^2.14.0",
40-
"eslint-plugin-jsx-a11y": "^4.0.0",
41-
"eslint-plugin-prettier": "^2.1.2",
42-
"eslint-plugin-react": "^6.10.0",
43-
"husky": "^0.14.3",
37+
"eslint": "^5.16.0",
38+
"eslint-config-prettier": "^4.3.0",
39+
"husky": "^2.4.0",
4440
"jest": "^24.8.0",
45-
"lint-staged": "^7.2.2",
41+
"lint-staged": "^8.2.0",
4642
"preact": "^8.3.1",
4743
"preact-compat": "^3.18.4",
4844
"preact-render-to-json": "^3.6.6",
49-
"prettier": "^1.14.2",
50-
"react": "^16.5.0",
51-
"react-dom": "^16.5.0",
52-
"react-native": "^0.53.3",
53-
"react-test-renderer": "^16.5.0",
54-
"react-testing-library": "^5.0.1",
55-
"styled-components": "^3.4.5",
45+
"prettier": "^1.18.2",
46+
"react": "^16.8.0",
47+
"react-dom": "^16.8.0",
48+
"react-is": "^16.8.6",
49+
"react-native": "^0.59.9",
50+
"react-test-renderer": "^16.8.0",
51+
"styled-components": "^3",
5652
"typescript": "^3.0.3"
5753
},
5854
"dependencies": {
@@ -61,6 +57,11 @@
6157
"peerDependencies": {
6258
"styled-components": ">= 2"
6359
},
60+
"husky": {
61+
"hooks": {
62+
"pre-commit": "lint-staged"
63+
}
64+
},
6465
"lint-staged": {
6566
"*.js": [
6667
"eslint --fix",

src/toHaveStyleRule.js

Lines changed: 48 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,112 @@
1-
const { getCSS, matcherTest, buildReturnMessage } = require('./utils')
1+
const { getCSS, matcherTest, buildReturnMessage } = require('./utils');
22

3-
const shouldDive = node =>
4-
typeof node.dive === 'function' && typeof node.type() !== 'string'
3+
const shouldDive = node => typeof node.dive === 'function' && typeof node.type() !== 'string';
54

6-
const isTagWithClassName = node =>
7-
node.exists() && node.prop('className') && typeof node.type() === 'string'
5+
const isTagWithClassName = node => node.exists() && node.prop('className') && typeof node.type() === 'string';
86

97
const getClassNames = received => {
10-
let className
8+
let className;
119

1210
if (received) {
1311
if (received.$$typeof === Symbol.for('react.test.json')) {
14-
className = received.props.className || received.props.class
12+
className = received.props.className || received.props.class;
1513
} else if (typeof received.exists === 'function' && received.exists()) {
16-
const tree = shouldDive(received) ? received.dive() : received
17-
const components = tree.findWhere(isTagWithClassName)
14+
const tree = shouldDive(received) ? received.dive() : received;
15+
const components = tree.findWhere(isTagWithClassName);
1816
if (components.length) {
19-
className = components.first().prop('className')
17+
className = components.first().prop('className');
2018
}
2119
} else if (global.Element && received instanceof global.Element) {
22-
className = Array.from(received.classList).join(' ')
20+
className = Array.from(received.classList).join(' ');
2321
}
2422
}
2523

26-
return className ? className.split(/\s/) : []
27-
}
24+
return className ? className.split(/\s/) : [];
25+
};
2826

29-
const hasAtRule = options =>
30-
Object.keys(options).some(option => ['media', 'supports'].includes(option))
27+
const hasAtRule = options => Object.keys(options).some(option => ['media', 'supports'].includes(option));
3128

3229
const getAtRules = (ast, options) => {
33-
const mediaRegex = /(\([a-z-]+:)\s?([a-z0-9.]+\))/g
30+
const mediaRegex = /(\([a-z-]+:)\s?([a-z0-9.]+\))/g;
3431

3532
return Object.keys(options)
3633
.map(option =>
3734
ast.stylesheet.rules
38-
.filter(
39-
rule =>
40-
rule.type === option &&
41-
rule[option] === options[option].replace(mediaRegex, '$1$2')
42-
)
35+
.filter(rule => rule.type === option && rule[option] === options[option].replace(mediaRegex, '$1$2'))
4336
.map(rule => rule.rules)
4437
.reduce((acc, rules) => acc.concat(rules), [])
4538
)
46-
.reduce((acc, rules) => acc.concat(rules), [])
47-
}
39+
.reduce((acc, rules) => acc.concat(rules), []);
40+
};
4841

4942
const getModifiedClassName = (className, modifier = '') => {
50-
const classNameSelector = `.${className}`
51-
let prefix = ''
43+
const classNameSelector = `.${className}`;
44+
let prefix = '';
5245

53-
modifier = modifier.trim()
46+
modifier = modifier.trim();
5447
if (modifier.includes('&')) {
55-
modifier = modifier.replace(/&/g, classNameSelector)
48+
modifier = modifier.replace(/&/g, classNameSelector);
5649
} else {
57-
prefix += classNameSelector
50+
prefix += classNameSelector;
5851
}
59-
const first = modifier[0]
52+
const first = modifier[0];
6053
if (first !== ':' && first !== '[') {
61-
prefix += ' '
54+
prefix += ' ';
6255
}
6356

64-
return `${prefix}${modifier}`.trim()
65-
}
57+
return `${prefix}${modifier}`.trim();
58+
};
6659

6760
const hasClassNames = (classNames, selectors, options) =>
68-
classNames.some(className =>
69-
selectors.includes(getModifiedClassName(className, options.modifier))
70-
)
61+
classNames.some(className => selectors.includes(getModifiedClassName(className, options.modifier)));
7162

7263
const getRules = (ast, classNames, options) => {
73-
const rules = hasAtRule(options)
74-
? getAtRules(ast, options)
75-
: ast.stylesheet.rules
76-
77-
return rules.filter(
78-
rule =>
79-
rule.type === 'rule' && hasClassNames(classNames, rule.selectors, options)
80-
)
81-
}
64+
const rules = hasAtRule(options) ? getAtRules(ast, options) : ast.stylesheet.rules;
65+
66+
return rules.filter(rule => rule.type === 'rule' && hasClassNames(classNames, rule.selectors, options));
67+
};
8268

8369
const handleMissingRules = options => ({
8470
pass: false,
8571
message: () =>
8672
`No style rules found on passed Component${
87-
Object.keys(options).length
88-
? ` using options:\n${JSON.stringify(options)}`
89-
: ''
73+
Object.keys(options).length ? ` using options:\n${JSON.stringify(options)}` : ''
9074
}`,
91-
})
75+
});
9276

9377
const getDeclaration = (rule, property) =>
9478
rule.declarations
95-
.filter(
96-
declaration =>
97-
declaration.type === 'declaration' && declaration.property === property
98-
)
99-
.pop()
79+
.filter(declaration => declaration.type === 'declaration' && declaration.property === property)
80+
.pop();
10081

101-
const getDeclarations = (rules, property) =>
102-
rules.map(rule => getDeclaration(rule, property)).filter(Boolean)
82+
const getDeclarations = (rules, property) => rules.map(rule => getDeclaration(rule, property)).filter(Boolean);
10383

10484
const normalizeOptions = options =>
10585
options.modifier
10686
? Object.assign({}, options, {
107-
modifier: Array.isArray(options.modifier)
108-
? options.modifier.join('')
109-
: options.modifier,
87+
modifier: Array.isArray(options.modifier) ? options.modifier.join('') : options.modifier,
11088
})
111-
: options
89+
: options;
11290

11391
function toHaveStyleRule(component, property, expected, options = {}) {
114-
const classNames = getClassNames(component)
115-
const ast = getCSS()
116-
const normalizedOptions = normalizeOptions(options)
117-
const rules = getRules(ast, classNames, normalizedOptions)
92+
const classNames = getClassNames(component);
93+
const ast = getCSS();
94+
const normalizedOptions = normalizeOptions(options);
95+
const rules = getRules(ast, classNames, normalizedOptions);
11896

11997
if (!rules.length) {
120-
return handleMissingRules(normalizedOptions)
98+
return handleMissingRules(normalizedOptions);
12199
}
122100

123-
const declarations = getDeclarations(rules, property)
124-
const declaration = declarations.pop() || {}
125-
const received = declaration.value
126-
const pass =
127-
!received && !expected && this.isNot
128-
? false
129-
: matcherTest(received, expected)
101+
const declarations = getDeclarations(rules, property);
102+
const declaration = declarations.pop() || {};
103+
const received = declaration.value;
104+
const pass = !received && !expected && this.isNot ? false : matcherTest(received, expected);
130105

131106
return {
132107
pass,
133108
message: buildReturnMessage(this.utils, pass, property, received, expected),
134-
}
109+
};
135110
}
136111

137-
module.exports = toHaveStyleRule
112+
module.exports = toHaveStyleRule;

0 commit comments

Comments
 (0)