Skip to content

Commit 4b1cb85

Browse files
authored
github actions (#381)
* github actions * update test yml * rename file & job * update jest * install specifically what's in the lockfile * proper yarn caching * small jest update * switch to inline snapshot * fix eslint * lint * cleanup and fix test * idk why this is being weird * set baseline node version to 12 * idk * dep upgrades * update babel-jest to match jest * this is some bullshit * move statement * update css dependency and a misc one
1 parent 0a97060 commit 4b1cb85

17 files changed

+3846
-3398
lines changed

.babelrc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
{
2-
"presets": [
3-
"@babel/preset-env",
4-
"@babel/preset-react"
5-
],
6-
"plugins": [
7-
"@babel/plugin-proposal-object-rest-spread",
8-
"@babel/plugin-proposal-class-properties"
9-
]
2+
"presets": ["@babel/preset-env", "@babel/preset-react"],
3+
"plugins": ["@babel/plugin-proposal-object-rest-spread", "@babel/plugin-proposal-class-properties"]
104
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.snap

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"env": {
44
"jest": true
55
},
6-
"parser": "babel-eslint"
6+
"parser": "babel-eslint",
7+
"plugins": ["prettier"]
78
}

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on: [push, pull_request_target]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
11+
- name: Setup node
12+
uses: actions/setup-node@v1
13+
with:
14+
node-version: 12
15+
16+
- name: Get yarn cache directory path
17+
id: yarn-cache-dir-path
18+
run: echo "::set-output name=dir::$(yarn cache dir)"
19+
20+
- uses: actions/cache@v1
21+
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
22+
with:
23+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
24+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
25+
restore-keys: |
26+
${{ runner.os }}-yarn-
27+
28+
- name: Install modules
29+
run: yarn --pure-lockfile
30+
31+
- name: Run tests
32+
run: yarn test

.github/workflows/codeql-analysis.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [main]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [main]
20+
schedule:
21+
- cron: "30 21 * * 0"
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: ["javascript"]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
37+
# Learn more:
38+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
39+
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v2
43+
44+
# Initializes the CodeQL tools for scanning.
45+
- name: Initialize CodeQL
46+
uses: github/codeql-action/init@v1
47+
with:
48+
languages: ${{ matrix.language }}
49+
# If you wish to specify custom queries, you can do so here or in a config file.
50+
# By default, queries listed here will override any specified in a config file.
51+
# Prefix the list here with "+" to use these queries and those in the config file.
52+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
53+
54+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55+
# If this step fails, then you should remove it and run the build manually (see below)
56+
- name: Autobuild
57+
uses: github/codeql-action/autobuild@v1
58+
59+
# ℹ️ Command-line programs to run using the OS shell.
60+
# 📚 https://git.io/JvXDl
61+
62+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63+
# and modify them (or add more) to build your code if your project
64+
# uses a compiled language
65+
66+
#- run: |
67+
# make bootstrap
68+
# make release
69+
70+
- name: Perform CodeQL Analysis
71+
uses: github/codeql-action/analyze@v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
yarn-error.log

.travis.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

package.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
"author": "Michele Bertoli",
1515
"license": "MIT",
1616
"scripts": {
17-
"test": "yarn test:web && yarn test:native && yarn test:preact && yarn test:ts",
18-
"test:web": "jest",
17+
"test": "yarn test:web && yarn test:native && yarn test:preact",
18+
"test:web": "jest --color",
1919
"test:web:watch": "jest --watch",
20-
"test:native": "jest --config .jest.native.json",
21-
"test:preact": "jest --config .jest.preact.json",
22-
"test:ts": "tsc --strict ./typings/index.d.ts"
20+
"test:native": "jest --color --config .jest.native.json",
21+
"test:preact": "jest --color --config .jest.preact.json"
2322
},
2423
"devDependencies": {
2524
"@babel/core": "^7.0.0",
@@ -30,29 +29,29 @@
3029
"@testing-library/react": "^9.3.2",
3130
"babel-core": "^7.0.0-bridge.0",
3231
"babel-eslint": "^10.0.1",
33-
"babel-jest": "^24.8.0",
32+
"babel-jest": "^26.0.0",
3433
"enzyme": "^3.6.0",
3534
"enzyme-adapter-preact-pure": "^2.2.0",
3635
"enzyme-adapter-react-16": "^1.5.0",
3736
"enzyme-to-json": "^3.3.1",
3837
"eslint": "^6.6.0",
3938
"eslint-config-prettier": "^6.5.0",
39+
"eslint-plugin-prettier": "^3.4.0",
4040
"husky": "^3.0.9",
41-
"jest": "^24.8.0",
41+
"jest": "^26.0.0",
4242
"lint-staged": "^9.4.2",
4343
"preact": "^10.0.0-beta.2",
4444
"preact-render-to-json": "^3.6.6",
45-
"prettier": "^1.18.2",
45+
"prettier": "^2.3.2",
4646
"react": "^16.8.0",
4747
"react-dom": "^16.8.0",
4848
"react-is": "^16.8.6",
4949
"react-native": "^0.61.4",
5050
"react-test-renderer": "^16.8.0",
51-
"styled-components": "^5.0.0",
52-
"typescript": "^3.0.3"
51+
"styled-components": "^5.0.0"
5352
},
5453
"dependencies": {
55-
"css": "^2.2.4"
54+
"css": "^3.0.0"
5655
},
5756
"peerDependencies": {
5857
"styled-components": ">= 5"
@@ -82,5 +81,8 @@
8281
"<rootDir>/test/native",
8382
"<rootDir>/test/preact"
8483
]
84+
},
85+
"engines": {
86+
"node": ">= 12"
8587
}
8688
}

