Skip to content

Commit

Permalink
Write unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lo-tp committed Apr 20, 2017
1 parent 32548c9 commit ff84fd5
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/jest-runtime/src/__tests__/transform-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
() => {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ff84fd5

Please sign in to comment.