Get Jasmine Configuration During Runtime
do extend my jasmine.json
file with some custom properties such as a server config for the server I want to send my requests to. As I also want to use this config in my tests, I need to read the jasmine.json
properties during runtime.
Of course I can require(path.join(process.cwd(), 'jasmine.json'))
. But this soultion would not work when specifying a different location of jasmine.json
when executing jasmine.
I assume there is at least one way to read the config during runtime, but it is definetly NOTjasmine.config
or jasmine.getConfig()
.
Any ideas how to retrieve the configuration?
Thanks
Answer
AFAIK it's not possible to access jasmine config through it's built-in API.
However there is still an option to achieve this through a workaround, as there are 3 possibilities to find the config:
const path = require('path');
const getJasmineConfig = () => {
// by default jasmine is using below path to find config file
let configPath = 'spec/support/jasmine.json';
const configArg = process.argv.find(arg => arg.indexOf('--config') > -1);
if (configArg) {
// if config path is specified by --config arg in cli
configPath = configArg.replace('--config=', '');
}
else if (process.env.JASMINE_CONFIG_PATH) {
// if config path is specified by environment variable
configPath = process.env.JASMINE_CONFIG_PATH;
}
return require(path.resolve(process.cwd(), configPath));
};
But yet again - it's not officially supported nor recommended by Jasmine.
Instead of using jasmine.json for this kind of things, you could create your own, project specific config file, i.e. project.config.js
and create a service that would serve you the config when needed.
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM