-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
chore: migrate jest-resolve-dependencies to TypeScript #7922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
c876827
00cc191
b60516f
cac1d7b
363baf6
bc96e8b
84fb2ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,37 +7,42 @@ | |
| */ | ||
| 'use strict'; | ||
|
|
||
| const path = require('path'); | ||
| const {normalize} = require('jest-config'); | ||
| const {buildSnapshotResolver} = require('jest-snapshot'); | ||
| const DependencyResolver = require('../index'); | ||
| import {tmpdir} from 'os'; | ||
| import path from 'path'; | ||
| import {Config} from '@jest/types'; | ||
| import {buildSnapshotResolver} from 'jest-snapshot'; | ||
| import {makeProjectConfig} from '../../../../TestUtils'; | ||
|
|
||
| import DependencyResolver from '../index'; | ||
|
|
||
| const maxWorkers = 1; | ||
| let dependencyResolver; | ||
| let dependencyResolver: DependencyResolver; | ||
| let Runtime; | ||
| let config; | ||
| const cases = { | ||
| let config: Config.ProjectConfig; | ||
| const cases: {[key: string]: jest.Mock} = { | ||
| fancyCondition: jest.fn(path => path.length > 10), | ||
| testRegex: jest.fn(path => /.test.js$/.test(path)), | ||
| }; | ||
| const filter = path => Object.keys(cases).every(key => cases[key](path)); | ||
| const filter = (path: Config.Path) => | ||
| Object.keys(cases).every(key => cases[key](path)); | ||
|
|
||
| beforeEach(() => { | ||
| Runtime = require('jest-runtime'); | ||
jeysal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| config = normalize( | ||
| { | ||
| rootDir: '.', | ||
| roots: ['./packages/jest-resolve-dependencies'], | ||
| }, | ||
| {}, | ||
| ).options; | ||
| return Runtime.createContext(config, {maxWorkers}).then(hasteMap => { | ||
| dependencyResolver = new DependencyResolver( | ||
| hasteMap.resolver, | ||
| hasteMap.hasteFS, | ||
| buildSnapshotResolver(config), | ||
| ); | ||
| config = makeProjectConfig({ | ||
| cacheDirectory: path.resolve(tmpdir(), 'jest-resolve-dependencies-test'), | ||
| moduleDirectories: ['node_modules'], | ||
| rootDir: '.', | ||
| roots: ['./packages/jest-resolve-dependencies'], | ||
| }); | ||
| return Runtime.createContext(config, {maxWorkers, watchman: false}).then( | ||
| (hasteMap: any) => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could type as
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's what I meant in #7922 (comment), would prefer to do it in another PR though since I expect it to become rather big
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good! |
||
| dependencyResolver = new DependencyResolver( | ||
| hasteMap.resolver, | ||
| hasteMap.hasteFS, | ||
| buildSnapshotResolver(config), | ||
| ); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test('resolves no dependencies for non-existent path', () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "extends": "../../tsconfig.json", | ||
| "compilerOptions": { | ||
| "rootDir": "src", | ||
| "outDir": "build" | ||
| }, | ||
| "references": [ | ||
| {"path": "../jest-regex-util"}, | ||
| {"path": "../jest-snapshot"}, | ||
| {"path": "../jest-types"} | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * 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 {Path} from './Config'; | ||
|
|
||
| export type ResolveModuleConfig = { | ||
| skipNodeResolution?: boolean; | ||
| paths?: Path[]; | ||
| }; | ||
| export type ResolvedModule = { | ||
| file: Path; | ||
| dependencies: Path[]; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /** | ||
| * 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 {Path} from './Config'; | ||
|
|
||
| export type SnapshotResolver = { | ||
jeysal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| testPathForConsistencyCheck: string; | ||
| resolveSnapshotPath(testPath: Path, extension?: string): Path; | ||
| resolveTestPath(snapshotPath: Path, extension?: string): Path; | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.