Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom platforms on jest-haste-map #3162

Merged
merged 2 commits into from
Mar 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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