diff --git a/CHANGELOG.md b/CHANGELOG.md index cc627eee63da..a35f09f8192f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,8 @@ - `[@jest/source-map]`: Extract `getCallsite` function from `jest-util` into a new separate package ([#8029](https://github.com/facebook/jest/pull/8029)) - `[@jest/console]`: Extract custom `console` implementations from `jest-util` into a new separate package ([#8030](https://github.com/facebook/jest/pull/8030)) - `[docs]`: Improve runAllTimers doc (it exhausts the micro-task queue) ([#8031](https://github.com/facebook/jest/pull/8031)) +- `[jest-cli]`: Migrate to TypeScript ([#8024](https://github.com/facebook/jest/pull/8024)) +- `[jest]`: Migrate to TypeScript ([#8024](https://github.com/facebook/jest/pull/8024)) ### Performance diff --git a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap index 2778cca75a7f..93748d2d53f6 100644 --- a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap +++ b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap @@ -100,6 +100,7 @@ exports[`--showConfig outputs config info and exits 1`] = ` "filter": null, "globalSetup": null, "globalTeardown": null, + "json": false, "listTests": false, "maxConcurrency": 5, "maxWorkers": "[maxWorkers]", diff --git a/e2e/__tests__/runProgramatically.test.ts b/e2e/__tests__/runProgrammatically.test.ts similarity index 87% rename from e2e/__tests__/runProgramatically.test.ts rename to e2e/__tests__/runProgrammatically.test.ts index 5e57c8598414..d6eecf7eac09 100644 --- a/e2e/__tests__/runProgramatically.test.ts +++ b/e2e/__tests__/runProgrammatically.test.ts @@ -9,7 +9,7 @@ import {resolve} from 'path'; import {run} from '../Utils'; -const dir = resolve(__dirname, '..', 'run-programatically'); +const dir = resolve(__dirname, '..', 'run-programmatically'); test('run Jest programatically', () => { const {stdout} = run(`node index.js --version`, dir); diff --git a/e2e/run-programatically/index.js b/e2e/run-programmatically/index.js similarity index 100% rename from e2e/run-programatically/index.js rename to e2e/run-programmatically/index.js diff --git a/e2e/run-programmatically/package.json b/e2e/run-programmatically/package.json new file mode 100644 index 000000000000..e886f90ea628 --- /dev/null +++ b/e2e/run-programmatically/package.json @@ -0,0 +1,6 @@ +{ + "name": "run-programmatically", + "version": "1.0.0", + "dependencies": {}, + "jest": {} +} diff --git a/packages/jest-cli/package.json b/packages/jest-cli/package.json index 3b37a7743958..f86edacc6a29 100644 --- a/packages/jest-cli/package.json +++ b/packages/jest-cli/package.json @@ -3,8 +3,10 @@ "description": "Delightful JavaScript Testing.", "version": "24.1.0", "main": "build/index.js", + "types": "build/index.d.ts", "dependencies": { "@jest/core": "^24.1.0", + "@jest/types": "^24.1.0", "chalk": "^2.0.1", "exit": "^0.1.2", "import-local": "^2.0.0", diff --git a/packages/jest-cli/src/__tests__/cli/args.test.js b/packages/jest-cli/src/__tests__/cli/args.test.ts similarity index 79% rename from packages/jest-cli/src/__tests__/cli/args.test.js rename to packages/jest-cli/src/__tests__/cli/args.test.ts index 91945fb17e55..8b1c3a291637 100644 --- a/packages/jest-cli/src/__tests__/cli/args.test.js +++ b/packages/jest-cli/src/__tests__/cli/args.test.ts @@ -6,55 +6,56 @@ * */ -'use strict'; - -import type {Argv} from 'types/Argv'; +import {Config} from '@jest/types'; import {check} from '../../cli/args'; import {buildArgv} from '../../cli'; describe('check', () => { it('returns true if the arguments are valid', () => { - const argv: Argv = {}; + const argv = {} as Config.Argv; expect(check(argv)).toBe(true); }); it('raises an exception if runInBand and maxWorkers are both specified', () => { - const argv: Argv = {maxWorkers: 2, runInBand: true}; + const argv = {maxWorkers: 2, runInBand: true} as Config.Argv; expect(() => check(argv)).toThrow( 'Both --runInBand and --maxWorkers were specified', ); }); it('raises an exception if onlyChanged and watchAll are both specified', () => { - const argv: Argv = {onlyChanged: true, watchAll: true}; + const argv = {onlyChanged: true, watchAll: true} as Config.Argv; expect(() => check(argv)).toThrow( 'Both --onlyChanged and --watchAll were specified', ); }); it('raises an exception when lastCommit and watchAll are both specified', () => { - const argv: Argv = {lastCommit: true, watchAll: true}; + const argv = {lastCommit: true, watchAll: true} as Config.Argv; expect(() => check(argv)).toThrow( 'Both --lastCommit and --watchAll were specified', ); }); it('raises an exception if findRelatedTests is specified with no file paths', () => { - const argv: Argv = {_: [], findRelatedTests: true}; + const argv = { + _: [] as Array, + findRelatedTests: true, + } as Config.Argv; expect(() => check(argv)).toThrow( 'The --findRelatedTests option requires file paths to be specified', ); }); it('raises an exception if maxWorkers is specified with no number', () => { - const argv: Argv = {maxWorkers: undefined}; + const argv = ({maxWorkers: undefined} as unknown) as Config.Argv; expect(() => check(argv)).toThrow( 'The --maxWorkers (-w) option requires a number to be specified', ); }); it('raises an exception if config is not a valid JSON string', () => { - const argv: Argv = {config: 'x:1'}; + const argv = {config: 'x:1'} as Config.Argv; expect(() => check(argv)).toThrow( 'The --config option requires a JSON string literal, or a file path with a .js or .json extension', ); @@ -63,9 +64,11 @@ describe('check', () => { describe('buildArgv', () => { it('should return only camelcased args ', () => { + // @ts-ignore const mockProcessArgv = jest .spyOn(process.argv, 'slice') .mockImplementation(() => ['--clear-mocks']); + // @ts-ignore const actual = buildArgv(null); expect(actual).not.toHaveProperty('clear-mocks'); expect(actual).toHaveProperty('clearMocks', true); diff --git a/packages/jest-cli/src/cli/args.js b/packages/jest-cli/src/cli/args.ts similarity index 83% rename from packages/jest-cli/src/cli/args.js rename to packages/jest-cli/src/cli/args.ts index 184c09afd593..b98baa1791b1 100644 --- a/packages/jest-cli/src/cli/args.js +++ b/packages/jest-cli/src/cli/args.ts @@ -3,16 +3,13 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -import type {Argv} from 'types/Argv'; - +import {Config} from '@jest/types'; import {isJSONString} from 'jest-config'; import isCI from 'is-ci'; -export const check = (argv: Argv) => { +export const check = (argv: Config.Argv) => { if (argv.runInBand && argv.hasOwnProperty('maxWorkers')) { throw new Error( 'Both --runInBand and --maxWorkers were specified, but these two ' + @@ -80,7 +77,7 @@ export const options = { automock: { default: undefined, description: 'Automock all files by default.', - type: 'boolean', + type: 'boolean' as 'boolean', }, bail: { alias: 'b', @@ -94,27 +91,27 @@ export const options = { 'Respect the "browser" field in package.json ' + 'when resolving modules. Some packages export different versions ' + 'based on whether they are operating in node.js or a browser.', - type: 'boolean', + type: 'boolean' as 'boolean', }, cache: { default: undefined, description: 'Whether to use the transform cache. Disable the cache ' + 'using --no-cache.', - type: 'boolean', + type: 'boolean' as 'boolean', }, cacheDirectory: { description: 'The directory where Jest should store its cached ' + ' dependency information.', - type: 'string', + type: 'string' as 'string', }, changedFilesWithAncestor: { default: undefined, description: 'Runs tests related to the current changes and the changes made in the ' + 'last commit. Behaves similarly to `--onlyChanged`.', - type: 'boolean', + type: 'boolean' as 'boolean', }, changedSince: { description: @@ -122,7 +119,7 @@ export const options = { 'current branch has diverged from the given branch, then only changes ' + 'made locally will be tested. Behaves similarly to `--onlyChanged`.', nargs: 1, - type: 'string', + type: 'string' as 'string', }, ci: { default: isCI, @@ -130,48 +127,49 @@ export const options = { 'Whether to run Jest in continuous integration (CI) mode. ' + 'This option is on by default in most popular CI environments. It will ' + ' prevent snapshots from being written unless explicitly requested.', - type: 'boolean', + type: 'boolean' as 'boolean', }, clearCache: { default: undefined, description: 'Clears the configured Jest cache directory and then exits. ' + 'Default directory can be found by calling jest --showConfig', - type: 'boolean', + type: 'boolean' as 'boolean', }, clearMocks: { default: undefined, description: 'Automatically clear mock calls and instances between every ' + 'test. Equivalent to calling jest.clearAllMocks() between each test.', - type: 'boolean', + type: 'boolean' as 'boolean', }, collectCoverage: { default: undefined, description: 'Alias for --coverage.', - type: 'boolean', + type: 'boolean' as 'boolean', }, collectCoverageFrom: { description: 'A glob pattern relative to matching the files that coverage ' + 'info needs to be collected from.', - type: 'string', + type: 'string' as 'string', }, collectCoverageOnlyFrom: { description: 'Explicit list of paths coverage will be restricted to.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, color: { default: undefined, description: 'Forces test results output color highlighting (even if ' + 'stdout is not a TTY). Set to false if you would like to have no colors.', - type: 'boolean', + type: 'boolean' as 'boolean', }, colors: { default: undefined, description: 'Alias for `--color`.', - type: 'boolean', + type: 'boolean' as 'boolean', }, config: { alias: 'c', @@ -180,42 +178,44 @@ export const options = { 'and execute tests. If no rootDir is set in the config, the directory ' + 'containing the config file is assumed to be the rootDir for the project.' + 'This can also be a JSON encoded value which Jest will use as configuration.', - type: 'string', + type: 'string' as 'string', }, coverage: { default: undefined, description: 'Indicates that test coverage information should be ' + 'collected and reported in the output.', - type: 'boolean', + type: 'boolean' as 'boolean', }, coverageDirectory: { description: 'The directory where Jest should output its coverage files.', - type: 'string', + type: 'string' as 'string', }, coveragePathIgnorePatterns: { description: 'An array of regexp pattern strings that are matched ' + 'against all file paths before executing the test. If the file path' + 'matches any of the patterns, coverage information will be skipped.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, coverageReporters: { description: 'A list of reporter names that Jest uses when writing ' + 'coverage reports. Any istanbul reporter can be used.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, coverageThreshold: { description: 'A JSON string with which will be used to configure ' + 'minimum threshold enforcement for coverage results', - type: 'string', + type: 'string' as 'string', }, debug: { default: undefined, description: 'Print debugging info about your jest config.', - type: 'boolean', + type: 'boolean' as 'boolean', }, detectLeaks: { default: false, @@ -223,32 +223,32 @@ export const options = { '**EXPERIMENTAL**: Detect memory leaks in tests. After executing a ' + 'test, it will try to garbage collect the global object used, and fail ' + 'if it was leaked', - type: 'boolean', + type: 'boolean' as 'boolean', }, detectOpenHandles: { default: false, description: 'Print out remaining open handles preventing Jest from exiting at the ' + 'end of a test run.', - type: 'boolean', + type: 'boolean' as 'boolean', }, env: { description: 'The test environment used for all tests. This can point to ' + 'any file or node module. Examples: `jsdom`, `node` or ' + '`path/to/my-environment.js`', - type: 'string', + type: 'string' as 'string', }, errorOnDeprecated: { default: false, description: 'Make calling deprecated APIs throw helpful error messages.', - type: 'boolean', + type: 'boolean' as 'boolean', }, expand: { alias: 'e', default: undefined, description: 'Use this flag to show full diffs instead of a patch.', - type: 'boolean', + type: 'boolean' as 'boolean', }, filter: { default: undefined, @@ -257,7 +257,7 @@ export const options = { 'a list of tests which can be manipulated to exclude tests from ' + 'running. Especially useful when used in conjunction with a testing ' + 'infrastructure to filter known broken tests.', - type: 'string', + type: 'string' as 'string', }, findRelatedTests: { default: undefined, @@ -265,7 +265,7 @@ export const options = { 'Find related tests for a list of source files that were ' + 'passed in as arguments. Useful for pre-commit hook integration to run ' + 'the minimal amount of tests necessary.', - type: 'boolean', + type: 'boolean' as 'boolean', }, forceExit: { default: undefined, @@ -273,44 +273,44 @@ export const options = { 'Force Jest to exit after all tests have completed running. ' + 'This is useful when resources set up by test code cannot be ' + 'adequately cleaned up.', - type: 'boolean', + type: 'boolean' as 'boolean', }, globalSetup: { description: 'The path to a module that runs before All Tests.', - type: 'string', + type: 'string' as 'string', }, globalTeardown: { description: 'The path to a module that runs after All Tests.', - type: 'string', + type: 'string' as 'string', }, globals: { description: 'A JSON string with map of global variables that need ' + 'to be available in all test environments.', - type: 'string', + type: 'string' as 'string', }, haste: { description: 'A JSON string with map of variables for the haste module system', - type: 'string', + type: 'string' as 'string', }, init: { description: 'Generate a basic configuration file', - type: 'boolean', + type: 'boolean' as 'boolean', }, json: { default: undefined, description: 'Prints the test results in JSON. This mode will send all ' + 'other test output and user messages to stderr.', - type: 'boolean', + type: 'boolean' as 'boolean', }, lastCommit: { default: undefined, description: 'Run all tests affected by file changes in the last commit made. ' + 'Behaves similarly to `--onlyChanged`.', - type: 'boolean', + type: 'boolean' as 'boolean', }, listTests: { default: false, @@ -318,7 +318,7 @@ export const options = { 'Lists all tests Jest will run given the arguments and ' + 'exits. Most useful in a CI system together with `--findRelatedTests` ' + 'to determine the tests Jest will run based on specific files', - type: 'boolean', + type: 'boolean' as 'boolean', }, logHeapUsage: { default: undefined, @@ -326,21 +326,21 @@ export const options = { 'Logs the heap usage after every test. Useful to debug ' + 'memory leaks. Use together with `--runInBand` and `--expose-gc` in ' + 'node.', - type: 'boolean', + type: 'boolean' as 'boolean', }, mapCoverage: { default: undefined, description: 'Maps code coverage reports against original source code ' + 'when transformers supply source maps.\n\nDEPRECATED', - type: 'boolean', + type: 'boolean' as 'boolean', }, maxConcurrency: { default: 5, description: 'Specifies the maximum number of tests that are allowed to run' + 'concurrently. This only affects tests using `test.concurrent`.', - type: 'number', + type: 'number' as 'number', }, maxWorkers: { alias: 'w', @@ -349,56 +349,60 @@ export const options = { 'will spawn for running tests. This defaults to the number of the ' + 'cores available on your machine. (its usually best not to override ' + 'this default)', - type: 'number', + type: 'number' as 'number', }, moduleDirectories: { description: 'An array of directory names to be searched recursively ' + "up from the requiring module's location.", - type: 'array', + string: true as true, + type: 'array' as 'array', }, moduleFileExtensions: { description: 'An array of file extensions your modules use. If you ' + 'require modules without specifying a file extension, these are the ' + 'extensions Jest will look for. ', - type: 'array', + string: true as true, + type: 'array' as 'array', }, moduleNameMapper: { description: 'A JSON string with a map from regular expressions to ' + 'module names that allow to stub out resources, like images or ' + 'styles with a single module', - type: 'string', + type: 'string' as 'string', }, modulePathIgnorePatterns: { description: 'An array of regexp pattern strings that are matched ' + 'against all module paths before those paths are to be considered ' + '"visible" to the module loader.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, modulePaths: { description: 'An alternative API to setting the NODE_PATH env variable, ' + 'modulePaths is an array of absolute paths to additional locations to ' + 'search when resolving modules.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, noStackTrace: { default: undefined, description: 'Disables stack trace in test results output', - type: 'boolean', + type: 'boolean' as 'boolean', }, notify: { default: undefined, description: 'Activates notifications for test results.', - type: 'boolean', + type: 'boolean' as 'boolean', }, notifyMode: { default: 'failure-change', description: 'Specifies when notifications will appear for test results.', - type: 'string', + type: 'string' as 'string', }, onlyChanged: { alias: 'o', @@ -407,81 +411,84 @@ export const options = { 'Attempts to identify which tests to run based on which ' + "files have changed in the current repository. Only works if you're " + 'running tests in a git or hg repository at the moment.', - type: 'boolean', + type: 'boolean' as 'boolean', }, onlyFailures: { alias: 'f', default: undefined, description: 'Run tests that failed in the previous execution.', - type: 'boolean', + type: 'boolean' as 'boolean', }, outputFile: { description: 'Write test results to a file when the --json option is ' + 'also specified.', - type: 'string', + type: 'string' as 'string', }, passWithNoTests: { default: false, description: 'Will not fail if no tests are found (for example while using `--testPathPattern`.)', - type: 'boolean', + type: 'boolean' as 'boolean', }, preset: { description: "A preset that is used as a base for Jest's configuration.", - type: 'string', + type: 'string' as 'string', }, prettierPath: { default: undefined, description: 'The path to the "prettier" module used for inline snapshots.', - type: 'string', + type: 'string' as 'string', }, projects: { description: 'A list of projects that use Jest to run all tests of all ' + 'projects in a single instance of Jest.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, reporters: { description: 'A list of custom reporters for the test suite.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, resetMocks: { default: undefined, description: 'Automatically reset mock state between every test. ' + 'Equivalent to calling jest.resetAllMocks() between each test.', - type: 'boolean', + type: 'boolean' as 'boolean', }, resetModules: { default: undefined, description: 'If enabled, the module registry for every test file will ' + 'be reset before running each individual test.', - type: 'boolean', + type: 'boolean' as 'boolean', }, resolver: { description: 'A JSON string which allows the use of a custom resolver.', - type: 'string', + type: 'string' as 'string', }, restoreMocks: { default: undefined, description: 'Automatically restore mock state and implementation between every test. ' + 'Equivalent to calling jest.restoreAllMocks() between each test.', - type: 'boolean', + type: 'boolean' as 'boolean', }, rootDir: { description: 'The root directory that Jest should scan for tests and ' + 'modules within.', - type: 'string', + type: 'string' as 'string', }, roots: { description: 'A list of paths to directories that Jest should use to ' + 'search for files in.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, runInBand: { alias: 'i', @@ -491,7 +498,7 @@ export const options = { 'creating a worker pool of child processes that run tests). This ' + 'is sometimes useful for debugging, but such use cases are pretty ' + 'rare.', - type: 'boolean', + type: 'boolean' as 'boolean', }, runTestsByPath: { default: false, @@ -499,136 +506,145 @@ export const options = { 'Used when provided patterns are exact file paths. This avoids ' + 'converting them into a regular expression and matching it against ' + 'every single file.', - type: 'boolean', + type: 'boolean' as 'boolean', }, runner: { description: "Allows to use a custom runner instead of Jest's default test runner.", - type: 'string', + type: 'string' as 'string', }, setupFiles: { description: 'A list of paths to modules that run some code to configure or ' + 'set up the testing environment before each test. ', - type: 'array', + string: true as true, + type: 'array' as 'array', }, setupFilesAfterEnv: { description: 'A list of paths to modules that run some code to configure or ' + 'set up the testing framework before each test ', - type: 'array', + string: true as true, + type: 'array' as 'array', }, showConfig: { default: undefined, description: 'Print your jest config and then exits.', - type: 'boolean', + type: 'boolean' as 'boolean', }, silent: { default: undefined, description: 'Prevent tests from printing messages through the console.', - type: 'boolean', + type: 'boolean' as 'boolean', }, skipFilter: { default: undefined, description: 'Disables the filter provided by --filter. Useful for CI jobs, or ' + 'local enforcement when fixing tests.', - type: 'boolean', + type: 'boolean' as 'boolean', }, snapshotSerializers: { description: 'A list of paths to snapshot serializer modules Jest should ' + 'use for snapshot testing.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, testEnvironment: { description: 'Alias for --env', - type: 'string', + type: 'string' as 'string', }, testEnvironmentOptions: { description: 'Test environment options that will be passed to the testEnvironment. ' + 'The relevant options depend on the environment.', - type: 'string', // Object + type: 'string' as 'string', // Object }, testFailureExitCode: { description: 'Exit code of `jest` command if the test run failed', - type: 'string', // number + type: 'string' as 'string', // number }, testLocationInResults: { default: false, description: 'Add `location` information to the test results', - type: 'boolean', + type: 'boolean' as 'boolean', }, testMatch: { description: 'The glob patterns Jest uses to detect test files.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, testNamePattern: { alias: 't', description: 'Run only tests with a name that matches the regex pattern.', - type: 'string', + type: 'string' as 'string', }, testPathIgnorePatterns: { description: 'An array of regexp pattern strings that are matched ' + 'against all test paths before executing the test. If the test path ' + 'matches any of the patterns, it will be skipped.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, testPathPattern: { description: 'A regexp pattern string that is matched against all tests ' + 'paths before executing the test.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, testRegex: { description: 'A string or array of string regexp patterns that Jest uses to detect test files.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, testResultsProcessor: { description: 'Allows the use of a custom results processor. ' + 'This processor must be a node module that exports ' + 'a function expecting as the first argument the result object.', - type: 'string', + type: 'string' as 'string', }, testRunner: { description: 'Allows to specify a custom test runner. The default is ' + ' `jasmine2`. A path to a custom test runner can be provided: ' + '`/path/to/testRunner.js`.', - type: 'string', + type: 'string' as 'string', }, testURL: { description: 'This option sets the URL for the jsdom environment.', - type: 'string', + type: 'string' as 'string', }, timers: { description: 'Setting this value to fake allows the use of fake timers ' + 'for functions such as setTimeout.', - type: 'string', + type: 'string' as 'string', }, transform: { description: 'A JSON string which maps from regular expressions to paths ' + 'to transformers.', - type: 'string', + type: 'string' as 'string', }, transformIgnorePatterns: { description: 'An array of regexp pattern strings that are matched ' + 'against all source file paths before transformation.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, unmockedModulePathPatterns: { description: 'An array of regexp pattern strings that are matched ' + 'against all modules before the module loader will automatically ' + 'return a mock for them.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, updateSnapshot: { alias: 'u', @@ -638,24 +654,24 @@ export const options = { 'Can be used together with a test suite pattern or with ' + '`--testNamePattern` to re-record snapshot for test matching ' + 'the pattern', - type: 'boolean', + type: 'boolean' as 'boolean', }, useStderr: { default: undefined, description: 'Divert all output to stderr.', - type: 'boolean', + type: 'boolean' as 'boolean', }, verbose: { default: undefined, description: 'Display individual test results with the test suite hierarchy.', - type: 'boolean', + type: 'boolean' as 'boolean', }, version: { alias: 'v', default: undefined, description: 'Print the version and exit', - type: 'boolean', + type: 'boolean' as 'boolean', }, watch: { default: undefined, @@ -663,7 +679,7 @@ export const options = { 'Watch files for changes and rerun tests related to ' + 'changed files. If you want to re-run all tests when a file has ' + 'changed, use the `--watchAll` option.', - type: 'boolean', + type: 'boolean' as 'boolean', }, watchAll: { default: undefined, @@ -671,20 +687,21 @@ export const options = { 'Watch files for changes and rerun all tests. If you want ' + 'to re-run only the tests related to the changed files, use the ' + '`--watch` option.', - type: 'boolean', + type: 'boolean' as 'boolean', }, watchPathIgnorePatterns: { description: 'An array of regexp pattern strings that are matched ' + 'against all paths before trigger test re-run in watch mode. ' + 'If the test path matches any of the patterns, it will be skipped.', - type: 'array', + string: true as true, + type: 'array' as 'array', }, watchman: { default: undefined, description: 'Whether to use watchman for file crawling. Disable using ' + '--no-watchman.', - type: 'boolean', + type: 'boolean' as 'boolean', }, }; diff --git a/packages/jest-cli/src/cli/index.js b/packages/jest-cli/src/cli/index.ts similarity index 75% rename from packages/jest-cli/src/cli/index.js rename to packages/jest-cli/src/cli/index.ts index 910cc7f10fa8..a09878ba9dc5 100644 --- a/packages/jest-cli/src/cli/index.js +++ b/packages/jest-cli/src/cli/index.ts @@ -3,32 +3,25 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -import type {AggregatedResult} from 'types/TestResult'; -import type {Argv} from 'types/Argv'; -import type {GlobalConfig, Path} from 'types/Config'; - import path from 'path'; +import {Config, TestResult} from '@jest/types'; import {clearLine} from 'jest-util'; import {validateCLIOptions} from 'jest-validate'; import {deprecationEntries} from 'jest-config'; import {runCLI} from '@jest/core'; -import * as args from './args'; import chalk from 'chalk'; import exit from 'exit'; import yargs from 'yargs'; import {sync as realpath} from 'realpath-native'; import init from '../init'; +import getVersion from '../version'; +import * as args from './args'; -import {version as VERSION} from '../../package.json'; - -export async function run(maybeArgv?: Argv, project?: Path) { +export async function run(maybeArgv?: Array, project?: Config.Path) { try { - // $FlowFixMe:`allow reduced return - const argv: Argv = buildArgv(maybeArgv); + const argv: Config.Argv = buildArgv(maybeArgv); if (argv.init) { await init(); @@ -48,12 +41,14 @@ export async function run(maybeArgv?: Argv, project?: Path) { } } -export const buildArgv = (maybeArgv: ?Argv) => { +export const buildArgv = (maybeArgv?: Array): Config.Argv => { const version = - VERSION + (__dirname.includes(`packages${path.sep}jest-cli`) ? '-dev' : ''); + getVersion() + + (__dirname.includes(`packages${path.sep}jest-cli`) ? '-dev' : ''); - const rawArgv: Argv | string[] = maybeArgv || process.argv.slice(2); - const argv: Argv = yargs(rawArgv) + const rawArgv: Config.Argv | Array = + maybeArgv || process.argv.slice(2); + const argv: Config.Argv = yargs(rawArgv) .usage(args.usage) .version(version) .alias('help', 'h') @@ -71,16 +66,21 @@ export const buildArgv = (maybeArgv: ?Argv) => { ); // strip dashed args - return Object.keys(argv).reduce((result, key) => { - if (!key.includes('-')) { - // $FlowFixMe:`allow reduced return - result[key] = argv[key]; - } - return result; - }, {}); + return Object.keys(argv).reduce( + (result, key) => { + if (!key.includes('-')) { + result[key] = argv[key]; + } + return result; + }, + {} as Config.Argv, + ); }; -const getProjectListFromCLIArgs = (argv, project: ?Path) => { +const getProjectListFromCLIArgs = ( + argv: Config.Argv, + project?: Config.Path, +) => { const projects = argv.projects ? argv.projects : []; if (project) { @@ -104,8 +104,8 @@ const getProjectListFromCLIArgs = (argv, project: ?Path) => { }; const readResultsAndExit = ( - result: ?AggregatedResult, - globalConfig: GlobalConfig, + result: TestResult.AggregatedResult | null, + globalConfig: Config.GlobalConfig, ) => { const code = !result || result.success ? 0 : globalConfig.testFailureExitCode; @@ -140,7 +140,6 @@ const readResultsAndExit = ( '`--detectOpenHandles` to troubleshoot this issue.', ), ); - // $FlowFixMe: `unref` exists in Node }, 1000).unref(); } }; diff --git a/packages/jest-cli/src/index.js b/packages/jest-cli/src/index.ts similarity index 97% rename from packages/jest-cli/src/index.js rename to packages/jest-cli/src/index.ts index 7ebc603595c4..956d00196105 100644 --- a/packages/jest-cli/src/index.js +++ b/packages/jest-cli/src/index.ts @@ -3,8 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ // TODO: remove exports for the next major diff --git a/packages/jest-cli/src/init/__tests__/__snapshots__/modify_package_json.test.js.snap b/packages/jest-cli/src/init/__tests__/__snapshots__/modify_package_json.test.ts.snap similarity index 100% rename from packages/jest-cli/src/init/__tests__/__snapshots__/modify_package_json.test.js.snap rename to packages/jest-cli/src/init/__tests__/__snapshots__/modify_package_json.test.ts.snap diff --git a/packages/jest-cli/src/init/__tests__/init.test.js b/packages/jest-cli/src/init/__tests__/init.test.js index d10629e6153a..65a8128b36b6 100644 --- a/packages/jest-cli/src/init/__tests__/init.test.js +++ b/packages/jest-cli/src/init/__tests__/init.test.js @@ -3,8 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ /* eslint-disable no-eval */ diff --git a/packages/jest-cli/src/init/__tests__/modify_package_json.test.js b/packages/jest-cli/src/init/__tests__/modify_package_json.test.ts similarity index 97% rename from packages/jest-cli/src/init/__tests__/modify_package_json.test.js rename to packages/jest-cli/src/init/__tests__/modify_package_json.test.ts index aa2f8f4641f4..8c7dad5a0bef 100644 --- a/packages/jest-cli/src/init/__tests__/modify_package_json.test.js +++ b/packages/jest-cli/src/init/__tests__/modify_package_json.test.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import modifyPackageJson from '../modify_package_json'; @@ -13,7 +12,7 @@ test('should remove jest config if exists', () => { modifyPackageJson({ projectPackageJson: { jest: { - coverage: true, + collectCoverage: true, }, }, shouldModifyScripts: true, diff --git a/packages/jest-cli/src/init/constants.js b/packages/jest-cli/src/init/constants.ts similarity index 96% rename from packages/jest-cli/src/init/constants.js rename to packages/jest-cli/src/init/constants.ts index 29044effbaeb..8ebd1eecd72a 100644 --- a/packages/jest-cli/src/init/constants.js +++ b/packages/jest-cli/src/init/constants.ts @@ -3,8 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ export const PACKAGE_JSON = 'package.json'; diff --git a/packages/jest-cli/src/init/errors.js b/packages/jest-cli/src/init/errors.ts similarity index 70% rename from packages/jest-cli/src/init/errors.js rename to packages/jest-cli/src/init/errors.ts index 242066f4d3dc..2c85b6585a7f 100644 --- a/packages/jest-cli/src/init/errors.js +++ b/packages/jest-cli/src/init/errors.ts @@ -3,32 +3,23 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ export class NotFoundPackageJsonError extends Error { - name: string; - message: string; - constructor(rootDir: string) { - super(); + super(`Could not find a "package.json" file in ${rootDir}`); this.name = ''; - this.message = `Could not find a "package.json" file in ${rootDir}`; Error.captureStackTrace(this, () => {}); } } export class MalformedPackageJsonError extends Error { - name: string; - message: string; - constructor(packageJsonPath: string) { - super(); - this.name = ''; - this.message = + super( `There is malformed json in ${packageJsonPath}\n` + - 'Fix it, and then run "jest --init"'; + 'Fix it, and then run "jest --init"', + ); + this.name = ''; Error.captureStackTrace(this, () => {}); } } diff --git a/packages/jest-cli/src/init/generate_config_file.js b/packages/jest-cli/src/init/generate_config_file.ts similarity index 70% rename from packages/jest-cli/src/init/generate_config_file.js rename to packages/jest-cli/src/init/generate_config_file.ts index 0732a08c6d5f..961c4610ce71 100644 --- a/packages/jest-cli/src/init/generate_config_file.js +++ b/packages/jest-cli/src/init/generate_config_file.ts @@ -3,15 +3,14 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ +import {Config} from '@jest/types'; import {defaults, descriptions} from 'jest-config'; const stringifyOption = ( - option: string, - map: Object, + option: keyof Config.InitialOptions, + map: Partial, linePrefix: string = '', ): string => { const optionDescription = ` // ${descriptions[option]}`; @@ -32,10 +31,10 @@ const stringifyOption = ( ); }; -const generateConfigFile = (results: {[string]: boolean}): string => { +const generateConfigFile = (results: {[key: string]: unknown}): string => { const {coverage, clearMocks, environment} = results; - const overrides: Object = {}; + const overrides: Record = {}; if (coverage) { Object.assign(overrides, { @@ -55,15 +54,21 @@ const generateConfigFile = (results: {[string]: boolean}): string => { }); } - const overrideKeys: Array = Object.keys(overrides); + const overrideKeys = Object.keys(overrides) as Array< + keyof Config.InitialOptions + >; const properties: Array = []; for (const option in descriptions) { - if (overrideKeys.includes(option)) { - properties.push(stringifyOption(option, overrides)); + const opt = option as keyof typeof descriptions; + + if (overrideKeys.includes(opt)) { + properties.push(stringifyOption(opt, overrides)); } else { - properties.push(stringifyOption(option, defaults, '// ')); + properties.push( + stringifyOption(opt, defaults as Config.InitialOptions, '// '), + ); } } diff --git a/packages/jest-cli/src/init/index.js b/packages/jest-cli/src/init/index.ts similarity index 92% rename from packages/jest-cli/src/init/index.js rename to packages/jest-cli/src/init/index.ts index 68dd9f4fa640..7df3da704f5c 100644 --- a/packages/jest-cli/src/init/index.js +++ b/packages/jest-cli/src/init/index.ts @@ -3,13 +3,11 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -import chalk from 'chalk'; import fs from 'fs'; import path from 'path'; +import chalk from 'chalk'; import prompts from 'prompts'; import {sync as realpath} from 'realpath-native'; import defaultQuestions, {testScriptQuestion} from './questions'; @@ -17,12 +15,13 @@ import {NotFoundPackageJsonError, MalformedPackageJsonError} from './errors'; import {PACKAGE_JSON, JEST_CONFIG} from './constants'; import generateConfigFile from './generate_config_file'; import modifyPackageJson from './modify_package_json'; +import {ProjectPackageJson} from './types'; type PromptsResults = { - clearMocks: boolean, - coverage: boolean, - environment: boolean, - scripts: boolean, + clearMocks: boolean; + coverage: boolean; + environment: boolean; + scripts: boolean; }; export default async (rootDir: string = realpath(process.cwd())) => { @@ -37,7 +36,7 @@ export default async (rootDir: string = realpath(process.cwd())) => { const questions = defaultQuestions.slice(0); let hasJestProperty: boolean = false; let hasJestConfig: boolean = false; - let projectPackageJson: ?Object; + let projectPackageJson: ProjectPackageJson; try { projectPackageJson = JSON.parse( @@ -89,6 +88,7 @@ export default async (rootDir: string = realpath(process.cwd())) => { let promptAborted: boolean = false; + // @ts-ignore: Return type cannot be object - faulty typings const results: PromptsResults = await prompts(questions, { onCancel: () => { promptAborted = true; diff --git a/packages/jest-cli/src/init/modify_package_json.js b/packages/jest-cli/src/init/modify_package_json.ts similarity index 83% rename from packages/jest-cli/src/init/modify_package_json.js rename to packages/jest-cli/src/init/modify_package_json.ts index 6dc6172872bb..c38835b00270 100644 --- a/packages/jest-cli/src/init/modify_package_json.js +++ b/packages/jest-cli/src/init/modify_package_json.ts @@ -3,17 +3,16 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ +import {ProjectPackageJson} from './types'; + const modifyPackageJson = ({ projectPackageJson, shouldModifyScripts, - hasJestProperty, }: { - projectPackageJson: Object, - shouldModifyScripts: boolean, + projectPackageJson: ProjectPackageJson; + shouldModifyScripts: boolean; }): string => { if (shouldModifyScripts) { projectPackageJson.scripts diff --git a/packages/jest-cli/src/init/questions.js b/packages/jest-cli/src/init/questions.ts similarity index 78% rename from packages/jest-cli/src/init/questions.js rename to packages/jest-cli/src/init/questions.ts index 5e7c829b7f10..d9179b2d1cb5 100644 --- a/packages/jest-cli/src/init/questions.js +++ b/packages/jest-cli/src/init/questions.ts @@ -3,19 +3,11 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -type Question = {| - initial?: boolean | number, - message: string, - name: string, - type: string, - choices?: Array<{title: string, value: string}>, -|}; +import {PromptObject} from 'prompts'; -const defaultQuestions: Array = [ +const defaultQuestions: Array = [ { choices: [ {title: 'node', value: 'node'}, @@ -42,7 +34,7 @@ const defaultQuestions: Array = [ export default defaultQuestions; -export const testScriptQuestion: Question = { +export const testScriptQuestion: PromptObject = { initial: true, message: 'Would you like to use Jest when running "test" script in "package.json"?', diff --git a/packages/jest-cli/src/init/types.ts b/packages/jest-cli/src/init/types.ts new file mode 100644 index 000000000000..81184fb1aabd --- /dev/null +++ b/packages/jest-cli/src/init/types.ts @@ -0,0 +1,13 @@ +/** + * 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 {Config} from '@jest/types'; + +export type ProjectPackageJson = { + jest?: Partial; + scripts?: {[key: string]: string}; +}; diff --git a/packages/jest-cli/src/version.js b/packages/jest-cli/src/version.ts similarity index 69% rename from packages/jest-cli/src/version.js rename to packages/jest-cli/src/version.ts index 23a05d19add1..5d778a274253 100644 --- a/packages/jest-cli/src/version.js +++ b/packages/jest-cli/src/version.ts @@ -3,12 +3,10 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -import {version as VERSION} from '../package.json'; +const {version: VERSION} = require('../package.json'); -export default function getVersion() { +export default function getVersion(): string { return VERSION; } diff --git a/packages/jest-cli/tsconfig.json b/packages/jest-cli/tsconfig.json new file mode 100644 index 000000000000..a7ff1e06b7d1 --- /dev/null +++ b/packages/jest-cli/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "references": [ + {"path": "../jest-core"}, + {"path": "../jest-config"}, + {"path": "../jest-types"}, + {"path": "../jest-util"}, + {"path": "../jest-validate"} + ] +} diff --git a/packages/jest-config/src/Deprecated.ts b/packages/jest-config/src/Deprecated.ts index 8ad752842d2a..898d9fe96deb 100644 --- a/packages/jest-config/src/Deprecated.ts +++ b/packages/jest-config/src/Deprecated.ts @@ -74,4 +74,4 @@ export default { Please update your configuration. `, -}; +} as Record; diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index d1ed515126a3..e43bd523af8a 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -829,7 +829,7 @@ export default function normalize( newOptions.nonFlagArgs = argv._; newOptions.testPathPattern = buildTestPathPattern(argv); - newOptions.json = argv.json; + newOptions.json = !!argv.json; newOptions.testFailureExitCode = parseInt( (newOptions.testFailureExitCode as unknown) as string, diff --git a/packages/jest-config/src/setFromArgv.ts b/packages/jest-config/src/setFromArgv.ts index f1ca92ed20be..8ae4aa11c4b1 100644 --- a/packages/jest-config/src/setFromArgv.ts +++ b/packages/jest-config/src/setFromArgv.ts @@ -39,8 +39,9 @@ export default function setFromArgv( case 'moduleNameMapper': case 'transform': case 'haste': - if (isJSONString(argv[key])) { - options[key] = JSON.parse(argv[key]); + const str = argv[key]; + if (isJSONString(str)) { + options[key] = JSON.parse(str); } break; default: diff --git a/packages/jest-config/src/utils.ts b/packages/jest-config/src/utils.ts index fb3b139f75b6..ca7c5d9d0047 100644 --- a/packages/jest-config/src/utils.ts +++ b/packages/jest-config/src/utils.ts @@ -217,8 +217,9 @@ export const getRunner = ( rootDir, }); -export const isJSONString = (text?: string) => - text && +type JSONString = string & {readonly $$type: never}; // newtype +export const isJSONString = (text?: JSONString | string): text is JSONString => + text != null && typeof text === 'string' && text.startsWith('{') && text.endsWith('}'); diff --git a/packages/jest-core/src/SearchSource.ts b/packages/jest-core/src/SearchSource.ts index 5c1992b55d94..ee28ca92bc8b 100644 --- a/packages/jest-core/src/SearchSource.ts +++ b/packages/jest-core/src/SearchSource.ts @@ -128,7 +128,7 @@ export default class SearchSource { const testCasesKeys = Object.keys(testCases) as Array; data.tests = allPaths.filter(test => - testCasesKeys.reduce((flag, key) => { + testCasesKeys.reduce((flag, key) => { const {stats} = data; if (testCases[key](test.path)) { stats[key] = stats[key] === undefined ? 1 : stats[key] + 1; diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index 45cea095571d..d0b958ee9e44 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -363,92 +363,90 @@ export type ProjectConfig = { unmockedModulePathPatterns: Array | null | undefined; }; -export type Argv = Arguments<{ - all: boolean; - automock: boolean; - bail: boolean | number; - browser: boolean; - cache: boolean; - cacheDirectory: string; - changedFilesWithAncestor: boolean; - changedSince: string; - ci: boolean; - clearCache: boolean; - clearMocks: boolean; - collectCoverage: boolean; - collectCoverageFrom: Array; - collectCoverageOnlyFrom: Array; - config: string; - coverage: boolean; - coverageDirectory: string; - coveragePathIgnorePatterns: Array; - coverageReporters: Array; - coverageThreshold: string; - debug: boolean; - env: string; - expand: boolean; - findRelatedTests: boolean; - forceExit: boolean; - globals: string; - globalSetup: string | null | undefined; - globalTeardown: string | null | undefined; - h: boolean; - haste: string; - help: boolean; - init: boolean; - json: boolean; - lastCommit: boolean; - logHeapUsage: boolean; - maxWorkers: number; - moduleDirectories: Array; - moduleFileExtensions: Array; - moduleLoader: string; - moduleNameMapper: string; - modulePathIgnorePatterns: Array; - modulePaths: Array; - name: string; - noSCM: boolean; - noStackTrace: boolean; - notify: boolean; - notifyMode: string; - onlyChanged: boolean; - outputFile: string; - preset: string | null | undefined; - projects: Array; - prettierPath: string | null | undefined; - replname: string | null | undefined; - resetMocks: boolean; - resetModules: boolean; - resolver: string | null | undefined; - restoreMocks: boolean; - rootDir: string; - roots: Array; - runInBand: boolean; - setupFiles: Array; - setupFilesAfterEnv: Array; - showConfig: boolean; - silent: boolean; - snapshotSerializers: Array; - testEnvironment: string; - testFailureExitCode: string | null | undefined; - testMatch: Array; - testNamePattern: string; - testPathIgnorePatterns: Array; - testPathPattern: Array; - testRegex: string | Array; - testResultsProcessor: string | null | undefined; - testRunner: string; - testURL: string; - timers: 'real' | 'fake'; - transform: string; - transformIgnorePatterns: Array; - unmockedModulePathPatterns: Array | null | undefined; - updateSnapshot: boolean; - useStderr: boolean; - verbose: boolean | null | undefined; - version: boolean; - watch: boolean; - watchAll: boolean; - watchman: boolean; - watchPathIgnorePatterns: Array; -}>; +export type Argv = Arguments< + Partial<{ + all: boolean; + automock: boolean; + bail: boolean | number; + browser: boolean; + cache: boolean; + cacheDirectory: string; + changedFilesWithAncestor: boolean; + changedSince: string; + ci: boolean; + clearCache: boolean; + clearMocks: boolean; + collectCoverage: boolean; + collectCoverageFrom: string; + collectCoverageOnlyFrom: Array; + color: boolean; + colors: boolean; + config: string; + coverage: boolean; + coverageDirectory: string; + coveragePathIgnorePatterns: Array; + coverageReporters: Array; + coverageThreshold: string; + debug: boolean; + env: string; + expand: boolean; + findRelatedTests: boolean; + forceExit: boolean; + globals: string; + globalSetup: string | null | undefined; + globalTeardown: string | null | undefined; + haste: string; + init: boolean; + json: boolean; + lastCommit: boolean; + logHeapUsage: boolean; + maxWorkers: number; + moduleDirectories: Array; + moduleFileExtensions: Array; + moduleNameMapper: string; + modulePathIgnorePatterns: Array; + modulePaths: Array; + noStackTrace: boolean; + notify: boolean; + notifyMode: string; + onlyChanged: boolean; + outputFile: string; + preset: string | null | undefined; + projects: Array; + prettierPath: string | null | undefined; + resetMocks: boolean; + resetModules: boolean; + resolver: string | null | undefined; + restoreMocks: boolean; + rootDir: string; + roots: Array; + runInBand: boolean; + setupFiles: Array; + setupFilesAfterEnv: Array; + showConfig: boolean; + silent: boolean; + snapshotSerializers: Array; + testEnvironment: string; + testFailureExitCode: string | null | undefined; + testMatch: Array; + testNamePattern: string; + testPathIgnorePatterns: Array; + testPathPattern: Array; + testRegex: string | Array; + testResultsProcessor: string | null | undefined; + testRunner: string; + testURL: string; + timers: string; + transform: string; + transformIgnorePatterns: Array; + unmockedModulePathPatterns: Array | null | undefined; + updateSnapshot: boolean; + useStderr: boolean; + verbose: boolean | null | undefined; + version: boolean; + watch: boolean; + watchAll: boolean; + watchman: boolean; + watchPathIgnorePatterns: Array; + }> +>; diff --git a/packages/jest-validate/src/validateCLIOptions.ts b/packages/jest-validate/src/validateCLIOptions.ts index 9a2e6406ddbb..a4962ed2dc74 100644 --- a/packages/jest-validate/src/validateCLIOptions.ts +++ b/packages/jest-validate/src/validateCLIOptions.ts @@ -8,6 +8,8 @@ import {Config} from '@jest/types'; import chalk from 'chalk'; import camelcase from 'camelcase'; +// eslint-disable-next-line import/no-extraneous-dependencies +import {Options} from 'yargs'; import {createDidYouMeanMessage, format, ValidationError} from './utils'; import {deprecationWarning} from './deprecated'; import defaultConfig from './defaultConfig'; @@ -63,15 +65,16 @@ const logDeprecatedOptions = ( export default function validateCLIOptions( argv: Config.Argv, options: { - [s: string]: {alias?: string}; deprecationEntries: DeprecatedOptions; + [s: string]: Options; }, rawArgv: Array = [], ) { const yargsSpecialOptions = ['$0', '_', 'help', 'h']; const deprecationEntries = options.deprecationEntries || {}; const allowedOptions = Object.keys(options).reduce( - (acc, option) => acc.add(option).add(options[option].alias || option), + (acc, option) => + acc.add(option).add((options[option].alias as string) || option), new Set(yargsSpecialOptions), ); const unrecognizedOptions = Object.keys(argv).filter( @@ -89,7 +92,7 @@ export default function validateCLIOptions( (acc, entry) => { if (options[entry]) { acc[entry] = deprecationEntries[entry]; - const alias = options[entry].alias; + const alias = options[entry].alias as string; if (alias) { acc[alias] = deprecationEntries[entry]; } diff --git a/packages/jest-watcher/package.json b/packages/jest-watcher/package.json index df3bd61731ce..5d3fe4087861 100644 --- a/packages/jest-watcher/package.json +++ b/packages/jest-watcher/package.json @@ -6,6 +6,7 @@ "dependencies": { "@jest/types": "^24.1.0", "@types/node": "*", + "@types/yargs": "^12.0.9", "ansi-escapes": "^3.0.0", "chalk": "^2.0.1", "jest-util": "^24.0.0", diff --git a/packages/jest/package.json b/packages/jest/package.json index b14020ae23a7..5099ba284447 100644 --- a/packages/jest/package.json +++ b/packages/jest/package.json @@ -3,6 +3,7 @@ "description": "Delightful JavaScript Testing.", "version": "24.1.0", "main": "build/jest.js", + "types": "build/jest.d.ts", "dependencies": { "import-local": "^2.0.0", "jest-cli": "^24.1.0" diff --git a/packages/jest/src/jest.js b/packages/jest/src/jest.ts similarity index 87% rename from packages/jest/src/jest.js rename to packages/jest/src/jest.ts index fe580071a094..f7322540629f 100644 --- a/packages/jest/src/jest.js +++ b/packages/jest/src/jest.ts @@ -3,10 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ import * as cli from 'jest-cli'; -module.exports = cli; +export = cli; diff --git a/packages/jest/tsconfig.json b/packages/jest/tsconfig.json new file mode 100644 index 000000000000..0e089576b519 --- /dev/null +++ b/packages/jest/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "references": [ + {"path": "../jest-cli"} + ] +} diff --git a/yarn.lock b/yarn.lock index d0398e7f8311..8da8658b833f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1928,7 +1928,7 @@ dependencies: "@types/node" "*" -"@types/yargs@^12.0.2": +"@types/yargs@^12.0.2", "@types/yargs@^12.0.9": version "12.0.9" resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-12.0.9.tgz#693e76a52f61a2f1e7fb48c0eef167b95ea4ffd0" integrity sha512-sCZy4SxP9rN2w30Hlmg5dtdRwgYQfYRiLo9usw8X9cxlf+H4FqM1xX7+sNH7NNKVdbXMJWqva7iyy+fxh/V7fA==