Files
cypress/scripts/binary/get-config.js
Gleb Bahmutov 5015cbbe87 Wrap konfig load from scripts tests to avoid changing CWD (#4067)
* chore: add utility method to get konfig from scripts tests

Local scripts specs should be be caught by the changing current
directory when loading `konfig.coffee` (which loads `cwd.coffee`,
which changes the cwd to `packages/server`). This was throwing
snapshot tests into saving into a wrong folder until I have noticed
this and fixed in
[v8.0.3](https://github.com/bahmutov/snap-shot-core/releases/tag/v8.0.3)

* linting

* add more comments
2019-04-29 17:14:38 -04:00

23 lines
634 B
JavaScript

/**
* Safer konfig load for test code. The original konfig changes the
* current working directory, thus the tests might be affected
* unexpectedly. This function loads the konfig, but then
* restores the current working directory.
*
* The tests should use this function to get `konfig` function like
*
* @example
* const konfig = require('../binary/get-config')()
*/
const getConfig = () => {
const cwd = process.cwd()
const konfig = require('../../packages/server/lib/konfig')
// restore previous cwd in case it was changed by loading "konfig"
process.chdir(cwd)
return konfig
}
module.exports = getConfig