-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
karma-webpack does not support DefinePlugin constants #299
Comments
Hi, i also facing the issue that webpack constants are not using on karma test. new webpack.ProvidePlugin({ Error on test some one has solved this issue? |
I'm encountering the exact same problem. Any intentions to fix this? |
Any update on this? |
A temporary solution that worked for me is to use the app.component.ts declare const BUILD: string;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
// Build number to help us identify the deployed version
build: string;
ngOnInit() {
this.build = BUILD;
}
... app.component.spec.ts describe('AppComponent', () => {
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
beforeEach(() => {
...
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
// Mock global constant defined using webpack's DefinePlugin
window['BUILD'] = '2020.01.01.ffffffff';
});
... |
Not sure if this helps but i was able to make a globally defined var /custom-typings.d.ts accessible to (i-e get updated by) /tsconfig.json
|
As karma is now deprecated and coming up on EOL, we are no longer planning on any significant enhancements to this project and are instead going to focus on security updates, stability, and a migration path forward as karma's lifecycle comes to an end. Thank you for supporting and using this project! |
I'm submitting a bug report
Webpack version:
3.5.2
Webpack Karma version:
2.0.9
Karma version:
2.0.0
Please tell us about your environment:
OSX 10.13.3
Browser:
Electron 1.7.5 (Chromium 58.0.3029.110)
Current behavior:
Global constants defined using webpack.DefinePlugin are undefined during the test.
I've tried to define the constants straight in the karma.conf.js file (in case it would override the webpackConfig variable, but to no avail.
I've looked up on SO for potential answers, but nothing came up.
I've updated all the karma, webpack and al. deps to their latest.
I've cloned your repository and all tests run fine.
Bug is also present with the following versions:
Expected/desired behavior:
Global constant defined using webpack.DefinePlugin are defined during the test :P
See the following gist. The package.json is only the dependencies.
If you want I can do a public fork of my private repository from the current commit (essentially SimulatedGREG/electron-vue boilerplate with a few minor changes to accommodate my dev stack). From there on, all you'd need to do is create three files and run
yarn && yarn run unit
to reproduce.The text was updated successfully, but these errors were encountered: