![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Angular library which drastically improves execution time of your component's unit tests
Bullet is a library which enhances your unit testing experience with Angular TestBed
, greatly increasing execution speed of your tests.
But how does it do that?
Most of the time our angular unit tests for components are configured in the following way:
beforeEach(async(() => {
// a really simplified example of TestBed configuration
TestBed.configureTestingModule({
declarations: [ /*list of components goes here*/ ],
imports: [ /* list of providers goes here*/ ]
})
.compileComponents();
}));
This is the common approach of doing that and you will see exactly the same approach while reading Angular documentation or watching Angular courses.
However what it also means is that Angular will re-compile everything we used to configure our TestBed
for every test in a suite, thus increasing the overall test execution time.
With ng-bullet the previous code snippet will look like this:
import { configureTestSuite } from 'ng-bullet';
...
configureTestSuite(() => {
TestBed.configureTestingModule({
declarations: [ /*list of components goes here*/ ],
imports: [ /* list of providers goes here*/ ]
})
});
We basically just replaced your code snippet with TestBed configuration on configureTestSuite
fucntion call. No need to call compileComponents
explicitly. After this
ng-bullet will ensure for you that components were compiled only once, still providing all the isolation for your tests and creating new instances of components / services / etc for every test.
ng-bullet also provides 2 handful functions to spin up your component's instances.
createTestContext: <T>(component: Type<T>) => TestCtx<T>;
which creates TestCtx instance for the Angular Component which is not initialized yet (no ngOnInit called). Use case: you can override Component's providers before lifetime hooks were called.
And
createStableTestContext: <T>(component: Type<T>) => Promise<TestCtx<T>>;
which is exactly the same as function above, but this one waits till fixture becomes stable.
Both of them return TestCtx
instance which is a wrapper around ComponentFixture
, which simplifies your access to some most commonly used features of ComponentFixture
.
So don't hesitate and give a try ;)
The performance gain depends heavily on the number of tests in the suite and the number of components and modules you imported / declared. The more tests you have the bigger will be your benefit. With a really fat configurations it may come close to be N times faster, where N is the number of tests in the suite.
A small comparison from a real project.
This is what it takes to run ~1400 tests completely without using ng-bullet:
And this is how it looks like after most of the suites were updated with ng-bullet usage (there are some suites which are still run on a raw TestBed
):
So in this case 300 % speed increase gained.
npm install ng-bullet
or yarn add ng-bullet
FAQs
Angular library which drastically improves execution time of your component's unit tests
The npm package ng-bullet receives a total of 10,065 weekly downloads. As such, ng-bullet popularity was classified as popular.
We found that ng-bullet demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.