|
1 | 1 | import { describe, expect, test } from 'vitest'
|
2 |
| -import { groupTargetsByDirectoryTree } from './utils' |
| 2 | +import { isSubdirectoryOrEqual, groupTargetsByDirectoryTree } from './utils' |
3 | 3 | import path from 'node:path'
|
| 4 | +import { fileURLToPath } from 'node:url' |
| 5 | +import os from 'node:os' |
| 6 | + |
| 7 | +const _dirname = path.dirname(fileURLToPath(import.meta.url)) |
| 8 | +const isWindows = os.platform() === 'win32' |
| 9 | + |
| 10 | +describe('isSubdirectoryOrEqual', () => { |
| 11 | + const cases: readonly [a: string, b: string, expected: boolean][] = [ |
| 12 | + ['./', '.', true], |
| 13 | + ['./', './', true], |
| 14 | + ['.', './', true], |
| 15 | + ['./index.ts', './', true], |
| 16 | + ['./foo/', './', true], |
| 17 | + ['./foo/bar', './', true], |
| 18 | + ['./foo/bar.js', './', true], |
| 19 | + ['..', './', false], |
| 20 | + ['../', './', false], |
| 21 | + ['../test', './', false], |
| 22 | + ['../test/', './', false], |
| 23 | + ...(isWindows |
| 24 | + ? ([ |
| 25 | + ['C:/', 'C:/', true], |
| 26 | + ['C:\\', 'C:/', true], |
| 27 | + ['C:/', 'D:/', false], |
| 28 | + ['C:\\', 'D:/', false] |
| 29 | + ] satisfies readonly [string, string, boolean][]) |
| 30 | + : []) |
| 31 | + ] |
| 32 | + |
| 33 | + const resolve = (p: string) => path.resolve(_dirname, p) |
| 34 | + |
| 35 | + for (const [a, b, expected] of cases) { |
| 36 | + test(`isSubdirectoryOrEqual(${a}, ${b})`, () => { |
| 37 | + expect(isSubdirectoryOrEqual(resolve(a), resolve(b))).toBe(expected) |
| 38 | + }) |
| 39 | + } |
| 40 | +}) |
4 | 41 |
|
5 | 42 | describe('groupTargetsByDirectoryTree', () => {
|
6 | 43 | const defineCase = (input: string[], expected: string[][]) => ({
|
|
0 commit comments