From ff84fd5399a5da0fd1ac353b61be49fd4895caae Mon Sep 17 00:00:00 2001 From: lo-tp Date: Mon, 17 Apr 2017 16:29:08 +0800 Subject: [PATCH] Write unit test --- .../src/__tests__/transform-test.js | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/jest-runtime/src/__tests__/transform-test.js b/packages/jest-runtime/src/__tests__/transform-test.js index 196de7d1be52..3d520c09761b 100644 --- a/packages/jest-runtime/src/__tests__/transform-test.js +++ b/packages/jest-runtime/src/__tests__/transform-test.js @@ -23,6 +23,29 @@ jest }) .mock('vm'); +jest.mock( + 'test-preprocessor-2', + () => { + const escapeStrings = str => { + return str.replace(/'/, `'`); + }; + + return { + getCacheKey: jest.fn((content, filename, configStr) => 'ab'), + process: (content, filename, config) => { + return ` + const TRANSFORMED = { + filename: '${escapeStrings(filename)}', + script: '${escapeStrings(content)+'second'}', + config: '${escapeStrings(JSON.stringify(config))}', + }; + `; + }, + }; + }, + {virtual: true}, +); + jest.mock( 'test-preprocessor', () => { @@ -145,6 +168,23 @@ describe('transform', () => { beforeEach(reset); + it('retransform when transform argument is changed', () => { + let localConfig = Object.assign(config, { + transform: [['^.+\\.js$', 'test-preprocessor-2']], + }); + + const response = transform('/fruits/banana.js', localConfig).script; + const snapshot = vm.Script.mock.calls[0][0]; + + localConfig = Object.assign(config, { + transform: [['^.+\\.js$', 'test-preprocessor']], + }); + + reset(); + transform('/fruits/banana.js', localConfig); + expect(vm.Script.mock.calls[0][0]).not.toEqual(snapshot); + + }); it('transforms a file properly', () => { config.collectCoverage = true; const response = transform('/fruits/banana.js', config).script;