Skip to content

Commit

Permalink
tests for getGraphId + calcTransformerOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Jun 18, 2021
1 parent 860e720 commit ef54802
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/metro/src/lib/__tests__/getGraphId-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,35 @@ describe('getGraphId', () => {
),
);
});

it('generates a unique id with unstable_disableModuleWrapping', () => {
const transformOptions = {
dev: true,
hot: true,
minify: true,
type: 'module',
platform: 'web',
runtimeBytecodeVersion: null,
unstable_transformProfile: 'default',
};
expect(
getGraphId(
'/root/waddup',
{
...transformOptions,
unstable_disableModuleWrapping: false,
},
{shallow: false, experimentalImportBundleSupport: false},
),
).not.toBe(
getGraphId(
'/root/waddup',
{
...transformOptions,
unstable_disableModuleWrapping: true,
},
{shallow: false, experimentalImportBundleSupport: false},
),
);
});
});
56 changes: 56 additions & 0 deletions packages/metro/src/lib/__tests__/transformHelpers-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails oncall+metro_bundler
* @format
*/

'use strict';

const {calcTransformerOptions} = require('../transformHelpers');

describe('calcTransformerOptions', () => {
const entryFiles = [];
const bundler = {};
const deltaBundler = {};
const options = {};

it('returns `unstable_disableModuleWrapping: false` by default', async () => {
const transformOptions = await calcTransformerOptions(
entryFiles,
bundler,
deltaBundler,
{
transformer: {
getTransformOptions: async () => ({
transform: {},
}),
},
},
options,
);
expect(transformOptions.unstable_disableModuleWrapping).toBe(false);
});

it('returns `unstable_disableModuleWrapping`', async () => {
const transformOptions = await calcTransformerOptions(
entryFiles,
bundler,
deltaBundler,
{
transformer: {
getTransformOptions: async () => ({
transform: {
unstable_disableModuleWrapping: true,
},
}),
},
},
options,
);
expect(transformOptions.unstable_disableModuleWrapping).toBe(true);
});
});
1 change: 1 addition & 0 deletions packages/metro/src/lib/transformHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ async function getResolveDependencyFn(
}

module.exports = {
calcTransformerOptions,
getTransformFn,
getResolveDependencyFn,
};

0 comments on commit ef54802

Please sign in to comment.