npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@azhang_cc/ng-bullet-forked

v1.0.0

Published

Forked from ng-bullet for Angular 12 update - Angular library which drastically improves execution time of your component's unit tests

Downloads

3

Readme

Forked ng-bullet for Anular 12 to remove warning message Deprecation warning from jasmine 3.7.0 for async before/it/after with done callback and retured promise

For original ng-bullet, see https://npmjs.com/package/ng-bullet.

ng-bullet

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 ;)

Performance benefits

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:

test results before 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):

test results after ng-bullet

So in this case 300 % speed increase gained.

Installation

npm install ng-bullet or yarn add ng-bullet