title: Nest can't resolve dependencies in the RootTestModule context when I use Bazel Test
body: <p>I need to run my tests in the bezel. how can I solve this mysterious problem?</p>
  <p>I have a nestjs project contains multiple apps and libs. When I run the test <code>yarn jest --config ./jest.config.json libs/lib1</code>, it works perfectly. However when I run with bezel <code>bazel test //libs/lib1/...</code> it gives me an error &quot;Nest can't resolve dependencies ... Please make sure that the argument dependency at index ... is available in the RootTestModule context.&quot;.</p>
  <p>REPO</p>
  <pre><code>https://github.com/smhmayboudi/bazel_jest_nestjs
  </code></pre>
  <p>I find out that the order of mapping at jest.config.json is important.
  this one works well ( shows test + coverage ), but dependency problem</p>
  <pre><code>  &quot;moduleNameMapper&quot;: {
      &quot;@melo/lib1&quot;: &quot;&lt;rootDir&gt;/libs/lib1/src&quot;,
      &quot;@melo/lib1/(.*)&quot;: &quot;&lt;rootDir&gt;/libs/lib1/src/$1&quot;,
    },
  </code></pre>
  <p>this one works ( show just pass message with out actual test result and coverage !? )</p>
  <pre><code>  &quot;moduleNameMapper&quot;: {
      &quot;@melo/lib1/(.*)&quot;: &quot;&lt;rootDir&gt;/libs/lib1/src/$1&quot;,
      &quot;@melo/lib1&quot;: &quot;&lt;rootDir&gt;/libs/lib1/src&quot;,
    },
  </code></pre>
  <p>Jest Config</p>
  <pre><code>{
    &quot;coverageReporters&quot;: [&quot;lcov&quot;, &quot;text-summary&quot;],
    &quot;moduleNameMapper&quot;: {
      &quot;@melo/libs1&quot;: &quot;&lt;rootDir&gt;/libs/libs1/src&quot;,
      &quot;@melo/libs1/(.*)&quot;: &quot;&lt;rootDir&gt;/libs/libs1/src/$1&quot;,
    },
    &quot;modulePathIgnorePatterns&quot;: [&quot;/bazel-out/&quot;, &quot;/node_modules/&quot;],
    &quot;preset&quot;: &quot;ts-jest&quot;,
    &quot;testEnvironment&quot;: &quot;node&quot;
  }
  </code></pre>
  <p>Bazel Config</p>
  <pre><code>ts_library(
      name = &quot;lib1_test_ts_library&quot;,
      srcs = glob([&quot;*spec.ts&quot;]),
      runtime = &quot;nodejs&quot;,
      deps = [
          &quot;:lib1_ts_library&quot;,
          &quot;@npm//@nestjs/common&quot;,
          &quot;@npm//@nestjs/testing&quot;,
          &quot;@npm//@types/jest&quot;,
          &quot;@npm//rxjs&quot;,
          &quot;@npm//ts-jest&quot;,
      ],
  )
  
  jest_test(
      name = &quot;lib1_jest_test&quot;,
      srcs = glob([&quot;*spec.ts&quot;]),
      jest_config = &quot;//:jest.config.json&quot;,
      deps = [
          &quot;:lib1_test_ts_library&quot;,
      ],
      coverage = True,
  )
  </code></pre>
  <p>Error Log</p>
  <pre><code>INFO: Invocation ID: 84f45d55-c6e4-4c2a-b05d-367d0f84baf7
  INFO: Analyzed target //libs/lib1/src:lib1_jest_test (633 packages loaded, 19569 targets configured).
  INFO: Found 1 test target...
  WARNING: failed to create one or more convenience symlinks for prefix 'dist/':
    cannot create symbolic link bazel-out -&gt; /Users/WHOAMI/Developer/MY_PROJECT/bazel-out/execroot/melo/bazel-out:  /Users/WHOAMI/Developer/MY_PROJECT/bazel-out (File exists)
  FAIL: //libs/lib1/src:lib1_jest_test (see /Users/WHOAMI/Developer/MY_PROJECT/bazel-out/execroot/melo/bazel-out/darwin-fastbuild/testlogs/libs/lib1/src/lib1_jest_test/test.log)
  INFO: From Testing //libs/lib1/src:lib1_jest_test:
  ==================== Test output for //libs/lib1/src:lib1_jest_test:
  PASS libs/lib1/src/lib1.util.spec.ts (23.866 s)
  PASS libs/lib1/src/lib1.interceptor.spec.ts (23.977 s)
  FAIL libs/lib1/src/lib1.service.spec.ts (24.717 s)
    ● ApmService › should be defined
  
      Nest can't resolve dependencies of the ApmService (?). Please make sure that the argument dependency at index [0] is available in the RootTestModule context.
  
      Potential solutions:
      - If dependency is a provider, is it part of the current RootTestModule?
      - If dependency is exported from a separate @Module, is that module imported within RootTestModule?
        @Module({
          imports: [ /* the Module containing dependency */ ]
        })
  
        at Injector.resolveSingleParam (../../../../../../../../node_modules/@nestjs/core/injector/injector.js:134:19)
        at resolveParam (../../../../../../../../node_modules/@nestjs/core/injector/injector.js:102:49)
            at Array.map (&lt;anonymous&gt;)
        at Injector.resolveConstructorParams (../../../../../../../../node_modules/@nestjs/core/injector/injector.js:117:58)
        at Injector.loadInstance (../../../../../../../../node_modules/@nestjs/core/injector/injector.js:81:20)
        at Injector.loadProvider (../../../../../../../../node_modules/@nestjs/core/injector/injector.js:38:20)
        at ../../../../../../../../node_modules/@nestjs/core/injector/instance-loader.js:43:62
            at Array.map (&lt;anonymous&gt;)
        at InstanceLoader.createInstancesOfProviders (../../../../../../../../node_modules/@nestjs/core/injector/instance-loader.js:43:36)
        at ../../../../../../../../node_modules/@nestjs/core/injector/instance-loader.js:28:24
  
    ● ApmService › should be defined
  
      expect(received).toBeDefined()
  
      Received: undefined
  
        56 | 
        57 |   it(&quot;should be defined&quot;, () =&gt; {
      &gt; 58 |     expect(service).toBeDefined();
           |                     ^
        59 |   });
        60 | 
        61 |   it(&quot;start should be called&quot;, () =&gt; {
  
        at Object.&lt;anonymous&gt; (libs/lib1/src/lib1.service.spec.ts:58:21)
  
  ...
  
  Test Suites: 2 failed, 2 passed, 4 total
  Tests:       27 failed, 3 todo, 6 passed, 36 total
  Snapshots:   0 total
  Time:        26.102 s
  Ran all test suites within paths &quot;libs/lib1/src/lib1.decorator.spec.ts&quot;, &quot;libs/lib1/src/lib1.interceptor.spec.ts&quot;, &quot;libs/lib1/src/lib1.service.spec.ts&quot;, &quot;libs/lib1/src/lib1.util.spec.ts&quot;.
  ================================================================================
  Target //libs/lib1/src:lib1_jest_test up-to-date:
    dist/bin/libs/lib1/src/lib1_jest_test.sh
    dist/bin/libs/lib1/src/lib1_jest_test_loader.js
    dist/bin/libs/lib1/src/lib1_jest_test_require_patch.js
  INFO: Elapsed time: 83.878s, Critical Path: 59.53s
  INFO: 4 processes: 4 local.
  INFO: Build completed, 1 test FAILED, 12 total actions
  //libs/lib1/src:lib1_jest_test                                             FAILED in 28.2s
    /Users/WHOAMI/Developer/MY_PROJECT/bazel-out/execroot/melo/bazel-out/darwin-fastbuild/testlogs/libs/lib1/src/lib1_jest_test/test.log
  
  INFO: Build completed, 1 test FAILED, 12 total actions
  </code></pre>