Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/settings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as assert from 'node:assert';
import { pathToFileURL } from 'node:url';

import { describe, it } from 'mocha';

Expand Down Expand Up @@ -66,4 +67,12 @@ describe('Settings', () => {

assert.strictEqual(settings.fs.readdirSync, customReaddirSync);
});

it('should transform URL to string on cwd', () => {
const settings = new Settings({
cwd: new URL(pathToFileURL(process.cwd())),
});

assert.ok(typeof settings.cwd === 'string');
});
});
5 changes: 3 additions & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from 'node:fs';
import { fileURLToPath } from 'node:url';

import type { FileSystemAdapter, Pattern } from './types';

Expand Down Expand Up @@ -42,7 +43,7 @@ export interface Options {
*
* @default process.cwd()
*/
cwd?: string;
cwd?: string | URL;
/**
* Specifies the maximum depth of a read directory relative to the start
* directory.
Expand Down Expand Up @@ -176,7 +177,7 @@ export default class Settings {
this.baseNameMatch = options.baseNameMatch ?? false;
this.braceExpansion = options.braceExpansion ?? true;
this.caseSensitiveMatch = options.caseSensitiveMatch ?? true;
this.cwd = options.cwd ?? process.cwd();
this.cwd = options.cwd instanceof URL ? fileURLToPath(options.cwd) : options.cwd ?? process.cwd();
this.deep = options.deep ?? Number.POSITIVE_INFINITY;
this.dot = options.dot ?? false;
this.extglob = options.extglob ?? true;
Expand Down
6 changes: 4 additions & 2 deletions src/tests/e2e/runner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable mocha/no-setup-in-describe */
import * as assert from 'node:assert';
import { fileURLToPath } from 'node:url';

import * as snapshotIt from 'snap-shot-it';
import snapshotIt from 'snap-shot-it';
import { describe, it } from 'mocha';

import * as fg from '../..';
Expand Down Expand Up @@ -95,8 +96,9 @@ function getTestPatterns(test: Test): Pattern[] {

function getTestTitle(test: Test): string {
// Replacing placeholders to hide absolute paths from snapshots.
const cwd = test.options?.cwd instanceof URL ? fileURLToPath(test.options.cwd) : test.options?.cwd;
const replacements = {
cwd: test.options?.cwd?.replace(CWD, '<root>'),
cwd: cwd?.replace(CWD, '<root>'),
ignore: test.options?.ignore?.map((pattern) => pattern.replace(CWD, '<root>')),
};

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"noFallthroughCasesInSwitch": true,

"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"verbatimModuleSyntax": false,

"downlevelIteration": true,
Expand Down