-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jest-resolve): expose
JestResolver
, AsyncResolver
and `SyncR…
…esolver` types (#12707)
- Loading branch information
1 parent
75c7c40
commit 0208815
Showing
14 changed files
with
157 additions
and
59 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
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
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
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
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,70 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {expectAssignable, expectError, expectType} from 'tsd-lite'; | ||
import type {AsyncResolver, JestResolver, SyncResolver} from 'jest-resolve'; | ||
|
||
type PackageJson = Record<string, unknown>; | ||
type PackageFilter = ( | ||
pkg: PackageJson, | ||
file: string, | ||
dir: string, | ||
) => PackageJson; | ||
type PathFilter = ( | ||
pkg: PackageJson, | ||
path: string, | ||
relativePath: string, | ||
) => string; | ||
|
||
// AsyncResolver | ||
|
||
const asyncResolver: AsyncResolver = async (path, options) => { | ||
expectType<string>(path); | ||
|
||
expectType<string>(options.basedir); | ||
expectType<Array<string> | undefined>(options.conditions); | ||
expectType<SyncResolver>(options.defaultResolver); | ||
expectType<Array<string> | undefined>(options.extensions); | ||
expectType<Array<string> | undefined>(options.moduleDirectory); | ||
expectType<PackageFilter | undefined>(options.packageFilter); | ||
expectType<PathFilter | undefined>(options.pathFilter); | ||
expectType<Array<string> | undefined>(options.paths); | ||
expectType<string | undefined>(options.rootDir); | ||
|
||
return path; | ||
}; | ||
|
||
const notReturningAsyncResolver = async () => {}; | ||
expectError<AsyncResolver>(notReturningAsyncResolver()); | ||
|
||
// SyncResolver | ||
|
||
const syncResolver: SyncResolver = (path, options) => { | ||
expectType<string>(path); | ||
|
||
expectType<string>(options.basedir); | ||
expectType<Array<string> | undefined>(options.conditions); | ||
expectType<SyncResolver>(options.defaultResolver); | ||
expectType<Array<string> | undefined>(options.extensions); | ||
expectType<Array<string> | undefined>(options.moduleDirectory); | ||
expectType<PackageFilter | undefined>(options.packageFilter); | ||
expectType<PathFilter | undefined>(options.pathFilter); | ||
expectType<Array<string> | undefined>(options.paths); | ||
expectType<string | undefined>(options.rootDir); | ||
|
||
return path; | ||
}; | ||
|
||
const notReturningSyncResolver = () => {}; | ||
expectError<SyncResolver>(notReturningSyncResolver()); | ||
|
||
// JestResolver | ||
|
||
expectAssignable<JestResolver>({async: asyncResolver}); | ||
expectAssignable<JestResolver>({sync: syncResolver}); | ||
expectAssignable<JestResolver>({async: asyncResolver, sync: syncResolver}); | ||
expectError<JestResolver>({}); |
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,12 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"composite": false, | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"skipLibCheck": true, | ||
|
||
"types": [] | ||
}, | ||
"include": ["./**/*"] | ||
} |
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
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
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
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
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
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
Oops, something went wrong.