Skip to content

Commit

Permalink
test(lib): adjust coverage
Browse files Browse the repository at this point in the history
Signed-off-by: euberdeveloper <euberdeveloper@gmail.com>
  • Loading branch information
euberdeveloper committed Jun 12, 2024
1 parent b2ad4ee commit a8e7f8e
Showing 1 changed file with 43 additions and 22 deletions.
65 changes: 43 additions & 22 deletions source/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ function postSortFilesFirst(x: Dree, y: Dree): number {

function postSortFiles(nodes: Dree[], postSortOption: boolean | PostSortMethodPredefined | PostSortDiscriminator): Dree[] {
if (!postSortOption) {
/* c8 ignore next */
return nodes;
}

Expand Down Expand Up @@ -527,7 +528,6 @@ function _scan<Node extends Dree = Dree>(root: string, path: string, depth: numb
stat = statSync(path);
}
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
Expand All @@ -539,15 +539,16 @@ function _scan<Node extends Dree = Dree>(root: string, path: string, depth: numb
try {
lstat = lstatSync(path);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore stop */
const symbolicLink = lstat.isSymbolicLink();
const type = stat.isFile() ? Type.FILE : Type.DIRECTORY;

Expand Down Expand Up @@ -586,15 +587,16 @@ function _scan<Node extends Dree = Dree>(root: string, path: string, depth: numb
files = readdirSync(path);
files = sortFiles(files, options.sorted);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore stop */
if (options.emptyDirectory) {
dirTree.isEmpty = !files.length
}
Expand Down Expand Up @@ -657,23 +659,25 @@ function _scan<Node extends Dree = Dree>(root: string, path: string, depth: numb
try {
data = readFileSync(path);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
hash.update(data);
const hashEncoding = options.hashEncoding as BinaryToTextEncoding;
dirTree.hash = hash.digest(hashEncoding);
}
break;
/* c8 ignore start */
default:
/* c8 ignore next */
return null;
/* c8 ignore end */
}

if (onFile && type === Type.FILE) {
Expand Down Expand Up @@ -706,28 +710,30 @@ async function _scanAsync<Node extends Dree = Dree>(root: string, path: string,
try {
stat = await statAsync(path);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
let lstat: Stats;
try {
lstat = await lstatAsync(path);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
const symbolicLink = lstat.isSymbolicLink();
const type = stat.isFile() ? Type.FILE : Type.DIRECTORY;

Expand Down Expand Up @@ -766,15 +772,16 @@ async function _scanAsync<Node extends Dree = Dree>(root: string, path: string,
files = await readdirAsync(path);
files = sortFiles(files, options.sorted);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
if (options.emptyDirectory) {
dirTree.isEmpty = !files.length
}
Expand Down Expand Up @@ -836,23 +843,25 @@ async function _scanAsync<Node extends Dree = Dree>(root: string, path: string,
try {
data = await readFileAsync(path);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
hash.update(data);
const hashEncoding = options.hashEncoding as BinaryToTextEncoding;
dirTree.hash = hash.digest(hashEncoding);
}
break;
/* c8 ignore start */
default:
/* c8 ignore next */
return null;
/* c8 ignore end */
}

if (onFile && type === Type.FILE) {
Expand Down Expand Up @@ -895,28 +904,30 @@ function _parse(root: string, children: string[], prefix: string, options: Parse
try {
stat = statSync(child);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
let lstat: Stats;
try {
lstat = lstatSync(child);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
const symbolicLink = lstat.isSymbolicLink();
const type = stat.isFile() ? Type.FILE : Type.DIRECTORY;

Expand All @@ -941,15 +952,16 @@ function _parse(root: string, children: string[], prefix: string, options: Parse
children = readdirSync(child).map(file => resolve(child, file));
children = sortFiles(children, options.sorted);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
result += children.length ? _parse(root, children, newPrefix, options, depth + 1) : '';
}

Expand Down Expand Up @@ -982,28 +994,30 @@ async function _parseAsync(root: string, children: string[], prefix: string, opt
try {
stat = await statAsync(child);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
let lstat: Stats;
try {
lstat = await lstatAsync(child);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
const symbolicLink = lstat.isSymbolicLink();
const type = stat.isFile() ? Type.FILE : Type.DIRECTORY;

Expand All @@ -1028,15 +1042,16 @@ async function _parseAsync(root: string, children: string[], prefix: string, opt
children = (await readdirAsync(child)).map(file => resolve(child, file));
children = sortFiles(children, options.sorted);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (options.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
result += children.length ? (await _parseAsync(root, children, newPrefix, options, depth + 1)) : '';
}

Expand Down Expand Up @@ -1136,28 +1151,30 @@ export function parse(path: string, options?: ParseOptions): string {
try {
stat = statSync(root);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (opt.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
let lstat: Stats;
try {
lstat = lstatSync(root);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (opt.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
const symbolicLink = lstat.isSymbolicLink();

if ((opt.followLinks || !symbolicLink) && stat.isDirectory()) {
Expand All @@ -1166,15 +1183,16 @@ export function parse(path: string, options?: ParseOptions): string {
children = readdirSync(root).map(file => resolve(root, file));
children = sortFiles(children, opt.sorted);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (opt.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
result += children.length ? _parse(root, children, '\n ', opt, 1) : '';
}

Expand All @@ -1199,28 +1217,30 @@ export async function parseAsync(path: string, options?: ParseOptions): Promise<
try {
stat = await statAsync(root);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (opt.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
let lstat: Stats;
try {
lstat = await lstatAsync(root);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (opt.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
const symbolicLink = lstat.isSymbolicLink();

if ((opt.followLinks || !symbolicLink) && stat.isDirectory()) {
Expand All @@ -1229,15 +1249,16 @@ export async function parseAsync(path: string, options?: ParseOptions): Promise<
children = (await readdirAsync(root)).map(file => resolve(root, file));
children = sortFiles(children, opt.sorted);
}
/* c8 ignore start */
catch (exception) {
/* c8 ignore next */
if (opt.skipErrors) {
return null;
}
else {
throw exception;
}
}
/* c8 ignore end */
result += children.length ? (await _parseAsync(root, children, '\n ', opt, 1)) : '';
}

Expand Down

0 comments on commit a8e7f8e

Please sign in to comment.