Skip to content

Commit

Permalink
created test to ensure static styles don't contain themeColor() calls…
Browse files Browse the repository at this point in the history
…, use node 18 in workflows
  • Loading branch information
myxmaster committed Nov 27, 2023
1 parent e4d59f2 commit 13d2cf4
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ This pull request is categorized as a:
- [ ] Code refactor
- [ ] Configuration change
- [ ] Locales update
- [ ] Quality assurance
- [ ] Quality assurance
- [ ] Other

## Checklist
- [ ] I’ve run `yarn run tsc` and made sure my code compiles correctly
- [ ] I’ve run `yarn run lint` and made sure my code didn’t contain any problematic patterns
- [ ] I’ve run `yarn run prettier` and made sure my code is formatted correctly
- [ ] I’ve run `yarn run test` and made sure all of the tests pass
- [ ] I’ve run `yarn run check-styles` and made sure all of the static styles don't contain themeColor() calls

## Testing

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '18.x'
- run: yarn install --frozen-lockfile
- run: yarn run lint
2 changes: 1 addition & 1 deletion .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '18.x'
- run: yarn install --frozen-lockfile
- run: yarn run prettier
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '18.x'
- run: yarn install --frozen-lockfile
- run: yarn run test
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ ZEUS is proud to be integrated on the following platforms:

**Don't trust, verify** the code with your own two eyes. Then when ready proceed to the steps below based on your platform.

### Prerequisites
1. Node.js (minimum version: 18.17)

### Android
1. install and setup react-native and its related dependencies under **"Building Projects with Native Code"** on
[react-native's Getting Started page](https://reactnative.dev/docs/environment-setup)
Expand Down
38 changes: 38 additions & 0 deletions check-styles.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as fs from 'fs';
import * as path from 'path';

describe('static style sheets', () => {
it('must not contain themeColor() calls', () => {
const dirs = fs
.readdirSync('.', { withFileTypes: true })
.filter((e) => e.isDirectory() && e.name !== 'node_modules')
.map((e) => e.name);
dirs.push('.');
const tsxFiles = dirs.flatMap((dir) =>
fs
.readdirSync(dir, { recursive: dir !== '.' })
.filter(
(file) =>
typeof file === 'string' &&
!file.startsWith('node_modules/') &&
file.toLowerCase().endsWith('.tsx')
)
.map((file) => path.join(dir, file as string))
);
const regExp = new RegExp(
/\n[^\s][^\n]+StyleSheet\.create\(\{.*themeColor\(/,
's'
);
const invalidFiles = tsxFiles.filter((file) =>
fs.readFileSync(file).toString('utf8').match(regExp)
);

if (invalidFiles.length > 0) {
throw new Error(
'The following files contain static StyleSheets with themeColor() calls. ' +
'This is not allowed because the color then will not be updated when theme is changed.\n' +
invalidFiles.join('\n')
);
}
});
});
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"transformIgnorePatterns": [
"node_modules/(?!(react-native|@react-native|react-native-blob-util|react-native-randombytes)/)"
]
],
"testPathIgnorePatterns": ["check-styles.test.ts"]
},
"scripts": {
"start": "react-native start",
Expand All @@ -18,14 +19,15 @@
"postinstall": "rn-nodeify --install --hack & npx jetify & yarn run patch & react-native setup-ios-permissions & yarn run fetch-libraries & pod-install",
"test": "jest",
"tsc": "tsc",
"lint": "eslint --ext .js,.ts,.tsx \"*.@(js|ts|tsx)\" .",
"lint": "eslint --ext .js,.ts,.tsx \"*.@(js|ts|tsx)\" . && yarn run test check-styles.test.ts --testPathIgnorePatterns=",
"prettier": "prettier --check \"**/*.ts*\"",
"prettier-write": "prettier --check --write \"**/*.ts*\"",
"patch": "git apply patches/react-native-camera-kit.patch && git apply patches/rnqli-build.gradle.patch",
"gen-proto": "pbjs -t static-module --keep-case -w es6 --force-long -o proto/lightning.js proto/*.proto proto/*/*.proto && pbts -o proto/lightning.d.ts proto/lightning.js",
"gradlew": "cd android && ./gradlew",
"android:clean": "yarn gradlew clean",
"fetch-libraries": "bash fetch-libraries.sh"
"fetch-libraries": "bash fetch-libraries.sh",
"check-styles": "bash check-styles.sh"
},
"dependencies": {
"@keystonehq/bc-ur-registry": "0.4.2",
Expand Down

0 comments on commit 13d2cf4

Please sign in to comment.