Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@ import http from 'http';
import statusPageMiddleware from './../statusPageMiddleware';

describe('statusPageMiddleware', () => {
it('should set headers and end the response', () => {
process.cwd = () => '/mocked/path';
let res: jest.Mocked<http.ServerResponse>;
let mockReq: http.IncomingMessage;

const res: http.ServerResponse = {
beforeEach(() => {
res = {
setHeader: jest.fn(),
end: jest.fn(),
} as any;

const mockReq: http.IncomingMessage = {} as any;
mockReq = {} as any;
});

afterEach(() => {
jest.restoreAllMocks();
});

it('should set headers and end the response', () => {
jest.spyOn(process, 'cwd').mockReturnValue('/mocked/path');

statusPageMiddleware(mockReq, res);

// We're strictly checking response here, because React Native is strongly depending on this response. Changing the response might be a breaking change.
Expand All @@ -20,4 +30,16 @@ describe('statusPageMiddleware', () => {
);
expect(res.end).toHaveBeenCalledWith('packager-status:running');
});

it('should set headers and end the response with decoded value', () => {
jest.spyOn(process, 'cwd').mockReturnValue('/привіт/path');

statusPageMiddleware(mockReq, res);

expect(res.setHeader).toHaveBeenCalledWith(
'X-React-Native-Project-Root',
'/%D0%BF%D1%80%D0%B8%D0%B2%D1%96%D1%82/path',
);
expect(res.end).toHaveBeenCalledWith('packager-status:running');
});
});
5 changes: 4 additions & 1 deletion packages/cli-server-api/src/statusPageMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export default function statusPageMiddleware(
_req: http.IncomingMessage,
res: http.ServerResponse,
) {
res.setHeader('X-React-Native-Project-Root', process.cwd());
res.setHeader(
'X-React-Native-Project-Root',
new URL(`file:///${process.cwd()}`).pathname.slice(1),
);
res.end('packager-status:running');
}
5 changes: 4 additions & 1 deletion packages/cli-tools/src/getNextPort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const getNextPort = async (port: number, root: string): Promise<Result> => {

const isRunning = typeof result === 'object' && result.status === 'running';

if (isRunning && result.root === root) {
if (
isRunning &&
result.root === new URL(`file:///${root}`).pathname.slice(1)
) {
// Found running bundler for this project, so we do not need to start packager!
start = false;
} else if (isRunning || result === 'unrecognized') {
Expand Down
Loading