summaryrefslogtreecommitdiff
path: root/tools/util_test.ts
blob: 79868b4401803e70ccae70f8e109912ffb80a19b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test, assertEqual } from "../js/test_util.ts";
import { findFiles } from "./util.ts";

const testDir = "tools/testdata/find_files_testdata";

// Sorts and replace backslashes with slashes.
const normalize = files => files.map(f => f.replace(/\\/g, "/")).sort();

test(function testFindFiles() {
  const files = findFiles([testDir], [".ts", ".md"]);
  assertEqual(normalize(files), [
    `${testDir}/bar.md`,
    `${testDir}/bar.ts`,
    `${testDir}/foo.md`,
    `${testDir}/foo.ts`,
    `${testDir}/subdir0/bar.ts`,
    `${testDir}/subdir0/foo.ts`,
    `${testDir}/subdir0/subdir0/bar.ts`,
    `${testDir}/subdir0/subdir0/foo.ts`,
    `${testDir}/subdir1/bar.ts`,
    `${testDir}/subdir1/foo.ts`
  ]);
});

test(function testFindFilesDepth() {
  const files = findFiles([testDir], [".ts", ".md"], { depth: 1 });
  assertEqual(normalize(files), [
    `${testDir}/bar.md`,
    `${testDir}/bar.ts`,
    `${testDir}/foo.md`,
    `${testDir}/foo.ts`
  ]);
});

test(function testFindFilesSkip() {
  const files = findFiles([testDir], [".ts", ".md"], {
    skip: ["foo.md", "subdir1"]
  });
  assertEqual(normalize(files), [
    `${testDir}/bar.md`,
    `${testDir}/bar.ts`,
    `${testDir}/foo.ts`,
    `${testDir}/subdir0/bar.ts`,
    `${testDir}/subdir0/foo.ts`,
    `${testDir}/subdir0/subdir0/bar.ts`,
    `${testDir}/subdir0/subdir0/foo.ts`
  ]);
});