Skip to content

Mock Config Updates #581

@blueyetisoftware-jason

Description

@blueyetisoftware-jason

The mocked environment config for firebase appears to only be mutable on initialization. I would like to be able to modify the config for various mocha tests and test different configurations of the code. Here is an example

const chai = require('chai')
const test = require('firebase-functions-test')()
const functions = require('firebase-functions')

describe('All Tests', () => {
    describe('Test1', () => {
        before(function () {
            const config = {
                site: {
                    url: 'https://site1.com'
                }
            }
            test.mockConfig(config)
        })

        it('Run Test', async () => {
            console.log(functions.config().site.url)
            // ...
        })

        after(() => {
            test.cleanup()
        })
    })

    describe('Test2', () => {
        before(function () {
            const config = {
                site: {
                    url: 'https://site2.com'
                }
            }
            test.mockConfig(config)
        })

        it('Run Test', async () => {
            console.log(functions.config().site.url)
        })

        after(() => {
            test.cleanup()
        })
    })
})

The config in 'Test 2' will match that of 'Test 1'. My hope was that test.cleanup() would reset the mocked state and allow it to be changed in further tests. Instead, you will see this output

  All Tests
    Test1
https://site1.com
      ✓ Run Test
    Test2
https://site1.com
      ✓ Run Test

  2 passing (12ms)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions