mirror of https://github.com/status-im/metro.git
metro-bundler: DependencyGraph-test: proof of concept for proper test cleanup
Summary: The `DependencyGraph-test` hangs forever if run in isolation because the watch mode is not properly ended. I propose we just wrap each test in a function that does the correct thing, and also migrate tests to `async`/`await`. Reviewed By: cpojer Differential Revision: D5245477 fbshipit-source-id: ea30c0e637e0c7b85afe4c76c5e985846ae9b243
This commit is contained in:
parent
e87a8205d8
commit
4012f96c25
|
@ -220,6 +220,10 @@ class DependencyGraph extends EventEmitter {
|
|||
return this._haste;
|
||||
}
|
||||
|
||||
end() {
|
||||
this._haste.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the module object for the given path.
|
||||
*/
|
||||
|
|
|
@ -135,7 +135,21 @@ describe('DependencyGraph', function() {
|
|||
process.platform = realPlatform;
|
||||
});
|
||||
|
||||
it('should get dependencies', function() {
|
||||
/**
|
||||
* When running a test on the dependency graph, watch mode is enabled by
|
||||
* default, so we must end the watcher to ensure the test does not hang up
|
||||
* (regardless if the test passes or fails).
|
||||
*/
|
||||
async function processDgraph(options, processor) {
|
||||
const dgraph = await DependencyGraph.load(options);
|
||||
try {
|
||||
await processor(dgraph);
|
||||
} finally {
|
||||
dgraph.end();
|
||||
}
|
||||
}
|
||||
|
||||
it('should get dependencies', async function() {
|
||||
var root = '/root';
|
||||
setMockFileSystem({
|
||||
root: {
|
||||
|
@ -152,14 +166,12 @@ describe('DependencyGraph', function() {
|
|||
},
|
||||
});
|
||||
|
||||
var dgraph = DependencyGraph.load({
|
||||
...defaults,
|
||||
roots: [root],
|
||||
});
|
||||
return getOrderedDependenciesAsJSON(
|
||||
dgraph,
|
||||
'/root/index.js',
|
||||
).then(function(deps) {
|
||||
const opts = {...defaults, roots: [root]};
|
||||
return await processDgraph(opts, async dgraph => {
|
||||
const deps = await getOrderedDependenciesAsJSON(
|
||||
dgraph,
|
||||
'/root/index.js',
|
||||
);
|
||||
expect(deps).toEqual([
|
||||
{
|
||||
id: 'index',
|
||||
|
|
Loading…
Reference in New Issue