Skip to content

fix[gen1][react]: ENG-8739 change to makeFn() for handling errors when serialising functions #4050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ jobs:
cache-node-modules: true
cache-install-state: true

- name: Test React SDK
run: yarn g:nx test @builder.io/react -- packages/react/src

- name: Run E2E tests
run: yarn g:nx test @e2e/${{ matrix.e2e-server }}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { shouldForceBrowserRuntimeInNode } from './should-force-browser-runtime-in-node';

describe('shouldForceBrowserRuntimeInNode', () => {
const originalArch = process.arch;
const originalVersion = process.version;
const originalNodeOptions = process.env.NODE_OPTIONS;
const originalConsoleLog = console.log;

beforeEach(() => {
// Mock console.log to prevent actual logging during tests
console.log = jest.fn();
});

afterEach(() => {
// Restore original process properties
Object.defineProperty(process, 'arch', { value: originalArch });
Object.defineProperty(process, 'version', { value: originalVersion });
process.env.NODE_OPTIONS = originalNodeOptions;
console.log = originalConsoleLog;
});

it('should return false when not in Node runtime', () => {
// Save original process
const originalProcess = global.process;

try {
// Mock not being in Node runtime
// @ts-ignore - Intentionally modifying global.process for test
global.process = undefined;

expect(shouldForceBrowserRuntimeInNode()).toBe(false);
} finally {
// Restore original process
global.process = originalProcess;
}
});

it('should return false when not on arm64 architecture', () => {
Object.defineProperty(process, 'arch', { value: 'x64' });
Object.defineProperty(process, 'version', { value: 'v20.0.0' });
expect(shouldForceBrowserRuntimeInNode()).toBe(false);
});

it('should return false when not on Node 20', () => {
Object.defineProperty(process, 'arch', { value: 'arm64' });
Object.defineProperty(process, 'version', { value: 'v18.0.0' });
expect(shouldForceBrowserRuntimeInNode()).toBe(false);
});

it('should return false when on arm64 and Node 20 but has no-node-snapshot option', () => {
Object.defineProperty(process, 'arch', { value: 'arm64' });
Object.defineProperty(process, 'version', { value: 'v20.0.0' });
process.env.NODE_OPTIONS = '--no-node-snapshot';
expect(shouldForceBrowserRuntimeInNode()).toBe(false);
});

it('should return true and log warning when on arm64, Node 20, and no snapshot option flag', () => {
Object.defineProperty(process, 'arch', { value: 'arm64' });
Object.defineProperty(process, 'version', { value: 'v20.0.0' });
process.env.NODE_OPTIONS = '';

const result = shouldForceBrowserRuntimeInNode();

expect(result).toBe(true);
expect(console.log).toHaveBeenCalled();
});
});
Loading
Loading