Skip to content

Commit

Permalink
feat(test) react-native & @react-native/ packages version alignment (#80
Browse files Browse the repository at this point in the history
)

* 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
blakef authored Nov 15, 2024
1 parent 2ccb689 commit 18d421d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/tests.yaml
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


34 changes: 34 additions & 0 deletions scripts/__tests__/package_json-test.js
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);
});
});

0 comments on commit 18d421d

Please sign in to comment.