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
7 changes: 4 additions & 3 deletions .github/workflows/matlab-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ jobs:
uses: matlab-actions/setup-matlab@v2

- name: Run tests
uses: matlab-actions/run-tests@v2
uses: matlab-actions/run-command@v2
with:
source-folder: toolbox
code-coverage-cobertura: code-coverage/coverage.xml
command: |
openProject("uihtml-debugger.prj");
runTests;

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
The UIHTML Debugger is a non-intrusive toolkit designed to bridge the gap between MATLAB and JavaScript development. It provides two essential tools to streamline web-based UI development within MATLAB:

1. **Console Error Rerouter**: Forwards console.log, warn, and error messages directly to the MATLAB Command Window.
2. **UIHTML DevTools**: Injects Eruda—a full-featured mobile-style console—directly into your UI for deep inspection without leaving the MATLAB environment.
1. **UIHTML DevTools**: Injects Eruda—a full-featured mobile-style console—directly into your UI for deep inspection without leaving the MATLAB environment.

---

## Requirements

* **MATLAB R2023a** or later.
* **Base MATLAB** (no additional toolboxes required).

---

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info Name="Toolbox Image File" ReadOnly="WRITABLE"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="Deployment_ToolboxImageFile_e879122a-6b93-4d3b-9a10-49a600882ccb" type="Label"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info Name="App Gallery File" ReadOnly="WRITABLE"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="Deployment_ToolboxAppGalleryFiles_e879122a-6b93-4d3b-9a10-49a600882ccb" type="Label"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info Name="Getting Started Guide" ReadOnly="WRITABLE"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="Deployment_GettingStartedGuideFile_e879122a-6b93-4d3b-9a10-49a600882ccb" type="Label"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info DataType="None" Name="Toolbox - Toolbox1 (1)" ReadOnly="0" SingleValued="0"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="Deployment_Category_e879122a-6b93-4d3b-9a10-49a600882ccb" type="Category"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info DataType="None" Name="Toolbox - Toolbox1 (2)" ReadOnly="0" SingleValued="0"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="Deployment_Category_9f79ed46-75ab-4c44-81b9-9b322b0cd885" type="Category"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info Name="Getting Started Guide" ReadOnly="WRITABLE"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="Deployment_GettingStartedGuideFile_9f79ed46-75ab-4c44-81b9-9b322b0cd885" type="Label"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info Name="App Gallery File" ReadOnly="WRITABLE"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="Deployment_ToolboxAppGalleryFiles_9f79ed46-75ab-4c44-81b9-9b322b0cd885" type="Label"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info Name="Toolbox Image File" ReadOnly="WRITABLE"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="Deployment_ToolboxImageFile_9f79ed46-75ab-4c44-81b9-9b322b0cd885" type="Label"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="runTests.m" type="File"/>
2 changes: 1 addition & 1 deletion resources/project/root/amwE3LmoG--0pRWluRol6WgE4ZYd.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info configMapData="{&quot;uihtml-dubugger&quot;:&quot;MathWorksDeploymentConfig{3b515abd-47e6-464e-adf2-ddaf8b81973e}&quot;}"/>
<Info configMapData="{&quot;uihtml-dubugger&quot;:&quot;MathWorksDeploymentConfig{3b515abd-47e6-464e-adf2-ddaf8b81973e}&quot;,&quot;uihtml_debugger&quot;:&quot;MathWorksDeploymentConfig{21b24f2e-5ece-47b0-a968-d291eb125bc4}&quot;}"/>
2 changes: 2 additions & 0 deletions resources/project/root/xRfC_Iq2vKr7PkzRJo-T0mI2Drkd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info ToolboxConfigModel="{&quot;entries&quot;:[{&quot;content&quot;:{&quot;appGalleryLabel&quot;:{&quot;content&quot;:{&quot;categoryID&quot;:&quot;Deployment_Category_e879122a-6b93-4d3b-9a10-49a600882ccb&quot;,&quot;labelID&quot;:&quot;Deployment_ToolboxAppGalleryFiles_e879122a-6b93-4d3b-9a10-49a600882ccb&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.ProjectLabel&quot;,&quot;uuid&quot;:&quot;253e8a7c-20f9-4ebf-add4-32713f0e617b&quot;},&quot;authorName&quot;:&quot;Austin Decker&quot;,&quot;description&quot;:&quot;The UIHTML Debugger is a non-intrusive toolkit designed to bridge the gap between MATLAB and JavaScript development. It provides two essential tools to streamline web-based UI development within MATLAB.&quot;,&quot;gettingStartedGuideLabel&quot;:{&quot;content&quot;:{&quot;categoryID&quot;:&quot;Deployment_Category_e879122a-6b93-4d3b-9a10-49a600882ccb&quot;,&quot;labelID&quot;:&quot;Deployment_GettingStartedGuideFile_e879122a-6b93-4d3b-9a10-49a600882ccb&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.ProjectLabel&quot;,&quot;uuid&quot;:&quot;a2bd07ad-eeaa-4e6a-949a-c75564bf3dd4&quot;},&quot;maxRelease&quot;:&quot;R2025b&quot;,&quot;minRelease&quot;:&quot;R2014b&quot;,&quot;outputFileName&quot;:&quot;uihtml_debugger.mltbx&quot;,&quot;outputFolder&quot;:&quot;release&quot;,&quot;summary&quot;:&quot;MATLAB UIHTML Debugger&quot;,&quot;supportedPlatforms&quot;:[&quot;Windows&quot;,&quot;Linux&quot;,&quot;Mac&quot;,&quot;MatlabOnline&quot;],&quot;toolboxFolder&quot;:&quot;toolbox&quot;,&quot;toolboxImgLabel&quot;:{&quot;content&quot;:{&quot;categoryID&quot;:&quot;Deployment_Category_e879122a-6b93-4d3b-9a10-49a600882ccb&quot;,&quot;labelID&quot;:&quot;Deployment_ToolboxImageFile_e879122a-6b93-4d3b-9a10-49a600882ccb&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.ProjectLabel&quot;,&quot;uuid&quot;:&quot;95c9122e-4ee1-4cf1-be4e-b586d3f56cea&quot;},&quot;toolboxName&quot;:&quot;uihtml_debugger&quot;,&quot;toolboxVersion&quot;:&quot;1.1.3&quot;,&quot;uniqueId&quot;:&quot;35da3f7c-30f8-467f-81c6-e62ba3206be6&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.ToolboxConfiguration&quot;,&quot;uuid&quot;:&quot;0d280020-8b56-44d2-aa8f-04ed650919e6&quot;},{&quot;content&quot;:{},&quot;type&quot;:&quot;deployment.toolbox.model.ProjectStateValidationIssueList&quot;,&quot;uuid&quot;:&quot;46190ffa-3b95-44dd-a9ad-fbc0a96b5b05&quot;}],&quot;packageUris&quot;:[&quot;http://schema.mathworks.com/mf0/deployment_toolbox_model/1.0.0&quot;],&quot;version&quot;:&quot;1.0&quot;}" displayName="uihtml_debugger" lastAccessed="1773989182439" type="Toolbox" uniqueId="e879122a-6b93-4d3b-9a10-49a600882ccb"/>
2 changes: 2 additions & 0 deletions resources/project/root/xRfC_Iq2vKr7PkzRJo-T0mI2Drkp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="MathWorksDeploymentConfig{21b24f2e-5ece-47b0-a968-d291eb125bc4}" type="Files"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="1" type="DIR_SIGNIFIER"/>
29 changes: 29 additions & 0 deletions runTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import matlab.unittest.TestRunner;
import matlab.unittest.TestSuite;
import matlab.unittest.plugins.CodeCoveragePlugin;
import matlab.unittest.plugins.codecoverage.CoberturaFormat;

