-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ensure schematic utils are tested properly
- Loading branch information
Showing
3 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,5 @@ module.exports = { | |
'<rootDir>/**/*.ts', | ||
'!**/testing/**', | ||
'!**/external-utils/**', | ||
'!**/utils/**', | ||
], | ||
} |
65 changes: 65 additions & 0 deletions
65
projects/ngx-meta/schematics/utils/get-all-typescript-files.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { describe, expect, it, jest } from '@jest/globals' | ||
import { | ||
getAllTypescriptFiles, | ||
GetAllTypescriptFilesOptions, | ||
} from './get-all-typescript-files' | ||
import { Tree } from '@angular-devkit/schematics' | ||
|
||
describe('get all typescript files', () => { | ||
const sut = getAllTypescriptFiles | ||
|
||
describe('should return Typescript files in the project', () => { | ||
const EXTENSIONS = ['.ts', '.mts'] | ||
EXTENSIONS.forEach((extension) => { | ||
it(`like ${extension} files`, () => { | ||
const tree = Tree.empty() | ||
const file = `/index${extension}` | ||
const fileInSubdir = `/subdir/index${extension}` | ||
;[file, fileInSubdir].forEach((filePath) => tree.create(filePath, '')) | ||
|
||
const files = getFilePathsFromResult(sut(tree)) | ||
expect(files).toEqual([file, fileInSubdir]) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('should not return Typescript definition files in the project', () => { | ||
const EXTENSIONS = ['.d.ts', '.d.mts'] | ||
|
||
EXTENSIONS.forEach((extension) => { | ||
it(`like ${extension} files`, () => { | ||
const tree = Tree.empty() | ||
tree.create(`/index${extension}`, '') | ||
|
||
const files = getFilePathsFromResult(sut(tree)) | ||
expect(files).toHaveLength(0) | ||
}) | ||
}) | ||
}) | ||
|
||
it('should not return Typescript files inside node_modules directory', () => { | ||
const tree = Tree.empty() | ||
tree.create(`/node_modules/@angular/core/index.ts`, '') | ||
|
||
const files = getFilePathsFromResult(sut(tree)) | ||
expect(files).toHaveLength(0) | ||
}) | ||
|
||
it('should not return Typescript files not matching the content filter when provided', () => { | ||
const contentFilter = jest | ||
.fn<Exclude<GetAllTypescriptFilesOptions['contentFilter'], undefined>>() | ||
.mockReturnValue(false) | ||
const tree = Tree.empty() | ||
const DUMMY_CONTENT = 'DUMMY_CONTENT' | ||
tree.create(`/index.ts`, DUMMY_CONTENT) | ||
|
||
const files = getFilePathsFromResult(sut(tree, { contentFilter })) | ||
expect(files).toHaveLength(0) | ||
expect(contentFilter).toHaveBeenCalledWith(DUMMY_CONTENT) | ||
expect(contentFilter).toHaveBeenCalledTimes(1) | ||
}) | ||
}) | ||
|
||
const getFilePathsFromResult = ( | ||
iterableIterator: ReturnType<typeof getAllTypescriptFiles>, | ||
): ReadonlyArray<string> => [...iterableIterator].map(([filePath]) => filePath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters