|
1 | 1 | // SPDX-License-Identifier: Apache-2.0 |
2 | 2 |
|
3 | | -import { test } from 'node:test'; |
4 | | -import assert from 'node:assert/strict'; |
5 | | -import { headerSource, listFiles } from '../files.mjs'; |
6 | | -import { makeRepo, writeFiles } from './repo.mjs'; |
| 3 | +import { test } from "node:test"; |
| 4 | +import assert from "node:assert/strict"; |
| 5 | +import { headerSource, listFiles } from "../files.mjs"; |
| 6 | +import { makeRepo, writeFiles } from "./repo.mjs"; |
7 | 7 |
|
8 | 8 | // Listing only looks at paths, so every file can be empty. |
9 | 9 | function repo(paths) { |
10 | | - return makeRepo(Object.fromEntries(paths.map((path) => [path, '']))); |
| 10 | + return makeRepo(Object.fromEntries(paths.map((path) => [path, ""]))); |
11 | 11 | } |
12 | 12 |
|
13 | 13 | function sorted(list) { |
14 | 14 | return [...list].sort(); |
15 | 15 | } |
16 | 16 |
|
17 | | -test('*.py matches at root and at depth', () => { |
18 | | - const cwd = repo(['a.py', 'pkg/b.py', 'pkg/sub/c.py', 'README.md']); |
19 | | - const files = listFiles({ include: ['*.py'], cwd }); |
20 | | - assert.deepEqual(sorted(files), ['a.py', 'pkg/b.py', 'pkg/sub/c.py']); |
| 17 | +test("*.py matches at root and at depth", () => { |
| 18 | + const cwd = repo(["a.py", "pkg/b.py", "pkg/sub/c.py", "README.md"]); |
| 19 | + const files = listFiles({ include: ["*.py"], cwd }); |
| 20 | + assert.deepEqual(sorted(files), ["a.py", "pkg/b.py", "pkg/sub/c.py"]); |
21 | 21 | }); |
22 | 22 |
|
23 | | -test('Dockerfile* matches root-level files only', () => { |
24 | | - const cwd = repo(['Dockerfile', 'Dockerfile.dev', 'deploy/Dockerfile']); |
25 | | - const files = listFiles({ include: ['Dockerfile*'], cwd }); |
26 | | - assert.deepEqual(sorted(files), ['Dockerfile', 'Dockerfile.dev']); |
| 23 | +test("Dockerfile* matches root-level files only", () => { |
| 24 | + const cwd = repo(["Dockerfile", "Dockerfile.dev", "deploy/Dockerfile"]); |
| 25 | + const files = listFiles({ include: ["Dockerfile*"], cwd }); |
| 26 | + assert.deepEqual(sorted(files), ["Dockerfile", "Dockerfile.dev"]); |
27 | 27 | }); |
28 | 28 |
|
29 | | -test('*/Dockerfile* matches nested files only', () => { |
30 | | - const cwd = repo(['Dockerfile', 'deploy/Dockerfile', 'deploy/Dockerfile.prod']); |
31 | | - const files = listFiles({ include: ['*/Dockerfile*'], cwd }); |
32 | | - assert.deepEqual(sorted(files), ['deploy/Dockerfile', 'deploy/Dockerfile.prod']); |
| 29 | +test("*/Dockerfile* matches nested files only", () => { |
| 30 | + const cwd = repo([ |
| 31 | + "Dockerfile", |
| 32 | + "deploy/Dockerfile", |
| 33 | + "deploy/Dockerfile.prod", |
| 34 | + ]); |
| 35 | + const files = listFiles({ include: ["*/Dockerfile*"], cwd }); |
| 36 | + assert.deepEqual(sorted(files), [ |
| 37 | + "deploy/Dockerfile", |
| 38 | + "deploy/Dockerfile.prod", |
| 39 | + ]); |
33 | 40 | }); |
34 | 41 |
|
35 | | -test('scripts/bin/* matches an extensionless file', () => { |
36 | | - const cwd = repo(['scripts/bin/run', 'scripts/other']); |
37 | | - const files = listFiles({ include: ['scripts/bin/*'], cwd }); |
38 | | - assert.deepEqual(files, ['scripts/bin/run']); |
| 42 | +test("scripts/bin/* matches an extensionless file", () => { |
| 43 | + const cwd = repo(["scripts/bin/run", "scripts/other"]); |
| 44 | + const files = listFiles({ include: ["scripts/bin/*"], cwd }); |
| 45 | + assert.deepEqual(files, ["scripts/bin/run"]); |
39 | 46 | }); |
40 | 47 |
|
41 | | -test('excludes remove matching files', () => { |
42 | | - const cwd = repo(['a.py', 'third_party/x.py', 'proto/m_pb2.py']); |
| 48 | +test("excludes remove matching files", () => { |
| 49 | + const cwd = repo(["a.py", "third_party/x.py", "proto/m_pb2.py"]); |
43 | 50 | const files = listFiles({ |
44 | | - include: ['*.py'], |
45 | | - exclude: ['third_party/*', '*_pb2.py'], |
| 51 | + include: ["*.py"], |
| 52 | + exclude: ["third_party/*", "*_pb2.py"], |
46 | 53 | cwd, |
47 | 54 | }); |
48 | | - assert.deepEqual(files, ['a.py']); |
| 55 | + assert.deepEqual(files, ["a.py"]); |
49 | 56 | }); |
50 | 57 |
|
51 | | -test('exclude patterns keep their own pathspec magic', () => { |
52 | | - const cwd = repo(['src/z.go', 'vendor/y.go', 'vendor/a/x.go']); |
53 | | - const files = listFiles({ include: ['*.go'], exclude: [':(glob)vendor/**'], cwd }); |
54 | | - assert.deepEqual(files, ['src/z.go']); |
| 58 | +test("exclude patterns keep their own pathspec magic", () => { |
| 59 | + const cwd = repo(["src/z.go", "vendor/y.go", "vendor/a/x.go"]); |
| 60 | + const files = listFiles({ |
| 61 | + include: ["*.go"], |
| 62 | + exclude: [":(glob)vendor/**"], |
| 63 | + cwd, |
| 64 | + }); |
| 65 | + assert.deepEqual(files, ["src/z.go"]); |
55 | 66 | }); |
56 | 67 |
|
57 | | -test('untracked files are ignored', () => { |
58 | | - const cwd = repo(['a.py']); |
59 | | - writeFiles(cwd, { 'b.py': '' }); |
60 | | - assert.deepEqual(listFiles({ include: ['*.py'], cwd }), ['a.py']); |
| 68 | +test("untracked files are ignored", () => { |
| 69 | + const cwd = repo(["a.py"]); |
| 70 | + writeFiles(cwd, { "b.py": "" }); |
| 71 | + assert.deepEqual(listFiles({ include: ["*.py"], cwd }), ["a.py"]); |
61 | 72 | }); |
62 | 73 |
|
63 | | -test('multiple include patterns combine', () => { |
64 | | - const cwd = repo(['a.py', 'b.mjs', 'c.md']); |
65 | | - const files = listFiles({ include: ['*.py', '*.mjs'], cwd }); |
66 | | - assert.deepEqual(sorted(files), ['a.py', 'b.mjs']); |
| 74 | +test("multiple include patterns combine", () => { |
| 75 | + const cwd = repo(["a.py", "b.mjs", "c.md"]); |
| 76 | + const files = listFiles({ include: ["*.py", "*.mjs"], cwd }); |
| 77 | + assert.deepEqual(sorted(files), ["a.py", "b.mjs"]); |
67 | 78 | }); |
68 | 79 |
|
69 | | -test('headerSource returns the sidecar when it exists', () => { |
70 | | - const cwd = repo(['x.json', 'x.json.license']); |
71 | | - assert.equal(headerSource('x.json', cwd), 'x.json.license'); |
| 80 | +test("headerSource returns the sidecar when it exists", () => { |
| 81 | + const cwd = repo(["x.json", "x.json.license"]); |
| 82 | + assert.equal(headerSource("x.json", cwd), "x.json.license"); |
72 | 83 | }); |
73 | 84 |
|
74 | | -test('headerSource returns the path when there is no sidecar', () => { |
75 | | - const cwd = repo(['y.json']); |
76 | | - assert.equal(headerSource('y.json', cwd), 'y.json'); |
| 85 | +test("headerSource returns the path when there is no sidecar", () => { |
| 86 | + const cwd = repo(["y.json"]); |
| 87 | + assert.equal(headerSource("y.json", cwd), "y.json"); |
77 | 88 | }); |
78 | 89 |
|
79 | | -test('headerSource works for nested paths', () => { |
80 | | - const cwd = repo(['conf/x.json', 'conf/x.json.license']); |
81 | | - assert.equal(headerSource('conf/x.json', cwd), 'conf/x.json.license'); |
| 90 | +test("headerSource works for nested paths", () => { |
| 91 | + const cwd = repo(["conf/x.json", "conf/x.json.license"]); |
| 92 | + assert.equal(headerSource("conf/x.json", cwd), "conf/x.json.license"); |
82 | 93 | }); |
0 commit comments