mirror of
https://github.com/status-im/metro.git
synced 2025-02-08 09:14:39 +00:00
Allow to configure the name of the require in the traverseDependency tests
Reviewed By: jeanlauliac Differential Revision: D7258095 fbshipit-source-id: 3cf11148ed58ba0b8802513db0731787a4d83773
This commit is contained in:
parent
cf5a431388
commit
6a587db117
@ -58,18 +58,19 @@ const Actions = {
|
|||||||
return module;
|
return module;
|
||||||
},
|
},
|
||||||
|
|
||||||
addDependency(path, dependencyPath, position) {
|
addDependency(path, dependencyPath, position, name = null) {
|
||||||
let dependency = dependencyGraph.getModuleForPath(dependencyPath);
|
let dependency = dependencyGraph.getModuleForPath(dependencyPath);
|
||||||
if (!dependency) {
|
if (!dependency) {
|
||||||
dependency = Actions.createFile(dependencyPath);
|
dependency = Actions.createFile(dependencyPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
const deps = mockedDependencyTree.get(path);
|
const deps = mockedDependencyTree.get(path);
|
||||||
|
name = name || dependency.name;
|
||||||
|
|
||||||
if (position == null) {
|
if (position == null) {
|
||||||
deps.push(dependency);
|
deps.push({name, dependency});
|
||||||
} else {
|
} else {
|
||||||
deps.splice(position, 0, dependency);
|
deps.splice(position, 0, {name, dependency});
|
||||||
}
|
}
|
||||||
|
|
||||||
mockedDependencyTree.set(path, deps);
|
mockedDependencyTree.set(path, deps);
|
||||||
@ -79,11 +80,12 @@ const Actions = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
removeDependency(path, dependencyPath) {
|
removeDependency(path, dependencyPath) {
|
||||||
const dependency = dependencyGraph.getModuleForPath(dependencyPath);
|
const dep = dependencyGraph.getModuleForPath(dependencyPath);
|
||||||
const deps = mockedDependencyTree.get(path);
|
const deps = mockedDependencyTree.get(path);
|
||||||
|
|
||||||
if (deps.indexOf(dependency) !== -1) {
|
const index = deps.findIndex(({dependency}) => dep === dependency);
|
||||||
deps.splice(deps.indexOf(dependency), 1);
|
if (index !== -1) {
|
||||||
|
deps.splice(index, 1);
|
||||||
mockedDependencyTree.set(path, deps);
|
mockedDependencyTree.set(path, deps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +146,7 @@ beforeEach(async () => {
|
|||||||
},
|
},
|
||||||
resolveDependency(module, relativePath) {
|
resolveDependency(module, relativePath) {
|
||||||
const deps = mockedDependencyTree.get(module.path);
|
const deps = mockedDependencyTree.get(module.path);
|
||||||
const dependency = deps.filter(dep => dep.name === relativePath)[0];
|
const {dependency} = deps.filter(dep => dep.name === relativePath)[0];
|
||||||
|
|
||||||
if (!mockedDependencies.has(dependency)) {
|
if (!mockedDependencies.has(dependency)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -312,8 +314,6 @@ describe('edge cases', () => {
|
|||||||
const edges = new Map();
|
const edges = new Map();
|
||||||
await initialTraverseDependencies('/bundle', dependencyGraph, {}, edges);
|
await initialTraverseDependencies('/bundle', dependencyGraph, {}, edges);
|
||||||
|
|
||||||
mockedDependencyTree.set(moduleFoo.path, [moduleBar]);
|
|
||||||
|
|
||||||
Actions.modifyFile('/baz');
|
Actions.modifyFile('/baz');
|
||||||
Actions.removeDependency('/foo', '/baz');
|
Actions.removeDependency('/foo', '/baz');
|
||||||
|
|
||||||
@ -419,9 +419,15 @@ describe('edge cases', () => {
|
|||||||
|
|
||||||
// Create a dependency tree where moduleBaz has two inverse dependencies.
|
// Create a dependency tree where moduleBaz has two inverse dependencies.
|
||||||
mockedDependencyTree = new Map([
|
mockedDependencyTree = new Map([
|
||||||
[entryModule.path, [moduleFoo, moduleBar]],
|
[
|
||||||
[moduleFoo.path, [moduleBaz]],
|
entryModule.path,
|
||||||
[moduleBar.path, [moduleBaz]],
|
[
|
||||||
|
{name: 'foo', dependency: moduleFoo},
|
||||||
|
{name: 'bar', dependency: moduleBar},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[moduleFoo.path, [{name: 'baz', dependency: moduleBaz}]],
|
||||||
|
[moduleBar.path, [{name: 'baz', dependency: moduleBaz}]],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Test that even when having different modules taking longer, the order
|
// Test that even when having different modules taking longer, the order
|
||||||
|
Loading…
x
Reference in New Issue
Block a user