From d6d7639f0723c0db98705f3f7134bb63a270556a Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Fri, 26 May 2023 15:55:44 -0700 Subject: [PATCH 1/7] add jest transform config Signed-off-by: Jackie Han --- test/jest.config.js | 5 +++++ test/mocks/transformMock.js | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100644 test/mocks/transformMock.js diff --git a/test/jest.config.js b/test/jest.config.js index c726f920..7d59a1a0 100644 --- a/test/jest.config.js +++ b/test/jest.config.js @@ -44,4 +44,9 @@ module.exports = { testPathIgnorePatterns: ['/build/', '/node_modules/'], transformIgnorePatterns: ['/node_modules'], globalSetup: '/global-setup.js', + transform: { + '\\.[jt]sx?$': 'babel-jest', + '^.+\\.svg$': '/test/mocks/transformMock.js', + '^.+\\.html$': '/test/mocks/transformMock.js', + }, }; diff --git a/test/mocks/transformMock.js b/test/mocks/transformMock.js new file mode 100644 index 00000000..dcc08c81 --- /dev/null +++ b/test/mocks/transformMock.js @@ -0,0 +1,10 @@ +module.exports = { + process() { + return { + code: `module.exports = {};`, + }; + }, + getCacheKey() { + return 'svgTransform'; + }, +}; \ No newline at end of file From 48a64dee1388c1e866eb233896109de0bed78996 Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Tue, 30 May 2023 09:53:02 -0700 Subject: [PATCH 2/7] add license header Signed-off-by: Jackie Han --- test/mocks/transformMock.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/mocks/transformMock.js b/test/mocks/transformMock.js index dcc08c81..50b99e4c 100644 --- a/test/mocks/transformMock.js +++ b/test/mocks/transformMock.js @@ -1,3 +1,7 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ module.exports = { process() { return { From ee14cc819856b9d6bf258c5b53db7ad844f2ca1c Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Tue, 30 May 2023 09:57:53 -0700 Subject: [PATCH 3/7] update file as .ts file Signed-off-by: Jackie Han --- test/jest.config.js | 4 ++-- test/mocks/{transformMock.js => transformMock.ts} | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) rename test/mocks/{transformMock.js => transformMock.ts} (72%) diff --git a/test/jest.config.js b/test/jest.config.js index 7d59a1a0..b71f095f 100644 --- a/test/jest.config.js +++ b/test/jest.config.js @@ -46,7 +46,7 @@ module.exports = { globalSetup: '/global-setup.js', transform: { '\\.[jt]sx?$': 'babel-jest', - '^.+\\.svg$': '/test/mocks/transformMock.js', - '^.+\\.html$': '/test/mocks/transformMock.js', + '^.+\\.svg$': '/test/mocks/transformMock.ts', + '^.+\\.html$': '/test/mocks/transformMock.ts', }, }; diff --git a/test/mocks/transformMock.js b/test/mocks/transformMock.ts similarity index 72% rename from test/mocks/transformMock.js rename to test/mocks/transformMock.ts index 50b99e4c..d0436ea6 100644 --- a/test/mocks/transformMock.js +++ b/test/mocks/transformMock.ts @@ -2,13 +2,13 @@ * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ -module.exports = { - process() { +export = { + process(): { code: string } { return { code: `module.exports = {};`, }; }, - getCacheKey() { + getCacheKey(): string { return 'svgTransform'; }, }; \ No newline at end of file From 32951836d4447d9c4038454fae3ee98b3f8f13b6 Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Tue, 30 May 2023 10:01:18 -0700 Subject: [PATCH 4/7] add comment on jest config file Signed-off-by: Jackie Han --- test/jest.config.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/jest.config.js b/test/jest.config.js index b71f095f..242924cc 100644 --- a/test/jest.config.js +++ b/test/jest.config.js @@ -44,6 +44,11 @@ module.exports = { testPathIgnorePatterns: ['/build/', '/node_modules/'], transformIgnorePatterns: ['/node_modules'], globalSetup: '/global-setup.js', + + /** + * This configuration specifies different file extensions + * and the corresponding transformers to be used + */ transform: { '\\.[jt]sx?$': 'babel-jest', '^.+\\.svg$': '/test/mocks/transformMock.ts', From 2b1204b9fb8aea54f5c087c4b76b1021673d17fe Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Tue, 30 May 2023 10:25:13 -0700 Subject: [PATCH 5/7] add more comments Signed-off-by: Jackie Han --- test/mocks/transformMock.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/mocks/transformMock.ts b/test/mocks/transformMock.ts index d0436ea6..a85ba9a5 100644 --- a/test/mocks/transformMock.ts +++ b/test/mocks/transformMock.ts @@ -2,12 +2,25 @@ * 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. + */ export = { + /** + * This function is responsible for transforming the file. + * @returns the string module.exports = {};, which is an empty CommonJS module. + */ process(): { code: string } { 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 returns a unique string that serves as a cache key for the transformation. + */ getCacheKey(): string { return 'svgTransform'; }, From 2778ecae47662343d6533566dd5983f1df9d1b77 Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Tue, 30 May 2023 10:26:55 -0700 Subject: [PATCH 6/7] cleanup Signed-off-by: Jackie Han --- test/mocks/transformMock.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mocks/transformMock.ts b/test/mocks/transformMock.ts index a85ba9a5..f13f4326 100644 --- a/test/mocks/transformMock.ts +++ b/test/mocks/transformMock.ts @@ -19,7 +19,7 @@ export = { }, /** * The cache key helps Jest determine if a file needs to be retransformed or if it can use the cached transformation result. - * @returns returns a unique string that serves as a cache key for the transformation. + * @returns a unique string that serves as a cache key for the transformation. */ getCacheKey(): string { return 'svgTransform'; From b29e75b923b51665472a4f423dc0482cda0efce5 Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Tue, 30 May 2023 11:40:21 -0700 Subject: [PATCH 7/7] update file export Signed-off-by: Jackie Han --- test/mocks/transformMock.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/mocks/transformMock.ts b/test/mocks/transformMock.ts index f13f4326..ac888d71 100644 --- a/test/mocks/transformMock.ts +++ b/test/mocks/transformMock.ts @@ -7,12 +7,12 @@ * The transform configuration in Jest allows you to * specify custom transformation logic for specific file types during testing. */ -export = { +module.exports = { /** * This function is responsible for transforming the file. * @returns the string module.exports = {};, which is an empty CommonJS module. */ - process(): { code: string } { + process() { return { code: `module.exports = {};`, }; @@ -21,7 +21,7 @@ export = { * 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(): string { + getCacheKey() { return 'svgTransform'; }, }; \ No newline at end of file