I'm using TypeScript, Mocha (with mocha-typescript plugin) for testing and WebPack for build in my application.
Recently I decided to add DefinePlugin for WebPack to separate configs for prod and dev environments:
import { AppSettings as DevSettings } from './appSettings.dev'
import { AppSettings as ProdSettings } from './appSettings.prod'
declare var __ENVIRONMENT__: string;
let settings = __ENVIRONMENT__ === 'prod' ? ProdSettings : DevSettings
export let AppSettings = settings;
In snippet above there is a global variable __ENVIRONMENT__ , which helps to choose settings I want to use. This variable is defined in webpack.config.js as follows:
module.exports = function(env) {
var config = {
// ...
plugins: [
new ExtendedDefinePlugin({
__ENVIRONMENT__: env === 'prod' ? 'prod' : 'dev',
})
]
// ...
}
return config;
}
So I change tests execution in package.json to
"test": "webpack --env=dev && mocha --recursive"
If I call "test", mocha throw error (webpack builds files correctly):
ReferenceError: __ENVIRONMENT__ is not defined
Testing watcher also won't work:
"test-watch": "mocha-typescript-watch"
throwing error "Exited with 1".
Is it possible to bring them work together? Or shall I use another way for testing?
__ENVIRONMENT__with 'prod' or 'dev' in the build output - are you sure that substitution is working for the browser?