title: How to inject data imported by Firestore emulator into db instance
body: <p>I know that we can now <a href="https://stackoverflow.com/a/61501928">export and import data</a> with the Firestore emulator.</p>
  <p>How might one access the imported data in a unit testing environment? That is, when using <code>@firebase/testing</code>, we typically create the test app like so:</p>
  <pre><code>const db = firebase.initializeTestApp({ projectId: PROJECT_ID, auth}).firestore(); 
  </code></pre>
  <p><strong>How can one access the data imported thru the emulator and feed it into this db instance?</strong></p>
  <p>My use case is for running unit tests on firestore rules against the imported data (for reference, the desired setup is very similar to this other <a href="https://stackoverflow.com/questions/62953365/how-to-mock-data-for-testing-firestore-with-emulator">related question</a>, but instead of relying on a manually built mock object, I'd like to use data coming from the emulator export/import feature)</p>
  <p>Here is my test file</p>
  <pre><code>/**
   * unit tests for firestore security and data validation rules
   *
   * adapted from https://github.com/firebase/quickstart-testing/blob/master/unit-test-security-rules
   */
  const firebase = require(&quot;@firebase/testing&quot;);
  const fs = require(&quot;fs&quot;);
  const path = require(&quot;path&quot;)
  
  /**
   * The emulator will accept any project ID for testing.
   */
  const PROJECT_ID = &quot;test-dev-project&quot;;
  
  /**
   * The FIRESTORE_EMULATOR_HOST environment variable is set automatically
   * by &quot;firebase emulators:exec&quot;
   */
  const COVERAGE_URL = `http://${process.env.FIRESTORE_EMULATOR_HOST}/emulator/v1/projects/${PROJECT_ID}:ruleCoverage.html`;
  
  /**
   * Set up mock data
   */
  const mockUser = {
    uid: 'alice',
    email: 'alice@example.com',
    company: 'testCompany'
  }
  
  /**
   * Creates a new client FirebaseApp with authentication and returns the Firestore db instance.
   * @param {object} auth the object to use for authentication (typically {uid: some-uid})
   * @param {object} data the test data to use for filling the db
   * @return {object} the firestore instance db .
   */
  getAuthedDb = async (auth, data) =&gt; {
    // initialize test app
    const app = firebase.initializeTestApp({ projectId: PROJECT_ID, auth });
    let db = app.firestore();
    return db;
  };
  
  beforeEach(async () =&gt; {
    // Clear the database between tests
    await firebase.clearFirestoreData({ projectId: PROJECT_ID });
  });
  
  before(async () =&gt; {
    // Load the rules file before the tests begin
    const rules = fs.readFileSync(&quot;firestore.rules&quot;, &quot;utf8&quot;);
    await firebase.loadFirestoreRules({ projectId: PROJECT_ID, rules });
  });
  
  after(async () =&gt; {
    // Delete all the FirebaseApp instances created during testing
    // Note: this does not affect or clear any data
    await Promise.all(firebase.apps().map((app) =&gt; app.delete()));
    console.log(`View rule coverage information at ${COVERAGE_URL}\n`);
  });
  
  function printDoc(doc) {
    if (doc.exists) {
        console.log(`Document ${doc.id} data:`, doc.data());
    } else {
        // doc.data() will be undefined in this case
        console.log(`No such document: ${doc.ref.path}, parent: ${doc.ref.parent.id}`);
    }
  }
  
  describe(&quot;Test Security Rules&quot;, () =&gt; {
    it(&quot;fetches data imported from emulator&quot;, async () =&gt; {
      const db = await getAuthedDb({uid: 'abcd'});
      const ref = db.doc(&quot;testdata/ac7yWTZekvGJMQj6Zq3M&quot;);
      await firebase.assertSucceeds(ref.get().then(printDoc));
    });
  });
  </code></pre>
  <p>When I run <code>firebase emulators:exec --only firestore --import=data/ &quot;yarn run test-rules&quot;</code> (<code>test-rules</code> maps to <code>mocha --timeout 10000 test/test.spec.js</code>), the assert succeeds but the doc <code>&quot;testdata/ac7yWTZekvGJMQj6Zq3M&quot;</code> is not found, yet it exists in the data I'd imported from <code>data/</code></p>