% Create suite
suite = TestSuite.fromFolder('tests', 'IncludingSubfolders', true);

% Create runner
runner = TestRunner.withTextOutput;

% Configure coverage
sourceFiles = { ...
fullfile(pwd, 'toolbox', 'ConsoleErrorRerouter.m'), ...
fullfile(pwd, 'toolbox', 'UIHTMLDevTools.m') ...
};

mkdir('code-coverage');
coverageFile = fullfile(pwd, 'code-coverage', 'coverage.xml');
plugin = CodeCoveragePlugin.forFile(sourceFiles, ...
'Producing', CoberturaFormat(coverageFile));
runner.addPlugin(plugin);

% Run tests
results = runner.run(suite);

% Output results for CI
display(results);
assertSuccess(results);
2 changes: 1 addition & 1 deletion tests/MockComponent.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef MockComponent < handle
classdef MockComponent < handle & dynamicprops
properties
HTMLSource
end
Expand Down
114 changes: 114 additions & 0 deletions tests/tConsoleErrorRerouter.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ function testConstructorInvalidComponent(testCase)
"ConsoleErrorRerouter:InvalidComponent");
end % function testConstructorInvalidComponent

function testConstructorNoSource(testCase)
testCase.Component.HTMLSource = "";
rerouter = ConsoleErrorRerouter(testCase.Component);
testCase.addTeardown(@() delete(rerouter));
testCase.verifyEqual(string(testCase.Component.HTMLSource), "");
end % function testConstructorNoSource

