go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/examples/reactjs/example_app/jest.config.js (about)

     1  // Copyright 2022 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
    16  // eslint-disable-next-line no-undef
    17  module.exports = {
    18    /**
    19      * This resolved many issues that may occur while importing 3rd party tools.
    20      */
    21    preset: 'ts-jest/presets/js-with-ts',
    22    /**
    23      * The test env is JSDom as it enables us to use
    24      * `window` and other browser specific variables.
    25      */
    26    testEnvironment: 'jsdom',
    27    /**
    28      * files with `.spec.ts` are reserved for cypress tests.
    29      */
    30    testMatch: [
    31      '**/__tests__/**/*.[jt]s?(x)',
    32      '**/?(*.)+(test).[jt]s?(x)',
    33    ],
    34    /**
    35      * The reason we need to set this is because we are
    36      * importing node_modules which are using
    37      * `es6` modules and that is not compatible with jest,
    38      * so we need to transform them.
    39      */
    40    transformIgnorePatterns: [
    41      '/node_modules/(?!(lit-element|lit-html|@material|lit|@lit|node-fetch|data-uri-to-buffer|fetch-blob|formdata-polyfill)/)',
    42    ],
    43    /**
    44     * This allows components to import styling files without
    45     * failing the jest build.
    46     */
    47    moduleNameMapper: {
    48      '\\.(css|less|scss)$': 'identity-obj-proxy',
    49      '@/(.*)': '<rootDir>/src/$1',
    50    },
    51    /**
    52      * This files initializes the required environment for jest and react.
    53      */
    54    setupFiles: [
    55      './src/testing_tools/setUpEnv.ts',
    56    ],
    57  };