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

xor-testbed

v1.1.0

Published

Testing reactive angular components in a standalone environrnment has always been a problem. This library provides a neat component that can be placed in its own route inside the application and it provides a platform for setting up frontend tests with di

Downloads

10

Readme

Angular Testbed

Testing reactive angular components in a standalone environrnment has always been a problem. This library provides a neat component that can be placed in its own route inside the application and it provides a platform for setting up frontend tests with different data points for the same code.

Sandbox testing in your own source

xor-testbed provides simple components and patterns to create a sandbox based testing environment in your angular(v2+) app. It keeps the integration layer thin and separate and provides a dedicated view for managing all your sandboxes. The testbed is minimal and runs in your angular app where you give it a special route as shown below. You can make changes to the data model within the testbed and copy the configuration model which can be pasted in place where the test was written making incremental testing both easier and mutable.

Integration

Even though the initial setup may seem a bit extended here, progressive iterations are much easier. You should only require to create a main testbed class and a testing class with minor updates to the list and models wherever necessary.

Add angular material with animations enabled

This library depends on angular material so add it as described here

Special route for the testbed

Wherever you have configured your routes for your application (by default it is in app.routes.ts), you need to add a new route that serves to contain the full testbed

export const routes: Routes = [
    {path:'', redirectTo: 'testbed', pathMatch: 'full'},// in your case, this will be different
    // ... other routes
    {path: 'testbed', component: TestbedComponent}// <--this is what you need to add
];

TestbedComponent is a special container component that you will need to add. The sole responsibility of this component is to listwise host the SandboxTests and call on the this library's main TestSelectingPlatformComponent with those sandbox list as input. We can generate a simple TestbedComponent by issuing the command

ng g c testbed --inline-template --inline-style --skip-tests --project=your-app --flat=true

Specifying the project flag is necessary if you have multiple projects in the workspace and/or you need to be explicit.

This is the minimal setup needed to run the testbed with testbed code roughly being:


@Component({
  selector: 'app-testbed',
  standalone: true,
  imports: [TestSelectingPlatformComponent],
  template: `<xor-test-selecting-platform [tests]="tests"></xor-test-selecting-platform>`,
  styles: ``
})
export class TestbedComponent {
  tests:ISandboxTest[] = [
    {
      model: t1,
      component: MyComponent1TestComponent
    },
    {
      model: t2,
      component: MyComponent2TestComponent
    }
  ]
}

ISandboxTest holds all the information about a sandbox like testing component, case studies and of course name and description. The list is supplied to the test selecting platform which uses it to display the currently selected test.

Creating frontend tests

Each ISandboxTest holds a model and a component type

export interface ISandboxTest{
  model: TestbedModel;
  component: ComponentType<AbstractTestbed>;
}
  • A TestbedModel is a simple class holding information about a test and its case studies.
  • A ComponentType<AbstractTestbed> is the testing component that you will be using to test your main component. This class needs to extend AbstractTestbed which only needs to return the same model as the one used in the ISandboxTest class.

Example

Here is an example of ISandboxTest as a list

export class TestbedComponent {
  tests:ISandboxTest[] = [
    {
      model: t1,
      component: MyComponent1TestComponent
    },
    {
      model: t2,
      component: MyComponent2TestComponent
    }
  ]
}

Here is an example of a testing component MyComponent1TestComponent.

@Component({
  selector: 'app-my-component1',
  standalone: true,
  imports: [CommonModule],
  template: `
  <span
    [ngClass]="{
        'font-bold':bold,
        'italic':italic,
        'underline':underline,
        'line-through':strikethrough
    }"
>
    {{message}}
</span>

  `,
  styles: ``
})
export class MyComponent1Component { //<--Component to test
  @Input() bold = false;
  @Input() italic = false;
  @Input() strikethrough = false;
  @Input() underline = false;
  @Input() message = 'This is a message from my-component1';
}

@Component({
  selector: 'app-my-component1-test',
  standalone: true,
  imports: [MyComponent1Component],
  template: `
    <app-my-component1
      [bold]="data.bold"
      [italic]="data.italic"
      [strikethrough]="data.strikethrough"
      [underline]="data.underline"
      [message]="data.message"
    ></app-my-component1>
  `,
  styles: ``
})
export class MyComponent1TestComponent extends AbstractTestbed{ //<--Testing component
  override get model(): TestbedModel {
    return testbedModel;
  }
}

export const testbedModel:TestbedModel = new TestbedModel("Stylable text", "Text that can be styled through different ways procdedurally");

testbedModel.caseStudies = [
  {
    name:"Basic",
    description:"No styling",
    data: {
      bold: false,
      italic: false,
      strikethrough: false,
      underline: false,
      message: 'This text is stylable'
    }
  },
  {
    name: "Bold",
    description: "Only bold text",
    data: {
      bold: true,
      italic: false,
      strikethrough: false,
      underline: false,
      message: "This text is stylable"
    }
  },
  {
    name: "Italic",
    description: "Only italic text",
    data: {
      bold: false,
      italic: true,
      strikethrough: false,
      underline: false,
      message: "This text is stylable"
    }
  }
]

Licence

Licensed under MIT