Skip to content

Commit 3b9beb3

Browse files
committed
fix test failure
1 parent 4603593 commit 3b9beb3

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

src/buildSummary.unit.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,9 @@ describe("processAndAddBuildSummary", () => {
176176
buildSummary.processAndAddBuildSummary("/nonexistent/directory/path", "my-action");
177177

178178
expect(core.summary.addTable).not.toHaveBeenCalled();
179-
expect(consoleSpy).toHaveBeenCalledWith(
180-
expect.stringContaining(
181-
"An error occurred while finding build summary file(s) in directory",
182-
),
183-
expect.any(Error),
179+
expect(consoleSpy).toHaveBeenCalled();
180+
expect(consoleSpy.mock.calls[0][0] as string).toContain(
181+
"An error occurred while finding build summary file(s) in directory",
184182
);
185183
consoleSpy.mockRestore();
186184
});

tests/tParallelizableBuildSummaryPlugin.m

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ function setupPath(testCase)
2020
methods (TestMethodSetup)
2121
function createPlugin(testCase)
2222
import matlab.unittest.fixtures.WorkingFolderFixture;
23-
23+
import matlab.unittest.fixtures.EnvironmentVariableFixture;
24+
2425
testCase.applyFixture(WorkingFolderFixture);
2526
testCase.TempFolder = pwd();
27+
testCase.applyFixture(EnvironmentVariableFixture("MW_GENERATE_JOB_SUMMARY", "true"));
28+
testCase.applyFixture(EnvironmentVariableFixture("GITHUB_ACTION", "my-action"));
2629

2730
testCase.Plugin = ParallelizableBuildSummaryPlugin(TempFolder=testCase.TempFolder);
2831
testCase.Runner = matlab.buildtool.BuildRunner.withNoPlugins();
@@ -38,8 +41,8 @@ function runningBuildCreatesSummaryArtifact(testCase)
3841

3942
testCase.Runner.run(plan, ["t1", "t2"]);
4043

41-
name = "buildSummary" + getenv("GITHUB_RUN_ID") + ".json";
42-
testCase.verifyTrue(isfile(fullfile(testCase.TempFolder, name)));
44+
f = findBuildSummaryFile(testCase.TempFolder);
45+
testCase.verifyNotEmpty(f);
4346
end
4447

4548
function runningBuildCreatesSummaryArtifactWithExpectedTasks(testCase)
@@ -49,9 +52,8 @@ function runningBuildCreatesSummaryArtifactWithExpectedTasks(testCase)
4952

5053
testCase.Runner.run(plan, ["t1", "t2"]);
5154

52-
name = "buildSummary" + getenv("GITHUB_RUN_ID") + ".json";
53-
f = fullfile(testCase.TempFolder, name);
54-
testCase.assertTrue(isfile(f));
55+
f = findBuildSummaryFile(testCase.TempFolder);
56+
testCase.assertTrue(~isempty(f));
5557

5658
s = readstruct(f);
5759

@@ -67,9 +69,8 @@ function summaryArtifactStatusesAreCorrect(testCase)
6769

6870
testCase.Runner.run(plan, ["t1", "t2"]);
6971

70-
name = "buildSummary" + getenv("GITHUB_RUN_ID") + ".json";
71-
f = fullfile(testCase.TempFolder, name);
72-
testCase.assertTrue(isfile(f));
72+
f = findBuildSummaryFile(testCase.TempFolder);
73+
testCase.assertTrue(~isempty(f));
7374

7475
s = readstruct(f);
7576

@@ -88,10 +89,8 @@ function runningBuildCreatesSummaryForTaskGroups(testCase)
8889

8990
testCase.Runner.run(plan, "g:t");
9091

91-
name = "buildSummary" + getenv("GITHUB_RUN_ID") + ".json";
92-
f = fullfile(testCase.TempFolder, name);
93-
94-
testCase.assertTrue(isfile(f));
92+
f = findBuildSummaryFile(testCase.TempFolder);
93+
testCase.assertTrue(~isempty(f));
9594

9695
s = readstruct(f);
9796

@@ -109,3 +108,12 @@ function runningBuildCreatesSummaryForTaskGroups(testCase)
109108
function task = Task(varargin)
110109
task = matlab.buildtool.Task(varargin{:});
111110
end
111+
112+
function f = findBuildSummaryFile(folder)
113+
files = dir(fullfile(folder, "buildSummary*.json"));
114+
if isempty(files)
115+
f = "";
116+
else
117+
f = fullfile(folder, files(1).name);
118+
end
119+
end

0 commit comments

Comments
 (0)