function testUrlSourceMock(testCase)
mockComp = MockComponent();
mockComp.HTMLSource = "http://example.com";
Expand Down Expand Up @@ -216,8 +223,115 @@ function testPayloadEdgeCases(testCase)
'HTMLEventData', struct('level', 'error', 'message', 'No stack'));
rerouter.onHTMLEventReceived([], goodData);
testCase.verifySubstring(rerouter.LastMessage, "No stack");

% Object payload (instead of struct)
mockPayload = struct('level', 'error', 'message', 'Object message');
objData = struct('HTMLEventName', "ConsoleError", ...
'HTMLEventData', mockPayload);
rerouter.onHTMLEventReceived([], objData);
testCase.verifySubstring(rerouter.LastMessage, "Object message");

% Missing level
badData = struct('HTMLEventName', "ConsoleError", ...
'HTMLEventData', struct('message', 'No level'));
% We can't set LastMessage, but we know it should NOT be "No level"
% It currently is "Object message" from previous step
rerouter.onHTMLEventReceived([], badData);
testCase.verifyEqual(rerouter.LastMessage, "Object message");

% Other event name
otherData = struct('HTMLEventName', "OtherEvent", ...
'HTMLEventData', struct('level', 'error', 'message', 'Ignored'));
rerouter.onHTMLEventReceived([], otherData);
testCase.verifyEqual(rerouter.LastMessage, "Object message");
end % function testPayloadEdgeCases

function testListenerSetupFailure(testCase)
tempDir = tempname;
mkdir(tempDir);
testCase.addTeardown(@() rmdir(tempDir, 's'));
htmlFile = fullfile(tempDir, "test.html");
writelines("<html></html>", htmlFile);

% Create a struct that doesn't support listeners but has valid HTMLSource
mock = struct('HTMLSource', htmlFile);
rerouter = ConsoleErrorRerouter(mock);
testCase.addTeardown(@() delete(rerouter));
testCase.verifyClass(rerouter, "ConsoleErrorRerouter");
end % function testListenerSetupFailure

function testDeleteInvalidComponent(testCase)
rerouter = ConsoleErrorRerouter(testCase.Component);
testCase.Rerouter = rerouter;
delete(testCase.Figure); % Deletes component too
delete(rerouter); % Should not error in removeShim
testCase.Rerouter = [];
end % function testDeleteInvalidComponent

function testOriginalSourceDeleted(testCase)
tempDir = tempname;
mkdir(tempDir);
testCase.addTeardown(@() rmdir(tempDir, 's'));
htmlFile = fullfile(tempDir, "temp.html");
writelines("<html><body></body></html>", htmlFile);

mockComp = MockComponent();
mockComp.HTMLSource = htmlFile;
rerouter = ConsoleErrorRerouter(mockComp);

% Delete original source before rerouter is deleted
delete(htmlFile);

% removeShim should handle this gracefully
delete(rerouter);
testCase.verifyEqual(string(mockComp.HTMLSource), string(htmlFile));
end % function testOriginalSourceDeleted

function testCleanupWarnings(testCase)
if isunix
tempDir = tempname;
mkdir(tempDir);
testCase.addTeardown(@() rmdir(tempDir, 's'));
htmlFile = fullfile(tempDir, "test.html");
writelines("<html><body></body></html>", htmlFile);

mockComp = MockComponent();
mockComp.HTMLSource = htmlFile;
rerouter = ConsoleErrorRerouter(mockComp);

% On Linux, to make delete fail, we make the directory read-only
tempFile = string(mockComp.HTMLSource);
fileattrib(tempDir, '-w');
testCase.addTeardown(@() fileattrib(tempDir, '+w'));

testCase.verifyWarning(@() delete(rerouter), "ConsoleErrorRerouter:FailedCleanup");
end
end % function testCleanupWarnings

function testTempWriteFailure(testCase)
if isunix
% On Unix, we can easily make a directory read-only
tempDir = tempname;
mkdir(tempDir);
testCase.addTeardown(@() rmdir(tempDir, 's'));
htmlFile = fullfile(tempDir, "test.html");
writelines("<html></html>", htmlFile);

% Make dir read-only
fileattrib(tempDir, '-w');
testCase.addTeardown(@() fileattrib(tempDir, '+w'));

mockComp = MockComponent();
mockComp.HTMLSource = htmlFile;
testCase.verifyError(@() ConsoleErrorRerouter(mockComp), ...
"ConsoleErrorRerouter:TempWriteFailure");
else
% On Windows, it's harder to reliably trigger this via attributes,
% so we might skip or use a different trick if needed.
% For now, we'll assume unix coverage in CI is enough or skip.
end
end % function testTempWriteFailure

function testEmptyTargetDir(testCase)
origDir = pwd;
tempDir = tempname;
Expand Down
Loading
Loading