-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test) react-native & @react-native/ packages version alignment (#80
) * feat(test) react-native & @react-native/ packages version alignment These have to be aligned, unless we're not on a stable branch. * feat(tests) Add GHA workflow to run unit tests on PR + main Ensure that we don't sneak in irregular template modifications
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Tests | ||
|
||
on: | ||
pull_requests: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
unit-tests: | ||
name: Unit Tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/[email protected] | ||
- name: Setup node.js | ||
uses: actions/[email protected] | ||
with: | ||
node-version: 18 | ||
- name: Run unit tests | ||
run: npm test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const fs = require('fs'); | ||
const {execSync} = require('child_process'); | ||
|
||
const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim(); | ||
|
||
const isStableBranch = /\d+\.\d+-stable$/.test(branch); | ||
|
||
const isReactNativePackage = pkg => pkg === "react-native" || pkg.startsWith("@react-native/"); | ||
|
||
const label = isStableBranch ? 'react-native and ' : ''; | ||
|
||
describe("react-native packages on a version branch need to be aligned", () => { | ||
it(`has a consistent version for ${label}@react-native/ scoped packages in the template/package.json`, () => { | ||
const pkgJson = JSON.parse(fs.readFileSync('template/package.json')); | ||
|
||
const everything = Object.entries({ | ||
...pkgJson.dependencies, | ||
...pkgJson.devDependencies, | ||
...pkgJson.peerDependencies ?? {} | ||
}); | ||
|
||
const versions = Object.fromEntries(everything.filter(([name]) => isReactNativePackage(name))); | ||
|
||
if (!isStableBranch) { | ||
// This is the one case where "react-native" doesn't have to match | ||
delete versions["react-native"]; | ||
} | ||
|
||
const allReactNativeVersions = new Set(Object.values(versions)); | ||
|
||
// Only a single version | ||
expect(allReactNativeVersions.size).toEqual(1); | ||
}); | ||
}); |