src/native/toHaveStyleRule.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
1-
const { matcherTest, buildReturnMessage } = require('../utils')
1+
const { matcherTest, buildReturnMessage } = require('../utils');
22

33
function toHaveStyleRule(component, property, expected) {
4-
const styles = component.props.style.filter(x => x)
4+
const styles = component.props.style.filter((x) => x);
55

66
/**
77
* Convert style name to camel case (so we can compare)
88
*/
9-
const camelCasedProperty = property.replace(/-(\w)/, (_, match) =>
10-
match.toUpperCase()
11-
)
9+
const camelCasedProperty = property.replace(/-(\w)/, (_, match) => match.toUpperCase());
1210

1311
/**
1412
* Merge all styles into one final style object and search for the desired
1513
* stylename against this object
1614
*/
17-
const mergedStyles = styles.reduce((acc, item) => (Object.assign({}, acc, item )), {})
18-
const received = mergedStyles[camelCasedProperty]
19-
const pass =
20-
!received && !expected && this.isNot
21-
? false
22-
: matcherTest(received, expected)
15+
const mergedStyles = styles.reduce((acc, item) => Object.assign({}, acc, item), {});
16+
const received = mergedStyles[camelCasedProperty];
17+
const pass = !received && !expected && this.isNot ? false : matcherTest(received, expected);
2318

2419
return {
2520
pass,
2621
message: buildReturnMessage(this.utils, pass, property, received, expected),
27-
}
22+
};
2823
}
2924

30-
module.exports = toHaveStyleRule
25+
module.exports = toHaveStyleRule;

src/styleSheetSerializer.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ const getNodes = (node, nodes = []) => {
99
}
1010

1111
if (node.children) {
12-
Array.from(node.children).forEach(child => getNodes(child, nodes));
12+
Array.from(node.children).forEach((child) => getNodes(child, nodes));
1313
}
1414

1515
return nodes;
1616
};
1717

18-
const markNodes = nodes => nodes.forEach(node => (node[KEY] = true));
18+
const markNodes = (nodes) => nodes.forEach((node) => (node[KEY] = true));
1919

