Class JestConfigOptions.Builder

    • Constructor Detail

      • Builder

        public Builder()
    • Method Detail

      • automock

        @Stability(Experimental)
        public JestConfigOptions.Builder automock​(Boolean automock)
        Parameters:
        automock - This option tells Jest that all imported modules in your tests should be mocked automatically. All modules used in your tests will have a replacement implementation, keeping the API surface
        Returns:
        this
      • bail

        @Stability(Experimental)
        public JestConfigOptions.Builder bail​(Number bail)
        Sets the value of JestConfigOptions.getBail()
        Parameters:
        bail - By default, Jest runs all tests and produces all errors into the console upon completion. The bail config option can be used here to have Jest stop running tests after n failures. Setting bail to true is the same as setting bail to 1.
        Returns:
        this
      • bail

        @Stability(Experimental)
        public JestConfigOptions.Builder bail​(Boolean bail)
        Sets the value of JestConfigOptions.getBail()
        Parameters:
        bail - By default, Jest runs all tests and produces all errors into the console upon completion. The bail config option can be used here to have Jest stop running tests after n failures. Setting bail to true is the same as setting bail to 1.
        Returns:
        this
      • clearMocks

        @Stability(Experimental)
        public JestConfigOptions.Builder clearMocks​(Boolean clearMocks)
        Parameters:
        clearMocks - Automatically clear mock calls and instances before every test. Equivalent to calling jest.clearAllMocks() before each test. This does not remove any mock implementation that may have been provided
        Returns:
        this
      • collectCoverage

        @Stability(Experimental)
        public JestConfigOptions.Builder collectCoverage​(Boolean collectCoverage)
        Parameters:
        collectCoverage - Indicates whether the coverage information should be collected while executing the test. Because this retrofits all executed files with coverage collection statements, it may significantly slow down your tests
        Returns:
        this
      • coveragePathIgnorePatterns

        @Stability(Experimental)
        public JestConfigOptions.Builder coveragePathIgnorePatterns​(List<String> coveragePathIgnorePatterns)
        Parameters:
        coveragePathIgnorePatterns - 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
        Returns:
        this
      • coverageThreshold

        @Stability(Experimental)
        public JestConfigOptions.Builder coverageThreshold​(CoverageThreshold coverageThreshold)
        Parameters:
        coverageThreshold - Specify the global coverage thresholds. This will be used to configure minimum threshold enforcement for coverage results. Thresholds can be specified as global, as a glob, and as a directory or file path. If thresholds aren't met, jest will fail.
        Returns:
        this
      • dependencyExtractor

        @Stability(Experimental)
        public JestConfigOptions.Builder dependencyExtractor​(String dependencyExtractor)
        Parameters:
        dependencyExtractor - This option allows the use of a custom dependency extractor. It must be a node module that exports an object with an extract function
        Returns:
        this
      • extraGlobals

        @Stability(Experimental)
        public JestConfigOptions.Builder extraGlobals​(List<String> extraGlobals)
        Parameters:
        extraGlobals - Test files run inside a vm, which slows calls to global context properties (e.g. Math). With this option you can specify extra properties to be defined inside the vm for faster lookups.
        Returns:
        this
      • forceCoverageMatch

        @Stability(Experimental)
        public JestConfigOptions.Builder forceCoverageMatch​(List<String> forceCoverageMatch)
        Parameters:
        forceCoverageMatch - Test files are normally ignored from collecting code coverage. With this option, you can overwrite this behavior and include otherwise ignored files in code coverage.
        Returns:
        this
      • globalSetup

        @Stability(Experimental)
        public JestConfigOptions.Builder globalSetup​(String globalSetup)
        Parameters:
        globalSetup - This option allows the use of a custom global setup module which exports an async function that is triggered once before all test suites. This function gets Jest's globalConfig object as a parameter.
        Returns:
        this
      • globalTeardown

        @Stability(Experimental)
        public JestConfigOptions.Builder globalTeardown​(String globalTeardown)
        Parameters:
        globalTeardown - This option allows the use of a custom global teardown module which exports an async function that is triggered once after all test suites. This function gets Jest's globalConfig object as a parameter.
        Returns:
        this
      • injectGlobals

        @Stability(Experimental)
        public JestConfigOptions.Builder injectGlobals​(Boolean injectGlobals)
        Parameters:
        injectGlobals - Insert Jest's globals (expect, test, describe, beforeEach etc.) into the global environment. If you set this to false, you should import from.
        Returns:
        this
      • maxConcurrency

        @Stability(Experimental)
        public JestConfigOptions.Builder maxConcurrency​(Number maxConcurrency)
        Parameters:
        maxConcurrency - A number limiting the number of tests that are allowed to run at the same time when using test.concurrent. Any test above this limit will be queued and executed once a slot is released.
        Returns:
        this
      • maxWorkers

        @Stability(Experimental)
        public JestConfigOptions.Builder maxWorkers​(String maxWorkers)
        Parameters:
        maxWorkers - Specifies the maximum number of workers the worker-pool will spawn for running tests. In single run mode, this defaults to the number of the cores available on your machine minus one for the main thread In watch mode, this defaults to half of the available cores on your machine. For environments with variable CPUs available, you can use percentage based configuration: "maxWorkers": "50%"
        Returns:
        this
      • maxWorkers

        @Stability(Experimental)
        public JestConfigOptions.Builder maxWorkers​(Number maxWorkers)
        Parameters:
        maxWorkers - Specifies the maximum number of workers the worker-pool will spawn for running tests. In single run mode, this defaults to the number of the cores available on your machine minus one for the main thread In watch mode, this defaults to half of the available cores on your machine. For environments with variable CPUs available, you can use percentage based configuration: "maxWorkers": "50%"
        Returns:
        this
      • moduleDirectories

        @Stability(Experimental)
        public JestConfigOptions.Builder moduleDirectories​(List<String> moduleDirectories)
        Parameters:
        moduleDirectories - An array of directory names to be searched recursively up from the requiring module's location. Setting this option will override the default, if you wish to still search node_modules for packages include it along with any other options: ["node_modules", "bower_components"]
        Returns:
        this
      • moduleFileExtensions

        @Stability(Experimental)
        public JestConfigOptions.Builder moduleFileExtensions​(List<String> moduleFileExtensions)
        Parameters:
        moduleFileExtensions - 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, in left-to-right order.
        Returns:
        this
      • moduleNameMapper

        @Stability(Experimental)
        public JestConfigOptions.Builder moduleNameMapper​(Map<String,​? extends Object> moduleNameMapper)
        Parameters:
        moduleNameMapper - A map from regular expressions to module names or to arrays of module names that allow to stub out resources, like images or styles with a single module.
        Returns:
        this
      • modulePathIgnorePatterns

        @Stability(Experimental)
        public JestConfigOptions.Builder modulePathIgnorePatterns​(List<String> modulePathIgnorePatterns)
        Parameters:
        modulePathIgnorePatterns - 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. If a given module's path matches any of the patterns, it will not be require()-able in the test environment.
        Returns:
        this
      • modulePaths

        @Stability(Experimental)
        public JestConfigOptions.Builder modulePaths​(List<String> modulePaths)
        Parameters:
        modulePaths - 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. Use the string token to include the path to your project's root directory. Example: ["/app/"].
        Returns:
        this
      • preset

        @Stability(Experimental)
        public JestConfigOptions.Builder preset​(String preset)
        Parameters:
        preset - A preset that is used as a base for Jest's configuration. A preset should point to an npm module that has a jest-preset.json or jest-preset.js file at the root.
        Returns:
        this
      • projects

        @Stability(Experimental)
        public JestConfigOptions.Builder projects​(List<? extends Object> projects)
        Parameters:
        projects - When the projects configuration is provided with an array of paths or glob patterns, Jest will run tests in all of the specified projects at the same time. This is great for monorepos or when working on multiple projects at the same time.
        Returns:
        this
      • reporters

        @Stability(Experimental)
        public JestConfigOptions.Builder reporters​(List<? extends JestReporter> reporters)
        Parameters:
        reporters - Use this configuration option to add custom reporters to Jest. A custom reporter is a class that implements onRunStart, onTestStart, onTestResult, onRunComplete methods that will be called when any of those events occurs.
        Returns:
        this
      • resetMocks

        @Stability(Experimental)
        public JestConfigOptions.Builder resetMocks​(Boolean resetMocks)
        Parameters:
        resetMocks - Automatically reset mock state before every test. Equivalent to calling jest.resetAllMocks() before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation.
        Returns:
        this
      • resetModules

        @Stability(Experimental)
        public JestConfigOptions.Builder resetModules​(Boolean resetModules)
        Parameters:
        resetModules - By default, each test file gets its own independent module registry. Enabling resetModules goes a step further and resets the module registry before running each individual test.
        Returns:
        this
      • restoreMocks

        @Stability(Experimental)
        public JestConfigOptions.Builder restoreMocks​(Boolean restoreMocks)
        Parameters:
        restoreMocks - Automatically restore mock state before every test. Equivalent to calling jest.restoreAllMocks() before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation.
        Returns:
        this
      • rootDir

        @Stability(Experimental)
        public JestConfigOptions.Builder rootDir​(String rootDir)
        Parameters:
        rootDir - The root directory that Jest should scan for tests and modules within. If you put your Jest config inside your package.json and want the root directory to be the root of your repo, the value for this config param will default to the directory of the package.json.
        Returns:
        this
      • setupFiles

        @Stability(Experimental)
        public JestConfigOptions.Builder setupFiles​(List<String> setupFiles)
        Parameters:
        setupFiles - A list of paths to modules that run some code to configure or set up the testing environment. Each setupFile will be run once per test file. Since every test runs in its own environment, these scripts will be executed in the testing environment immediately before executing the test code itself.
        Returns:
        this
      • setupFilesAfterEnv

        @Stability(Experimental)
        public JestConfigOptions.Builder setupFilesAfterEnv​(List<String> setupFilesAfterEnv)
        Parameters:
        setupFilesAfterEnv - A list of paths to modules that run some code to configure or set up the testing framework before each test file in the suite is executed. Since setupFiles executes before the test framework is installed in the environment, this script file presents you the opportunity of running some code immediately after the test framework has been installed in the environment.
        Returns:
        this
      • snapshotResolver

        @Stability(Experimental)
        public JestConfigOptions.Builder snapshotResolver​(String snapshotResolver)
        Parameters:
        snapshotResolver - The path to a module that can resolve test<->snapshot path. This config option lets you customize where Jest stores snapshot files on disk.
        Returns:
        this
      • testEnvironment

        @Stability(Experimental)
        public JestConfigOptions.Builder testEnvironment​(String testEnvironment)
        Parameters:
        testEnvironment - The test environment that will be used for testing. The default environment in Jest is a browser-like environment through jsdom. If you are building a node service, you can use the node option to use a node-like environment instead.
        Returns:
        this
      • testMatch

        @Stability(Experimental)
        public JestConfigOptions.Builder testMatch​(List<String> testMatch)
        Parameters:
        testMatch - The glob patterns Jest uses to detect test files. By default it looks for .js, .jsx, .ts and .tsx files inside of tests folders, as well as any files with a suffix of .test or .spec (e.g. Component.test.js or Component.spec.js). It will also find files called test.js or spec.js.
        Returns:
        this
      • testPathIgnorePatterns

        @Stability(Experimental)
        public JestConfigOptions.Builder testPathIgnorePatterns​(List<String> testPathIgnorePatterns)
        Parameters:
        testPathIgnorePatterns - 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.
        Returns:
        this
      • testRegex

        @Stability(Experimental)
        public JestConfigOptions.Builder testRegex​(String testRegex)
        Parameters:
        testRegex - The pattern or patterns Jest uses to detect test files. By default it looks for .js, .jsx, .ts and .tsx files inside of tests folders, as well as any files with a suffix of .test or .spec (e.g. Component.test.js or Component.spec.js). It will also find files called test.js or spec.js.
        Returns:
        this
      • testRegex

        @Stability(Experimental)
        public JestConfigOptions.Builder testRegex​(List<String> testRegex)
        Parameters:
        testRegex - The pattern or patterns Jest uses to detect test files. By default it looks for .js, .jsx, .ts and .tsx files inside of tests folders, as well as any files with a suffix of .test or .spec (e.g. Component.test.js or Component.spec.js). It will also find files called test.js or spec.js.
        Returns:
        this
      • testRunner

        @Stability(Experimental)
        public JestConfigOptions.Builder testRunner​(String testRunner)
        Parameters:
        testRunner - This option allows the use of a custom test runner. The default is jasmine2. A custom test runner can be provided by specifying a path to a test runner implementation.
        Returns:
        this
      • testUrl

        @Stability(Experimental)
        public JestConfigOptions.Builder testUrl​(String testUrl)
        Sets the value of JestConfigOptions#getTestUrl
        Parameters:
        testUrl - This option sets the URL for the jsdom environment. It is reflected in properties such as location.href.
        Returns:
        this
      • timers

        @Stability(Experimental)
        public JestConfigOptions.Builder timers​(String timers)
        Parameters:
        timers - Setting this value to legacy or fake allows the use of fake timers for functions such as setTimeout. Fake timers are useful when a piece of code sets a long timeout that we don't want to wait for in a test.
        Returns:
        this
      • transformIgnorePatterns

        @Stability(Experimental)
        public JestConfigOptions.Builder transformIgnorePatterns​(List<String> transformIgnorePatterns)
        Parameters:
        transformIgnorePatterns - An array of regexp pattern strings that are matched against all source file paths before transformation. If the test path matches any of the patterns, it will not be transformed.
        Returns:
        this
      • unmockedModulePathPatterns

        @Stability(Experimental)
        public JestConfigOptions.Builder unmockedModulePathPatterns​(List<String> unmockedModulePathPatterns)
        Parameters:
        unmockedModulePathPatterns - An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them. If a module's path matches any of the patterns in this list, it will not be automatically mocked by the module loader.
        Returns:
        this
      • verbose

        @Stability(Experimental)
        public JestConfigOptions.Builder verbose​(Boolean verbose)
        Parameters:
        verbose - Indicates whether each individual test should be reported during the run. All errors will also still be shown on the bottom after execution. Note that if there is only one test file being run it will default to true.
        Returns:
        this
      • watchPathIgnorePatterns

        @Stability(Experimental)
        public JestConfigOptions.Builder watchPathIgnorePatterns​(List<String> watchPathIgnorePatterns)
        Parameters:
        watchPathIgnorePatterns - An array of RegExp patterns that are matched against all source file paths before re-running tests in watch mode. If the file path matches any of the patterns, when it is updated, it will not trigger a re-run of tests.
        Returns:
        this