Skip to content

Commit 0a297b7

Browse files
alexeyr-ci2alexeyrAbanoubGhadban
authored
Fix JS tests workflow in CI (#2155)
### Summary The matrix in `.github/workflows/package-js-tests.yml` didn't work: `exclude` applies to the matrix itself and not to combinations added by include. The result is https://github.com/shakacode/react_on_rails/actions/runs/19803605936 <img width="1695" height="866" alt="image" src="https://github.com/user-attachments/assets/20dfda26-9826-4431-b16d-fdacdfe84b97" /> on all workflow jobs since it was set up. ### Pull Request checklist CI-only change, none of the below are needed. - ~[ ] Add/update test to cover these changes~ - ~[ ] Update documentation~ - ~[ ] Update CHANGELOG file~ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * CI workflow matrix reorganized (node versions moved to a dedicated axis); Node install behavior adjusted; renderer test step split to run against two packages. * Dependency adjustments across packages: some dev/peer entries removed, others added or relocated; package references updated in a dummy app. * Tooling script extended to update React version constraints for an additional package. * **Tests** * Test runner configuration enhanced to support TypeScript CommonJS/ESM variants and additional TS file extensions. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alexey Romanov <alexey.v.romanov@gmail.com> Co-authored-by: Abanoub Ghadban <abanoub@shakacode.com>
1 parent 25e4639 commit 0a297b7

File tree

8 files changed

+160
-85
lines changed

8 files changed

+160
-85
lines changed

.github/workflows/package-js-tests.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ jobs:
8181
)
8282
strategy:
8383
matrix:
84-
include:
84+
node-version:
8585
# Always run: Latest Node version (fast feedback on PRs)
86-
- node-version: '22'
86+
- '22'
8787
# Master and full-ci label: Minimum supported Node version (full coverage)
88-
- node-version: '20'
88+
- '20'
8989
exclude:
9090
# Skip minimum dependency matrix on regular PRs (run only on master or with full-ci label)
9191
- node-version: ${{ github.event_name == 'pull_request' && github.ref != 'refs/heads/master' && needs.detect-changes.outputs.has_full_ci_label != 'true' && '20' || '' }}
@@ -122,9 +122,11 @@ jobs:
122122
run: script/convert
123123
- name: Install Node modules with pnpm for renderer package
124124
run: |
125-
pnpm install ${{ matrix.node-version == '22' && '--frozen-lockfile' || '' }}
125+
pnpm install ${{ matrix.node-version == '22' && '--frozen-lockfile' || '--no-frozen-lockfile' }}
126126
pnpm add -g yalc
127127
- name: Build Renderer package
128128
run: pnpm build
129-
- name: Run JS unit tests for Renderer package
130-
run: pnpm test
129+
- name: Run JS unit tests for react-on-rails package
130+
run: pnpm --filter react-on-rails test
131+
- name: Run JS unit tests for react-on-rails-pro package
132+
run: pnpm --filter react-on-rails-pro test

jest.config.base.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
import { createJsWithTsPreset } from 'ts-jest';
22

3+
const tsconfig = {
4+
// Relative imports in our TS code include `.ts` extensions.
5+
// When compiling the package, TS rewrites them to `.js`,
6+
// but ts-jest runs on the original code where the `.js` files don't exist,
7+
// so this setting needs to be disabled here.
8+
rewriteRelativeImportExtensions: false,
9+
// Override hybrid module kind (Node16/NodeNext) to avoid ts-jest warning
10+
// about requiring isolatedModules: true
11+
module: 'ESNext',
12+
};
13+
14+
const tsJestPreset = createJsWithTsPreset({
15+
tsconfig,
16+
});
17+
318
// Global Jest configuration for the monorepo
419
// Contains common settings that all packages inherit
520
export default {
621
// === TypeScript Configuration ===
7-
// ts-jest preset with custom TypeScript settings
8-
...createJsWithTsPreset({
9-
tsconfig: {
10-
// Relative imports in our TS code include `.ts` extensions.
11-
// When compiling the package, TS rewrites them to `.js`,
12-
// but ts-jest runs on the original code where the `.js` files don't exist,
13-
// so this setting needs to be disabled here.
14-
rewriteRelativeImportExtensions: false,
15-
},
16-
}),
22+
// ts-jest preset with custom TypeScript settings, extended to handle .cts/.mts files
23+
...tsJestPreset,
24+
transform: {
25+
...tsJestPreset.transform,
26+
// Extend transform to include CommonJS TypeScript (.cts) and ES Module TypeScript (.mts) files
27+
'^.+\\.[cm]?ts$': [
28+
'ts-jest',
29+
{
30+
tsconfig,
31+
},
32+
],
33+
},
1734

1835
// === Test Environment Configuration ===
1936
testEnvironment: 'jsdom',
@@ -23,5 +40,6 @@ export default {
2340
testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
2441

2542
// === Common Module File Extensions ===
26-
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json'],
43+
// Include cts/mts for CommonJS/ES module TypeScript files
44+
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'cts', 'mts', 'json'],
2745
};

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"publint": "^0.3.4",
6161
"react": "18.0.0",
6262
"react-dom": "18.0.0",
63-
"react-on-rails-rsc": "19.0.2",
6463
"redux": "^4.2.1",
6564
"size-limit": "^12.0.0",
6665
"stylelint": "^16.14.0",

packages/react-on-rails-pro/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@
7777
"homepage": "https://github.com/shakacode/react_on_rails#readme",
7878
"devDependencies": {
7979
"@types/mock-fs": "^4.13.4",
80-
"mock-fs": "^5.5.0"
80+
"mock-fs": "^5.5.0",
81+
"react": "19.0.0",
82+
"react-dom": "19.0.0",
83+
"react-on-rails-rsc": "19.0.2"
8184
}
8285
}

packages/react-on-rails/package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,7 @@
5959
},
6060
"peerDependencies": {
6161
"react": ">= 16",
62-
"react-dom": ">= 16",
63-
"react-on-rails-rsc": "19.0.2"
64-
},
65-
"peerDependenciesMeta": {
66-
"react-on-rails-rsc": {
67-
"optional": true
68-
}
62+
"react-dom": ">= 16"
6963
},
7064
"files": [
7165
"lib/**/*.js",

0 commit comments

Comments
 (0)