Skip to content

Commit

Permalink
Support custom platforms on jest-haste-map (#3162)
Browse files Browse the repository at this point in the history
* Support custom platforms on jest-haste-map

* Run prettier
  • Loading branch information
andrewimm authored and cpojer committed Mar 17, 2017
1 parent 2b3761c commit eed8203
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
6 changes: 4 additions & 2 deletions packages/jest-haste-map/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,10 @@ class HasteMap extends EventEmitter {
map[id] = Object.create(null);
}
const moduleMap = map[id];
const platform = getPlatformExtension(module[H.PATH]) ||
H.GENERIC_PLATFORM;
const platform = getPlatformExtension(
module[H.PATH],
this._options.platforms,
) || H.GENERIC_PLATFORM;
const existingModule = moduleMap[platform];
if (existingModule && existingModule[H.PATH] !== module[H.PATH]) {
const message = `jest-haste-map: @providesModule naming collision:\n` +
Expand Down
9 changes: 8 additions & 1 deletion packages/jest-haste-map/src/lib/getPlatformExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ const SUPPORTED_PLATFORM_EXTS = {
};

// Extract platform extension: index.ios.js -> ios
function getPlatformExtension(file: string): ?string {
function getPlatformExtension(
file: string,
platforms?: Array<string>,
): ?string {
const last = file.lastIndexOf('.');
const secondToLast = file.lastIndexOf('.', last - 1);
if (secondToLast === -1) {
return null;
}
const platform = file.substring(secondToLast + 1, last);
// If an overriding platform array is passed, check that first
if (platforms && platforms.includes(platform)) {
return platform;
}
return SUPPORTED_PLATFORM_EXTS[platform] ? platform : null;
}

Expand Down
7 changes: 1 addition & 6 deletions packages/jest-jasmine2/src/jasmine-light.js
Original file line number Diff line number Diff line change
Expand Up @@ -1654,12 +1654,7 @@ exports.TreeProcessor = function() {
return executableIndex === undefined ? defaultMax : executableIndex;
}

function segmentChildren(
node,
children,
nodeStats,
executableIndex,
) {
function segmentChildren(node, children, nodeStats, executableIndex) {
let currentSegment = {
index: 0,
owner: node,
Expand Down
6 changes: 4 additions & 2 deletions packages/jest-matchers/src/asymmetric-matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ class ArrayContaining extends AsymmetricMatcher {
);
}

return this.sample.length === 0 || Array.isArray(other) &&
this.sample.every(item => other.some(another => equals(item, another)));
return this.sample.length === 0 ||
(Array.isArray(other) &&
this.sample.every(item =>
other.some(another => equals(item, another))));
}

toString() {
Expand Down

0 comments on commit eed8203

Please sign in to comment.