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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Result, NeedAnalysis, Passed, Scenario } from './types.js';

import { importScenarios, type Violation } from '@d-zero/a11y-check-core';
import { createChildProcess } from '@d-zero/puppeteer-dealer';
import {
beforePageScan,
Expand All @@ -9,8 +10,6 @@ import {
import { Cache } from '@d-zero/shared/cache';
import c from 'ansi-colors';

import { importScenarios, type Violation } from '@d-zero/a11y-check-core';

export type ChildProcessParams = {
readonly scenarios: readonly Scenario[];
readonly cacheDir: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import type { DealOptions } from '@d-zero/dealer';

import path from 'node:path';

import { importScenarios, type Violation } from '@d-zero/a11y-check-core';
import { createProcess, deal } from '@d-zero/puppeteer-dealer';
import c from 'ansi-colors';

import { cleanResults } from './clean-results.js';

import { importScenarios, type Violation } from '@d-zero/a11y-check-core';

/**
*
* @param urlList
Expand Down
68 changes: 68 additions & 0 deletions packages/@d-zero/shared/src/path-list-to-tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,74 @@ test('Options: currentPath', () => {
});
});

test('Options: currentPath does not false-positive isAncestor on sibling prefix', () => {
const result = pathListToTree(
['/', '/foo/index.html', '/foo/bar.html', '/foo/bar_baz.html'],
{
currentPath: '/foo/bar_baz.html',
},
);

const foo = result.children[0]!;
expect(foo.stem).toBe('/foo/');
expect(foo.isAncestor).toBe(true);

const bar = foo.children.find((c) => c.stem === '/foo/bar')!;
expect(bar.isAncestor).toBe(false);

const barBaz = foo.children.find((c) => c.stem === '/foo/bar_baz')!;
expect(barBaz.current).toBe(true);
});

test('Options: currentPath file is not treated as child of same-prefix directory', () => {
const result = pathListToTree(['/', '/foo/', '/foo/bar/', '/foo/bar.html'], {
currentPath: '/foo/bar.html',
});

const foo = result.children[0]!;
expect(foo.stem).toBe('/foo/');
expect(foo.isAncestor).toBe(true);

const fooBarDir = foo.children.find((c) => c.stem === '/foo/bar/')!;
expect(fooBarDir.isAncestor).toBe(false);

const fooBarFile = foo.children.find((c) => c.stem === '/foo/bar')!;
expect(fooBarFile.current).toBe(true);
});

test('Options: currentPath as root marks root current and no ancestors', () => {
const result = pathListToTree(['/', '/a/', '/b.html'], {
currentPath: '/',
});

expect(result.current).toBe(true);
expect(result.isAncestor).toBe(false);
expect(result.children[0]!.isAncestor).toBe(false);
expect(result.children[1]!.isAncestor).toBe(false);
});

test('Options: currentPath deep nesting marks all ancestor directories', () => {
const result = pathListToTree(['/', '/a/', '/a/b/', '/a/b/c.html'], {
currentPath: '/a/b/c.html',
});

expect(result.isAncestor).toBe(true);
expect(result.current).toBe(false);

const a = result.children[0]!;
expect(a.stem).toBe('/a/');
expect(a.isAncestor).toBe(true);

const ab = a.children[0]!;
expect(ab.stem).toBe('/a/b/');
expect(ab.isAncestor).toBe(true);

const abc = ab.children[0]!;
expect(abc.stem).toBe('/a/b/c');
expect(abc.current).toBe(true);
expect(abc.isAncestor).toBe(false);
});

test('Options: addMetaData adds meta to every node', () => {
const result = pathListToTree(['/', '/a/', '/a/b', '/a/c/'], {
addMetaData: (node) => ({
Expand Down
7 changes: 5 additions & 2 deletions packages/@d-zero/shared/src/path-list-to-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type Node<MetaData = Record<string, unknown>> = {
depth: number;
/** True if this node is the current path. */
current: boolean;
/** True if the current path is under this node. */
/** True if this node is a directory ancestor of the current path. Only directory nodes (stem ending with '/') can be ancestors. */
isAncestor: boolean;
/** Present when the node was created as a virtual parent (no real file). */
virtual?: true;
Expand Down Expand Up @@ -118,7 +118,10 @@ export function pathListToTree<MetaData = Record<string, unknown>>(
stem: url.stem,
depth: url.depth,
current,
isAncestor: !current && currentPath ? currentPath.startsWith(url.stem) : false,
isAncestor:
!current && currentPath
? url.stem.endsWith('/') && currentPath.startsWith(url.stem)
: false,
children: [],
});
}
Expand Down
Loading