1

We're trying to query Firestore via a k6 script on a collection.
In order to integrate the Firestore library we followed this guide on k6 website:
https://k6.io/docs/using-k6/modules/#setting-up-the-bundler

When we run our script we get this weird error, that we can't find on Firestore documentation:

@firebase/firestore: Firestore (8.1.2): AsyncQueue Initialization of query 'Query(target=Target(my_collection_here, orderBy: [timestamp (asc), name (asc)]); limitType=F)' failed: TypeError: Value is not an object: undefined

The script is this:

import 'core-js/stable';
import 'regenerator-runtime/runtime';
import firebase from 'firebase/app';
import 'firebase/firestore';
import { sleep } from 'k6';
import behavior from './tests/behaviors/index.js';
import scenariosAndStages from './tests/options/index.js';

const firebaseConfig = {
  apiKey: ***,
  authDomain: ***,
  projectId: ***,
  storageBucket: ***,
  messagingSenderId: ***,
  appId: ***,
};

firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();

const conf = {
  multiply: __ENV.MULTIPLY || 1,
};

export const options = {
  ext: {
    loadimpact: {
      name: __ENV.NAME,
      projectID: __ENV.PROJECT_ID,
      distribution: {
        'amazon:us:ashburn': { loadZone: 'amazon:us:ashburn', percent: 100 },
      },
    },
  },
  discardResponseBodies: true,
  scenarios: __ENV.SCENARIOS ? { [__ENV.SCENARIOS]: scenariosAndStages.scenarios[__ENV.SCENARIOS] } : undefined,
  stages: scenariosAndStages.stages[__ENV.STAGES],
};

export default () => {
  db
    .collection('my_collection_here')
    .orderBy('timestamp')
    .get()
    .then(console.log);
  sleep(10);
  behavior.myBehavior('application load test one call', conf.multiply);
};

What are we doing wrong?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Ale TheFe
  • 1,540
  • 15
  • 43
  • k6 is for testing, right? Are you doing this with the [emulator](https://firebase.google.com/docs/firestore/quickstart#optional_prototype_and_test_with) or are you testing directly against your Firestore server? – fabc Dec 17 '21 at 08:09
  • Directly against Firestore server – Ale TheFe Dec 17 '21 at 08:37
  • 1
    Hmmm. Ok, well, I'd recommend using the emulator for most testing, since, at the very least, it can save you a couple of bucks (more likely cents, unless you commit a big mistake) to test against local emulation rather than your real server. That said... I'm kinda curious about [this line](https://k6.io/docs/using-k6/modules/#bundling-node-modules), the limited compability bit. I'm not sure if firestore is dependent on NodeJS itself... but I've never used the package outside of node, so I'll have to take another look at that, maybe ask a few colleagues. – fabc Dec 20 '21 at 14:23
  • Ok, yeah, [Firestore requires Node.js](https://github.com/firebase/firebase-js-sdk#nodejs), so due to the requirements of both k6 and Firestore they're not compatible. I will be posting this as an answer. – fabc Dec 27 '21 at 12:29

1 Answers1

0

After some light research I've come to realize that the Firestore JS SDK requires Node.js in order to function, making it incompatible with k6 according to k6's documentation.

I would recommend the Firebase emulator for unit testing. If one would prefer to mock certain functions for testing purposes, I would recommend using Jest instead, as shown here

fabc
  • 182
  • 10