cd into either codelab-initial-state or codelab-final-state
Update npm dependencies & dev-dependencies to latest in the functions directory. cd out of functions when done.
run firebase emulators:start
run npm --prefix=functions test
What is the expected result?
> functions@ test .../emulators-codelab/codelab-initial-state/functions
> mocha
shopping carts
1) can be created by the cart owner
shopping carts
2) can be read, updated, and deleted by the cart owner
shopping cart items
3) can be read by the cart owner
4) can be added by the cart owner
adding an item to the cart recalculates the cart total.
- should sum the cost of their items
0 passing (550ms)
1 pending
4 failing
What happens instead of that?
> functions@ test .../emulators-codelab/codelab-initial-state/functions
> mocha
body {"error":{"code":400,"message":"Payload isn't valid for request.","status":"INVALID_ARGUMENT"}}
1) "before all" hook in "{root}"
0 passing (147ms)
1 failing
1) "before all" hook in "{root}":
Payload isn't valid for request.
npm ERR! Test failed. See above for more details.
Fix explained:
Depending on the version of dependencies (or dev-dependencies, more accurately) the rulesContent is passed as a buffer instead of a string in the before hook of test,js.
This led to the npm --prefix=functions test failing in the first before hook with the status: "INVALID_ARGUMENT". (The instruction is given in this codelab under "3. Run the emulators and tests" with no mention of this issue.)
To fix this, I have added "utf8" explicitly as a second parameter to fs.readFileSync() in both the initial and final states.
Browser: No browser involved Browser version: Operating system: Ubuntu Linux Operating system version: 18.04.4 LTS package.json dependencies:
What steps will reproduce the problem:
cd
into either codelab-initial-state or codelab-final-statecd
out of functions when done.firebase emulators:start
npm --prefix=functions test
What is the expected result?
What happens instead of that?
Fix explained: Depending on the version of dependencies (or dev-dependencies, more accurately) the
rulesContent
is passed as a buffer instead of a string in thebefore
hook of test,js.This led to the
npm --prefix=functions
test failing in the firstbefore
hook with the status: "INVALID_ARGUMENT". (The instruction is given in this codelab under "3. Run the emulators and tests" with no mention of this issue.)To fix this, I have added
"utf8"
explicitly as a second parameter tofs.readFileSync()
in both the initial and final states.The change does not affect the old code negatively.