Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

styled-components v6 support #438

Merged
merged 5 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 13 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
name: CI

on: [push, pull_request_target]
on:
push:
branches:
- "main"
pull_request_target:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 12
node-version-file: '.nvmrc'

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"

- uses: actions/cache@v1
- name: Restore yarn cache
uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
key: yarn-cache-folder-${{ hashFiles('**/yarn.lock', '.yarnrc.yml') }}
restore-keys: |
${{ runner.os }}-yarn-
yarn-cache-folder-

- name: Install modules
run: yarn --pure-lockfile
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"react-is": "^17.0.2",
"react-native": "^0.66.3",
"react-test-renderer": "^17.0.2",
"styled-components": "^5.0.0"
"styled-components": "^6.0.9"
},
"dependencies": {
"@adobe/css-tools": "^4.0.1"
Expand Down
7 changes: 5 additions & 2 deletions src/toHaveStyleRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const getAtRules = (ast, options) => {
.reduce((acc, rules) => acc.concat(rules), []);
};

/** stylis v4 renders descendant selectors without a trailing space sometimes which trips up detection */
const removeSpaceAfterSelector = input => input.replace(/([>~+]) +/g, '$1')

const normalizeQuotations = (input) => input.replace(/['"]/g, '"');

const getModifiedClassName = (className, staticClassName, modifier = '') => {
Expand Down Expand Up @@ -75,8 +78,8 @@ const hasClassNames = (classNames, selectors, options) => {

return classNames.some((className) =>
staticClassNames.some((staticClassName) =>
selectors.includes(
normalizeQuotations(getModifiedClassName(className, staticClassName, options.modifier).replace(/['"]/g, '"'))
selectors.map(removeSpaceAfterSelector).includes(
removeSpaceAfterSelector(normalizeQuotations(getModifiedClassName(className, staticClassName, options.modifier).replace(/['"]/g, '"')))
)
)
);
Expand Down
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if (!__PRIVATE__) {
const { mainSheet, masterSheet } = __PRIVATE__;

const sheet = mainSheet || masterSheet;

const isServer = () => typeof document === 'undefined';

const resetStyleSheet = () => {
Expand All @@ -18,6 +19,7 @@ const resetStyleSheet = () => {
}
}

sheet.gs = {};
sheet.names = new Map();
sheet.clearTag();
};
Expand Down Expand Up @@ -63,7 +65,7 @@ const buildReturnMessage = (utils, pass, property, received, expected) => () =>
const matcherTest = (received, expected, isNot) => {
// when negating, assert on existence of the style, rather than the value
if (isNot && expected === undefined) {
return received !== undefined;
return received !== undefined;
}

try {
Expand Down