Skip to content

Commit

Permalink
fix: fix a bug when Node not found on report
Browse files Browse the repository at this point in the history
  • Loading branch information
wadackel committed May 1, 2022
1 parent 8a2521a commit 4e65658
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
4 changes: 3 additions & 1 deletion packages/acot-reporter-dot/src/index.ts
Expand Up @@ -112,7 +112,9 @@ export default createReporterFactory(({ config, stdout }) => (runner) => {
const selector = res.selector;
const code = pickup(html, selector, { color: false });

meta.push(code, `at "${selector}"`);
if (code != null) {
meta.push(code, `at "${selector}"`);
}
}

if (res.help) {
Expand Down
4 changes: 3 additions & 1 deletion packages/acot-reporter-pretty/src/index.ts
Expand Up @@ -298,7 +298,9 @@ export default createReporterFactory(
const selector = res.selector;
const code = pickup(html, selector, { color: false });

meta.push(code, `at "${selector}"`);
if (code != null) {
meta.push(code, `at "${selector}"`);
}
}

if (res.help) {
Expand Down
6 changes: 4 additions & 2 deletions packages/document/src/doc-result-reporter.ts
Expand Up @@ -64,8 +64,10 @@ export class DocResultReporter {
color: false,
});

meta.push(html);
meta.push(`at "${result.selector}"`);
if (html != null) {
meta.push(html);
meta.push(`at "${result.selector}"`);
}
}

meta.push(origin + generateDocPath(error.code));
Expand Down
10 changes: 8 additions & 2 deletions packages/html-pickup/src/__tests__/index.test.ts
Expand Up @@ -27,14 +27,20 @@ const html = `

describe('pickup', () => {
test('basic', () => {
const output = pickup(html, '#element');
const output = pickup(html, '#element') as string;

expect(output).not.toBe(stripAnsi(output));
expect(stripAnsi(output)).toMatchSnapshot();
});

test('not found', () => {
const output = pickup('', '#element');

expect(output).toBe(null);
});

test('disable color', () => {
const output = pickup(html, '#element', { color: false });
const output = pickup(html, '#element', { color: false }) as string;

expect(output).toBe(stripAnsi(output));
});
Expand Down
6 changes: 5 additions & 1 deletion packages/html-pickup/src/index.ts
Expand Up @@ -112,7 +112,7 @@ export const pickup = (
html: string,
selector: string,
options: Partial<PickupOptions> = {},
): string => {
): string | null => {
const opts = {
truncate: 120,
color: true,
Expand All @@ -127,6 +127,10 @@ export const pickup = (
adapter,
}) as Node[];

if (node == null) {
return null;
}

const output = stringify(node, chk);

return truncate(output, opts.truncate);
Expand Down

0 comments on commit 4e65658

Please sign in to comment.