Skip to content
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

add jest transform config #497

Merged
merged 7 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
},
};