20-
const getClassNamesFromDOM = node => Array.from(node.classList);
21-
const getClassNamesFromProps = node => {
20+
const getClassNamesFromDOM = (node) => Array.from(node.classList);
21+
const getClassNamesFromProps = (node) => {
2222
const classNameProp = node.props && (node.props.class || node.props.className);
2323

2424
if (classNameProp) {
@@ -28,7 +28,7 @@ const getClassNamesFromProps = node => {
2828
return [];
2929
};
3030

31-
const getClassNames = nodes =>
31+
const getClassNames = (nodes) =>
3232
nodes.reduce((classNames, node) => {
3333
let newClassNames = null;
3434

@@ -38,36 +38,40 @@ const getClassNames = nodes =>
3838
newClassNames = getClassNamesFromProps(node);
3939
}
4040

41-
newClassNames.forEach(className => classNames.add(className));
41+
newClassNames.forEach((className) => classNames.add(className));
4242

4343
return classNames;
4444
}, new Set());
4545

46-
const filterClassNames = (classNames, hashes) => classNames.filter(className => hashes.includes(className));
47-
const filterUnreferencedClassNames = (classNames, hashes) => classNames.filter(className => className.startsWith('sc-') && !hashes.includes(className));
46+
const filterClassNames = (classNames, hashes) => classNames.filter((className) => hashes.includes(className));
47+
const filterUnreferencedClassNames = (classNames, hashes) =>
48+
classNames.filter((className) => className.startsWith('sc-') && !hashes.includes(className));
4849

4950
const includesClassNames = (classNames, selectors) =>
50-
classNames.some(className => selectors.some(selector => selector.includes(className)));
51+
classNames.some((className) => selectors.some((selector) => selector.includes(className)));
5152

5253
const includesUnknownClassNames = (classNames, selectors) =>
5354
!selectors
54-
.flatMap(selector => selector.split(' '))
55-
.filter(chunk => chunk.includes('sc-'))
56-
.every(chunk => classNames.some(className => chunk.includes(className)))
55+
.flatMap((selector) => selector.split(' '))
56+
.filter((chunk) => chunk.includes('sc-'))
57+
.every((chunk) => classNames.some((className) => chunk.includes(className)));
5758

58-
const filterRules = classNames => rule =>
59-
rule.type === 'rule' && !includesUnknownClassNames(classNames, rule.selectors) && includesClassNames(classNames, rule.selectors) && rule.declarations.length;
59+
const filterRules = (classNames) => (rule) =>
60+
rule.type === 'rule' &&
61+
!includesUnknownClassNames(classNames, rule.selectors) &&
62+
includesClassNames(classNames, rule.selectors) &&
63+
rule.declarations.length;
6064

6165
const getAtRules = (ast, filter) =>
6266
ast.stylesheet.rules
63-
.filter(rule => rule.type === 'media' || rule.type === 'supports')
67+
.filter((rule) => rule.type === 'media' || rule.type === 'supports')
6468
.reduce((acc, atRule) => {
6569
atRule.rules = atRule.rules.filter(filter);
6670

6771
return acc.concat(atRule);
6872
}, []);
6973

70-
const getStyle = classNames => {
74+
const getStyle = (classNames) => {
7175
const ast = getCSS();
7276
const filter = filterRules(classNames);
7377
const rules = ast.stylesheet.rules.filter(filter);
@@ -83,10 +87,10 @@ const getClassNamesFromSelectorsByHashes = (classNames, hashes) => {
8387
const filter = filterRules(classNames);
8488
const rules = ast.stylesheet.rules.filter(filter);
8589

86-
const selectors = rules.map(rule => rule.selectors);
90+
const selectors = rules.map((rule) => rule.selectors);
8791
const classNamesIncludingFromSelectors = new Set(classNames);
88-
const addHashFromSelectorListToClassNames = hash =>
89-
selectors.forEach(selectorList => selectorList[0].includes(hash) && classNamesIncludingFromSelectors.add(hash));
92+
const addHashFromSelectorListToClassNames = (hash) =>
93+
selectors.forEach((selectorList) => selectorList[0].includes(hash) && classNamesIncludingFromSelectors.add(hash));
9094

9195
hashes.forEach(addHashFromSelectorListToClassNames);
9296

@@ -95,12 +99,11 @@ const getClassNamesFromSelectorsByHashes = (classNames, hashes) => {
9599

96100
const replaceClassNames = (result, classNames, style) =>
97101
classNames
98-
.filter(className => style.includes(className))
102+
.filter((className) => style.includes(className))
99103
.reduce((acc, className, index) => acc.replace(new RegExp(className, 'g'), `c${index++}`), result);
100104

101105
const stripUnreferencedClassNames = (result, classNames) =>
102-
classNames
103-
.reduce((acc, className) => acc.replace(new RegExp(`${className}\\s?`,'g'), ''), result);
106+
classNames.reduce((acc, className) => acc.replace(new RegExp(`${className}\\s?`, 'g'), ''), result);
104107

105108
const replaceHashes = (result, hashes) =>
106109
hashes.reduce(

0 commit comments

Comments
 (0)