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

spring-cloud-contract-stub-runner

v0.1.0

Published

A helper to run Spring Cloud Contracts as a part of test suite run

Downloads

7

Readme

Spring Cloud Contracts for Javascript

Spring Cloud Contracts is a library to automate contract testing and enable consumer driven contracts. SCC provides very nice integration with Spring Boot and allows to start and stop stubs as a part of test suite using @AutoConfigureStubRunner annotation. While being useful for testing service-to-service communication, it does not help when testing the most common client for pretty much any backend API - frontend Javascript apps. One possible option is to use Stub Runner Fat Jar and run stubs from command line before running tests.

Automating stub runner for a frontend app

This library designed to help and automate running stubs for frontend apps and provide functionality similar to @AutoConfigureStubRunner annotation.

React and Jest

React apps widely use Jest testing framework with JSDOM environment. To run stubs as a part of Jest test suite configure it via beforeAll setup method:

const SECONDS = 1000;
beforeAll(async () => {
    stubRunnerInstance = await runStubs(`com.example:cakefactor:+:${port}`);
}, 60 * SECONDS);

runStubs method will do few things for you:

  1. Check if there is a stub-runner.jar in the temp folder already
  2. Download it if necessary (this is quite slow as the JAR file is about ~60Mb)
  3. Run the stubs passing specified stub ids

To gracefully shutdown stub-runner use afterAll:

afterAll(() => {
    stubRunnerInstance.kill();
});

Note that beforeAll uses extended timeout of 60 seconds, this is to make sure test will not timeout on the first run, when downloading JAR file etc. Also based on the performance of your system you might want to adjust it to make sure there is enough time to run Spring Boot app, unpack stub and launch Wiremock.

Also it is quite important to use runStubs as few time as possible, ideally once per the whole test suite. It might be a good idea to extract all integration tests into a dedicated integration tests describe block, run all required stubs once, run the tests, stop the stubs.

Configuring fetch

By default, create-react-app uses combination of JSDOM and whatwg-fetch which automatically reject with TypeError: Network request failed. So to send a real network request to a stub-runner fetch need to be replaced with something that can actually make a network request, isomorphic-fetch should do just fine. Hence full setup for Jest + JSDOM would look like this:

beforeAll(async () => {
    global.fetch = require('isomorphic-fetch');
    stubRunnerInstance = await runStubs(`com.example:cakefactory:+:${port}`);
}, 60 * SECONDS);

Displaying stub-runner output

By default, all output to stdout is hidden to avoid noise in the test output. However if you want to enable it for debug purpose pass options to runStubs function:

stubRunnerInstance = await runStubs(`com.example:cakefactory:+:${port}`, { showOutput: true });

Options

The second argument of runStubs is options object, accepting the following properties:

  • pathToStubRunnerJar - path to Stub Runner Fat Jar, default = {os temp folder}/stub-runner.jar
  • stubRunnerJarDownloadUrl - the url to download Stub Runner Fat Jar if not found, default = maven download URL
  • showOutput - show / hide stdout output from stub-runner, default = false