Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Connormiha committed Apr 16, 2018
1 parent 268744d commit d501ef1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/jest-runtime/src/__tests__/script_transformer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jest.mock(
{virtual: true},
);

// Bad preprocessor
jest.mock(
'skipped-required-props-preprocessor',
() => {
Expand All @@ -93,6 +94,7 @@ jest.mock(
{virtual: true},
);

// Bad preprocessor
jest.mock(
'skipped-required-create-transformer-props-preprocessor',
() => {
Expand All @@ -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)) {
Expand Down Expand Up @@ -304,6 +322,16 @@ describe('ScriptTransformer', () => {
).toThrow('Jest: a transform must export a `process` function.');
});

it("shouldn't throw error without 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']],
Expand Down

0 comments on commit d501ef1

Please sign in to comment.