Skip to content

Commit

Permalink
Enable hot reload with a custom dist (#118)
Browse files Browse the repository at this point in the history
* enablehotreload

* increment version
  • Loading branch information
elliotBraem authored Jun 28, 2024
1 parent 7188945 commit a8b00c4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export function modifyIndexHtml(content: string, opts: DevOptions) {
viewer.setAttribute('src', opts.index);
viewer.setAttribute('rpc', `http://127.0.0.1:${opts.port}/api/proxy-rpc`);
viewer.setAttribute('network', opts.network);
if (opts.hot) {
viewer.setAttribute('enablehotreload', "");
}
}

return dom.serialize();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bos-workspace",
"version": "1.0.0-alpha.28",
"version": "1.0.0-alpha.29",
"description": "",
"bin": {
"bos-workspace": "./bin/bw.js",
Expand Down
26 changes: 22 additions & 4 deletions tests/unit/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DevOptions } from '@/lib/dev';
import { handleReplacements } from '@/lib/gateway';
import { handleReplacements, modifyIndexHtml } from '@/lib/gateway';
import { Logger, LogLevel } from "@/lib/logger";
import { Network } from '@/lib/types';

Expand All @@ -18,7 +18,7 @@ describe("gateway", () => {
// Mocked input options
const mockOpts: DevOptions = {
port: 8080,
hot: true,
hot: false,
network: 'testnet' as Network,
index: "test/widget/index"
};
Expand All @@ -41,9 +41,27 @@ describe("gateway", () => {
// Test replacement of the near-social-viewer component with an RPC attribute
it("should replace <near-social-viewer></near-social-viewer> with near-social-viewer having an RPC attribute", () => {
const htmlInput = "<html><head></head><body><near-social-viewer></near-social-viewer></body></html>";
const expectedHtmlOutput = `<html><head></head><body><near-social-viewer src="${mockOpts.index}" rpc="http://127.0.0.1:${mockOpts.port}/api/proxy-rpc" network="${mockOpts.network}" ></near-social-viewer></body></html>`;
const expectedHtmlOutput = `<html><head></head><body><near-social-viewer src="${mockOpts.index}" rpc="http://127.0.0.1:${mockOpts.port}/api/proxy-rpc" network="${mockOpts.network}"></near-social-viewer></body></html>`;

const result = handleReplacements(htmlInput, mockOpts);
const result = modifyIndexHtml(htmlInput, mockOpts);
expect(result).toBe(expectedHtmlOutput);
});

it("should replace <near-social-viewer></near-social-viewer> with hotreload attribute if enabled", () => {
mockOpts.hot = true;
const htmlInput = "<html><head></head><body><near-social-viewer></near-social-viewer></body></html>";
const expectedHtmlOutput = `<html><head></head><body><near-social-viewer src="${mockOpts.index}" rpc="http://127.0.0.1:${mockOpts.port}/api/proxy-rpc" network="${mockOpts.network}" enablehotreload=""></near-social-viewer></body></html>`;

const result = modifyIndexHtml(htmlInput, mockOpts);
expect(result).toBe(expectedHtmlOutput);
});

it("should not replace <near-social-viewer></near-social-viewer> with hotreload attribute if disabled", () => {
mockOpts.hot = false;
const htmlInput = "<html><head></head><body><near-social-viewer></near-social-viewer></body></html>";
const expectedHtmlOutput = `<html><head></head><body><near-social-viewer src="${mockOpts.index}" rpc="http://127.0.0.1:${mockOpts.port}/api/proxy-rpc" network="${mockOpts.network}"></near-social-viewer></body></html>`;

const result = modifyIndexHtml(htmlInput, mockOpts);
expect(result).toBe(expectedHtmlOutput);
});
});

0 comments on commit a8b00c4

Please sign in to comment.