Skip to content

Commit

Permalink
jest-haste-map: add test to demonstrate broken behavior for platform-…
Browse files Browse the repository at this point in the history
…specific files
  • Loading branch information
Jean Lauliac committed Feb 9, 2018
1 parent fc14ac8 commit 490f34c
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions packages/jest-haste-map/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,100 @@ describe('HasteMap', () => {
});
});

it('correctly handles platform-specific file additions', async () => {
mockFs = Object.create(null);
mockFs['/fruits/strawberry.js'] = [
'/**',
' * @providesModule Strawberry',
' */',
'const Banana = require("Banana");',
].join('\n');
let data;
({__hasteMapForTest: data} = await new HasteMap(defaultConfig).build());
expect(data.map['Strawberry']).toEqual({
g: ['/fruits/strawberry.js', 0],
});

delete mockFs['/fruits/strawberry.ios.js'];
mockChangedFiles = object({
'/fruits/strawberry.ios.js': [
'/**',
' * @providesModule Strawberry',
' */',
'const Raspberry = require("Raspberry");',
].join('\n'),
});
mockClocks = object({'/fruits': 'c:fake-clock:3'});
({__hasteMapForTest: data} = await new HasteMap(defaultConfig).build());
expect(data.map['Strawberry']).toEqual({
g: ['/fruits/strawberry.js', 0],
ios: ["/fruits/strawberry.ios.js", 0],
});
});

it('correctly handles platform-specific file deletions (broken)', async () => {
mockFs = Object.create(null);
mockFs['/fruits/strawberry.js'] = [
'/**',
' * @providesModule Strawberry',
' */',
'const Banana = require("Banana");',
].join('\n');
mockFs['/fruits/strawberry.ios.js'] = [
'/**',
' * @providesModule Strawberry',
' */',
'const Raspberry = require("Raspberry");',
].join('\n');
let data;
({__hasteMapForTest: data} = await new HasteMap(defaultConfig).build());
expect(data.map['Strawberry']).toEqual({
g: ['/fruits/strawberry.js', 0],
ios: ["/fruits/strawberry.ios.js", 0],
});

delete mockFs['/fruits/strawberry.ios.js'];
mockChangedFiles = object({'/fruits/strawberry.ios.js': null});
mockClocks = object({'/fruits': 'c:fake-clock:3'});
({__hasteMapForTest: data} = await new HasteMap(defaultConfig).build());
expect(data.map['Strawberry']).toEqual({
g: ['/fruits/strawberry.js', 0],
// FIXME: this file should NOT exist anymore!
ios: ["/fruits/strawberry.ios.js", 0],
});
});

it('correctly handles platform-specific file renames', async () => {
mockFs = Object.create(null);
mockFs['/fruits/strawberry.ios.js'] = [
'/**',
' * @providesModule Strawberry',
' */',
'const Raspberry = require("Raspberry");',
].join('\n');
let data;
({__hasteMapForTest: data} = await new HasteMap(defaultConfig).build());
expect(data.map['Strawberry']).toEqual({
ios: ["/fruits/strawberry.ios.js", 0],
});

delete mockFs['/fruits/strawberry.ios.js'];
mockChangedFiles = object({
'/fruits/strawberry.js': [
'/**',
' * @providesModule Strawberry',
' */',
'const Banana = require("Banana");',
].join('\n'),
'/fruits/strawberry.ios.js': null,
});
mockClocks = object({'/fruits': 'c:fake-clock:3'});
({__hasteMapForTest: data} = await new HasteMap(defaultConfig).build());
expect(data.map['Strawberry']).toEqual({
g: ['/fruits/strawberry.js', 0],
});
});

describe('duplicate modules', () => {
beforeEach(async () => {
mockFs['/fruits/another_strawberry.js'] = [
Expand Down

0 comments on commit 490f34c

Please sign in to comment.