Skip to content

Commit

Permalink
add jest transform config (opensearch-project#497)
Browse files Browse the repository at this point in the history
* add jest transform config

Signed-off-by: Jackie Han <jkhanjob@gmail.com>

* add license header

Signed-off-by: Jackie Han <jkhanjob@gmail.com>

* update file as .ts file

Signed-off-by: Jackie Han <jkhanjob@gmail.com>

* add comment on jest config file

Signed-off-by: Jackie Han <jkhanjob@gmail.com>

* add more comments

Signed-off-by: Jackie Han <jkhanjob@gmail.com>

* cleanup

Signed-off-by: Jackie Han <jkhanjob@gmail.com>

* update file export

Signed-off-by: Jackie Han <jkhanjob@gmail.com>

---------

Signed-off-by: Jackie Han <jkhanjob@gmail.com>
  • Loading branch information
jackiehanyang authored and amitgalitz committed Jul 7, 2023
1 parent b6b5d2a commit af963a9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ module.exports = {
testPathIgnorePatterns: ['<rootDir>/build/', '<rootDir>/node_modules/'],
transformIgnorePatterns: ['<rootDir>/node_modules'],
globalSetup: '<rootDir>/global-setup.js',

/**
* This configuration specifies different file extensions
* and the corresponding transformers to be used
*/
transform: {
'\\.[jt]sx?$': 'babel-jest',
'^.+\\.svg$': '<rootDir>/test/mocks/transformMock.ts',
'^.+\\.html$': '<rootDir>/test/mocks/transformMock.ts',
},
};
27 changes: 27 additions & 0 deletions test/mocks/transformMock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

/**
* The transform configuration in Jest allows you to
* specify custom transformation logic for specific file types during testing.
*/
module.exports = {
/**
* This function is responsible for transforming the file.
* @returns the string module.exports = {};, which is an empty CommonJS module.
*/
process() {
return {
code: `module.exports = {};`,
};
},
/**
* The cache key helps Jest determine if a file needs to be retransformed or if it can use the cached transformation result.
* @returns a unique string that serves as a cache key for the transformation.
*/
getCacheKey() {
return 'svgTransform';
},
};

0 comments on commit af963a9

Please sign in to comment.