Skip to content
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

Fix support for boolean value to junitReport option #937

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
99 changes: 99 additions & 0 deletions node-src/tasks/report.test.ts
@@ -0,0 +1,99 @@
import reportBuilder from 'junit-report-builder';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { generateReport } from './report';
import path from 'path';

const log = { error: vi.fn(), info: vi.fn() };
const mockTests = [
{
status: 'ACCEPTED',
result: '',
spec: { name: '', component: { name: '' } },
parameters: { viewportIsDefault: true, viewport: 1080 },
mode: { name: 'Beast Mode' },
},
{
status: 'PENDING',
result: '',
spec: { name: '', component: { name: '' } },
parameters: { viewportIsDefault: true, viewport: 1080 },
mode: { name: 'Beast Mode' },
},
{
status: 'DENIED',
result: '',
spec: { name: '', component: { name: '' } },
parameters: { viewportIsDefault: false, viewport: 1080 },
mode: { name: 'Beast Mode' },
},
{
status: 'BROKEN',
result: '',
spec: { name: '', component: { name: '' } },
parameters: { viewportIsDefault: true, viewport: 1080 },
mode: { name: null },
},
{
status: 'FAILED',
result: '',
spec: { name: '', component: { name: '' } },
parameters: { viewportIsDefault: false, viewport: 1080 },
mode: { name: null },
},
];

vi.spyOn(reportBuilder, 'writeTo').mockImplementation(vi.fn());

describe('generateRport', () => {
const client = { runQuery: vi.fn(), setAuthorization: vi.fn() };
const build = {
app: { repository: { provider: 'github' } },
number: 1,
reportToken: 'report-token',
};
beforeEach(() => {
vi.resetAllMocks();
client.runQuery.mockReturnValue({
app: {
build: {
number: 1,
status: 'PASSED',
createdAt: 0,
completedAt: 0,
webUrl: 'https://google.com',
storybookUrl: 'https://storybook.js.org',
tests: mockTests,
},
},
});
});
it('sucessfully generates report when passed a string', async () => {
const ctx = {
client,
log,
options: {
junitReport: 'tests-file.xml',
},
build,
} as any;
await generateReport(ctx);
expect(reportBuilder.writeTo).toHaveBeenCalledWith(
path.join(__dirname, '../../tests-file.xml')
);
});

it('sucessfully generates report when passed a boolean equal to true', async () => {
const ctx = {
client,
log,
options: {
junitReport: true,
},
build,
} as any;
await generateReport(ctx);
expect(reportBuilder.writeTo).toHaveBeenCalledWith(
path.join(__dirname, '../../chromatic-build-1.xml')
);
});
});
6 changes: 5 additions & 1 deletion node-src/tasks/report.ts
Expand Up @@ -74,7 +74,11 @@ export const generateReport = async (ctx: Context) => {
const { junitReport } = ctx.options;
const { number: buildNumber, reportToken } = ctx.build;

ctx.reportPath = path.resolve(junitReport.replace(/{buildNumber}/g, String(buildNumber)));
const file =
typeof junitReport === 'boolean' && junitReport
? 'chromatic-build-{buildNumber}.xml'
: junitReport;
ctx.reportPath = path.resolve(file.replace(/{buildNumber}/g, String(buildNumber)));

const {
app: { build },
Expand Down