|
1 |
| -import { window, Selection, workspace, Range, Position, Uri } from 'vscode'; |
| 1 | +import { Position, Range, Selection, Uri, window, workspace } from 'vscode'; |
2 | 2 | import fs from 'fs';
|
3 | 3 | import path from 'path';
|
4 | 4 |
|
5 | 5 | import {
|
6 |
| - createFile, |
7 |
| - rndName, |
8 | 6 | cleanWorkspace,
|
9 | 7 | closeEditorsAndCleanWorkspace,
|
| 8 | + createFile, |
10 | 9 | openTextDocument,
|
| 10 | + rndName, |
11 | 11 | toPlainObject,
|
| 12 | + updateConfigProperty, |
12 | 13 | } from '../test/testUtils';
|
| 14 | +import * as utils from './utils'; |
13 | 15 | import {
|
| 16 | + addCachedRefs, |
| 17 | + cacheRefs, |
| 18 | + cacheUris, |
| 19 | + cacheWorkspace, |
| 20 | + cleanWorkspaceCache, |
14 | 21 | containsImageExt,
|
15 | 22 | containsMarkdownExt,
|
16 | 23 | containsOtherKnownExts,
|
17 | 24 | containsUnknownExt,
|
18 |
| - fsPathToRef, |
19 |
| - trimLeadingSlash, |
20 |
| - trimTrailingSlash, |
21 |
| - trimSlashes, |
22 |
| - isLongRef, |
23 |
| - normalizeSlashes, |
24 |
| - getWorkspaceFolder, |
25 |
| - getWorkspaceCache, |
26 |
| - getMemoConfigProperty, |
27 |
| - matchAll, |
28 |
| - cacheWorkspace, |
29 |
| - cacheUris, |
30 |
| - cacheRefs, |
31 |
| - addCachedRefs, |
32 |
| - removeCachedRefs, |
33 |
| - cleanWorkspaceCache, |
34 |
| - getRefUriUnderCursor, |
35 |
| - getReferenceAtPosition, |
| 25 | + ensureDirectoryExists, |
36 | 26 | escapeForRegExp,
|
| 27 | + extractDanglingRefs, |
37 | 28 | extractEmbedRefs,
|
38 |
| - parseRef, |
39 |
| - replaceRefs, |
| 29 | + extractExt, |
| 30 | + findAllUrisWithUnknownExts, |
| 31 | + findDanglingRefsByFsPath, |
| 32 | + findFilesByExts, |
| 33 | + findNonIgnoredFiles, |
40 | 34 | findReferences,
|
| 35 | + findUriByRef, |
| 36 | + fsPathToRef, |
| 37 | + getConfigProperty, |
41 | 38 | getFileUrlForMarkdownPreview,
|
42 | 39 | getImgUrlForMarkdownPreview,
|
| 40 | + getMemoConfigProperty, |
| 41 | + getReferenceAtPosition, |
| 42 | + getRefUriUnderCursor, |
| 43 | + getWorkspaceCache, |
| 44 | + getWorkspaceFolder, |
| 45 | + isLongRef, |
43 | 46 | isUncPath,
|
44 |
| - findFilesByExts, |
45 |
| - findAllUrisWithUnknownExts, |
46 |
| - extractExt, |
47 |
| - findUriByRef, |
48 |
| - ensureDirectoryExists, |
49 |
| - extractDanglingRefs, |
50 |
| - findDanglingRefsByFsPath, |
| 47 | + matchAll, |
| 48 | + normalizeSlashes, |
| 49 | + parseRef, |
| 50 | + removeCachedRefs, |
| 51 | + replaceRefs, |
| 52 | + trimLeadingSlash, |
| 53 | + trimSlashes, |
| 54 | + trimTrailingSlash, |
51 | 55 | } from './utils';
|
52 |
| -import * as utils from './utils'; |
53 | 56 |
|
54 | 57 | describe('containsImageExt()', () => {
|
55 | 58 | test.each(['png', 'jpg', 'jpeg', 'gif'])(
|
@@ -1534,3 +1537,65 @@ describe('findDanglingRefsByFsPath()', () => {
|
1534 | 1537 | expect(await findDanglingRefsByFsPath(getWorkspaceCache().markdownUris)).toEqual({});
|
1535 | 1538 | });
|
1536 | 1539 | });
|
| 1540 | + |
| 1541 | +describe('findNonIgnoredFiles()', () => { |
| 1542 | + beforeEach(closeEditorsAndCleanWorkspace); |
| 1543 | + |
| 1544 | + afterEach(closeEditorsAndCleanWorkspace); |
| 1545 | + |
| 1546 | + it('should find non-ignored files', async () => { |
| 1547 | + const prevConfig = getConfigProperty('search.exclude', {}); |
| 1548 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 1549 | + await updateConfigProperty('search.exclude', { '**/search-ignored': true }); |
| 1550 | + |
| 1551 | + const allowedName = rndName(); |
| 1552 | + const ignoredName = rndName(); |
| 1553 | + |
| 1554 | + await createFile(`${allowedName}.md`); |
| 1555 | + await createFile(`search-ignored/some-package/${ignoredName}.md`); |
| 1556 | + |
| 1557 | + const files = await findNonIgnoredFiles('**/*.md'); |
| 1558 | + |
| 1559 | + expect(files).toHaveLength(1); |
| 1560 | + expect(path.basename(files[0].fsPath)).toBe(`${allowedName}.md`); |
| 1561 | + |
| 1562 | + await updateConfigProperty('search.exclude', prevConfig); |
| 1563 | + }); |
| 1564 | + |
| 1565 | + describe('when exclude param passed explicitly', () => { |
| 1566 | + it('should find non-ignored files', async () => { |
| 1567 | + const allowedName = rndName(); |
| 1568 | + const ignoredName = rndName(); |
| 1569 | + |
| 1570 | + await createFile(`${allowedName}.md`); |
| 1571 | + await createFile(`search-ignored/some-package/${ignoredName}.md`); |
| 1572 | + |
| 1573 | + const files = await findNonIgnoredFiles('**/*.md', '**/search-ignored'); |
| 1574 | + |
| 1575 | + expect(files).toHaveLength(1); |
| 1576 | + expect(path.basename(files[0].fsPath)).toBe(`${allowedName}.md`); |
| 1577 | + }); |
| 1578 | + }); |
| 1579 | + |
| 1580 | + describe('when exclude param passed explicitly and search.exclude set', () => { |
| 1581 | + it('should find non-ignored files', async () => { |
| 1582 | + const prevConfig = getConfigProperty('search.exclude', {}); |
| 1583 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 1584 | + await updateConfigProperty('search.exclude', { '**/search-ignored': true }); |
| 1585 | + |
| 1586 | + const allowedName = rndName(); |
| 1587 | + const ignoredName = rndName(); |
| 1588 | + |
| 1589 | + await createFile(`${allowedName}.md`); |
| 1590 | + await createFile(`search-ignored/some-package/${ignoredName}.md`); |
| 1591 | + await createFile(`search-ignored-2/some-package/${ignoredName}.md`); |
| 1592 | + |
| 1593 | + const files = await findNonIgnoredFiles('**/*.md', '**/search-ignored-2'); |
| 1594 | + |
| 1595 | + expect(files).toHaveLength(1); |
| 1596 | + expect(path.basename(files[0].fsPath)).toBe(`${allowedName}.md`); |
| 1597 | + |
| 1598 | + await updateConfigProperty('search.exclude', prevConfig); |
| 1599 | + }); |
| 1600 | + }); |
| 1601 | +}); |
0 commit comments