Skip to content
Prev Previous commit
Next Next commit
Fix normalize tests
  • Loading branch information
robin-drexler committed May 16, 2018
commit 161dc5ec7bcd10d0d4b1524dab6868a60551af75
27 changes: 9 additions & 18 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ describe('preset', () => {
beforeEach(() => {
const Resolver = require('jest-resolve');
Resolver.findNodeModule = jest.fn(name => {
if (name === 'react-native/jest-preset.json') {
if (name === 'react-native/jest-preset') {
return '/node_modules/react-native/jest-preset.json';
}
return '/node_modules/' + name;
Expand Down Expand Up @@ -961,28 +961,19 @@ describe('preset', () => {
}).not.toThrow();
});

test('supports .json preset files', () => {
const {options} = normalize(
{
preset: 'with-json-ext',
rootDir: '/root/path/foo',
},
{},
);

expect(options.moduleNameMapper).toEqual([['json', true]]);
});
test('searches for .json and .js preset files', () => {
const Resolver = require('jest-resolve');

test('supports .js preset files', () => {
const {options} = normalize(
normalize(
{
preset: 'with-js-ext',
preset: 'react-native',
rootDir: '/root/path/foo',
},
{},
);

expect(options.moduleNameMapper).toEqual([['js', true]]);
const options = Resolver.findNodeModule.mock.calls[0][1];
expect(options.extensions).toEqual(['.json', '.js']);
});

test('merges with options', () => {
Expand Down Expand Up @@ -1074,7 +1065,7 @@ describe('preset without setupFiles', () => {

beforeAll(() => {
jest.doMock(
'/node_modules/react-foo/jest-preset.json',
'/node_modules/react-foo/jest-preset',
() => {
return {
moduleNameMapper: {b: 'b'},
Expand All @@ -1086,7 +1077,7 @@ describe('preset without setupFiles', () => {
});

afterAll(() => {
jest.dontMock('/node_modules/react-foo/jest-preset.json');
jest.dontMock('/node_modules/react-foo/jest-preset');
});

it('should normalize setupFiles correctly', () => {
Expand Down