diff --git a/packages/jest-runtime/src/__tests__/script_transformer.test.js b/packages/jest-runtime/src/__tests__/script_transformer.test.js index 4f4a30fae925..4e1ac2509cba 100644 --- a/packages/jest-runtime/src/__tests__/script_transformer.test.js +++ b/packages/jest-runtime/src/__tests__/script_transformer.test.js @@ -85,6 +85,7 @@ jest.mock( {virtual: true}, ); +// Bad preprocessor jest.mock( 'skipped-required-props-preprocessor', () => { @@ -93,6 +94,7 @@ jest.mock( {virtual: true}, ); +// Bad preprocessor jest.mock( 'skipped-required-create-transformer-props-preprocessor', () => { @@ -105,6 +107,22 @@ jest.mock( {virtual: true}, ); +jest.mock( + 'skipped-process-method-preprocessor', + () => { + return { + createTransformer() { + const mockProcess = jest.fn(); + mockProcess.mockReturnValue('code'); + return { + process: mockProcess, + }; + }, + }; + }, + {virtual: true}, +); + const getCachePath = (fs, config) => { for (const path in mockFs) { if (path.startsWith(config.cacheDirectory)) { @@ -304,6 +322,16 @@ describe('ScriptTransformer', () => { ).toThrow('Jest: a transform must export a `process` function.'); }); + it("shouldn't throw error witthout process method. But with corrent createTransformer method", () => { + Object.assign(config, { + transform: [['^.+\\.js$', 'skipped-process-method-preprocessor']], + }); + const scriptTransformer = new ScriptTransformer(config); + expect(() => + scriptTransformer.transformSource('sample.js', '', false), + ).not.toThrow(); + }); + it('uses the supplied preprocessor', () => { config = Object.assign(config, { transform: [['^.+\\.js$', 'test_preprocessor']],