• Stars
    star
    101
  • Rank 326,229 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

easy-fix: run integration tests like unit tests

Easy-fix: record & replay test data for flexible integration testing

Opinions diverge on how to do integration testing. One camp says: "mock your input data to isolate the target code" but tests using mock data can lose fidelity with changing real-world systems. The other camp says: "let your integration tests run live. Side effects are no problem" but those tests can run slow (for network latency, etc) and might require you to be on a private network. Neither camp wins!

Why choose? This module helps integration tests capture and replay test data. This allows tests to run in "live" mode, interacting with remote systems/db, or in "replay" mode, isolated to using serialized mock data, with no side effects. This is integration testing zen.

NEW in v3

Several new features include

  • better serialization for whitespace
  • Error reinstantiation
  • mock file access log
  • a file cache for mock data
  • named mock files

Notes on the new options have been added below. See the changelog for more details.

NEW in v2

Easy-fix v2 now supports promises! See the changelog for details.

Installing

npm install easy-fix --save-dev

Usage & documentation

Easy-fix exposes only two methods: "wrapAsyncMethod" and "restore"

Let's start with an example. This test shows sinon stub replace with the easy-fix equivalent:

let wrapper;

// set up the stubs/mocks:
before(function () {

  // Perhaps you use stubs, something like this:
  //   sinon.stub(productFees, 'getFeesForUpcs', /* stub function here */ );

  // Let's replace that and use easy-fix:
  wrapper = easyFix.wrapAsyncMethod(productFees, 'getFeesForUpcs', {
    dir: 'test/captured-data', // directory for the captured test data
    prefix: 'product-fees', // filenames are prefixed with this string
  });
};

it('gets linked upcs', function (done) {
  var upcs = [
    '0007800015274',
    '0069766210858'
  ];

  productFees.getFeesForUpcs(upcs, function (err, fees) {
    expect(err).to.not.exist;
    expect(fees).to.exist;
    expect(_.keys(fees)).to.have.length.above(2);
    done();
  });
});

after(function () {
  wrapper.restore() // remove stubs
});

If you had no 'before' setup method, the test would hit the database.

If you used the sinon stub, you'd have to plumb in your own mock function. This is typically how people feed in the mock data.

Use easy-fix much like the sinon.stub - pass in an object, the name of a method, and an options hash. Easy-fix will then operate in one of three modes...

Test modes

Modes are specified by the TEST_MODE environment variable, and they can be overridden as the 'mode' in the options hash. The modes are:

  • "live": test runs live. Easy-fix simply falls back onto the target function.
  • "capture": test runs live, but the arguments and response are captured and written to disk.
  • "replay": test does not run live - the function is mocked by the captured data.

Options

  • dir: <string>: test data is written into this directory. This defaults to "test/data".
  • prefix: <string>: test data filenames are prefixed with this string. This defaults to the name of the target function.
  • mode: <replay | live | capture>: override the TEST_MODE environment variable. In the absence of the TEST_MODE and this option, the mode defaults to "replay".
  • callbackSwap: <function>: allow an alternate function to monkey-patch the target function callback. If the target function (under test) does not follow the nodejs convention of having a callback as it's last argument, you'll need to use this option to provide a custom function to swap the callbacks.
  • reinstantiateErrors: <boolean>: if the first argument to a callback is an Errror, or the first argument for a rejected Promise is an Error, easy-fix will attempt to reinstantiate this Error (when in replay mode). Default is true.
  • filepath: <string>: capture/replay a mock in the named file path (joined with the dir option). This avoids the filename being derived from a hash of the calling arguments to the target function.
  • sinon: <sinon module>: if your project uses sinon, you can pass in the module here, and the wrapped target function will be a sinon stub. This adds functionality to the easy-fix wrapped function object, but does not change the behavior of easy-fix. Allowing sinon as an option avoids taking it as a dependency.
  • log: <filename>: A file will be appended with lines describing the names of the mock files read and written.

Options - serialization

  • argumentSerializer: <function (argument_array)>: an alternate serialization of the target function arguments. The default is a cycle-safe JSON serializer. Easy-fix will match responses to a hash of the serialized call arguments. This is useful for deduplicating test data where you expect the call arguments will be different for each call but do not require a unique response (perhaps for a timestamp or uuid).
  • responseSerializer: <function (argument_array)>: use an alternate serialization of the target function callback arguments. This may be useful, for example, in removing details from a long response, if the test requires only some of the unaffected details. Note that this argument applies to the callback arguments for Promise resolution/rejection as well as an asynchronous function callback.
  • responseDeserializer: <function (string)>: use an alternate deserialization of the target function callback arguments. The default is JSON.parse. This is typically only useful if you specify a responseSerializer. This may be useful to reinstantiate a derived Object or Error type, if needed.
  • returnValueSerializer: <function (argument_array, callback)>: allow an alternate serialization to JSON.stringify on the target function return value. This may be useful, for example, in removing details from a long return value, if the test requires only some of the unaffected details. A callback is provided to allow the test to capture asynchronous information produced by the return value. This may help with capturing values produced by streams, for example.
  • returnValueDeserializer: <function (string, argument_array)>: use an alternate deserialization of the return value of the target function. The default is JSON.parse. This is typically only useful if you specify a returnValueSerializer. This may be useful to reinstantiate a derived Object or Error type, if needed. The second argument is the provided if any data was captured by the callback to the returnValueSerializer.

More Repositories

1

lacinia

GraphQL implementation in pure Clojure
Clojure
1,798
star
2

thorax

Strengthening your Backbone
JavaScript
1,324
star
3

react-ssr-optimization

React.js server-side rendering optimization with component memoization and templatization
JavaScript
821
star
4

electrode

Electrode - Application Platform on React/Node.js powering Walmart.com
446
star
5

little-loader

A lightweight, IE8+ JavaScript loader
JavaScript
371
star
6

json-to-simple-graphql-schema

Transforms JSON input into a GraphQL schema
JavaScript
279
star
7

eslint-config-defaults

A composable set of ESLint defaults
JavaScript
229
star
8

lumbar

Modular javascript build tool
JavaScript
226
star
9

datascope

Visualization of Clojure data structures using Graphviz
Clojure
206
star
10

lacinia-pedestal

Expose Lacinia GraphQL as Pedestal endpoints
Clojure
197
star
11

bigben

BigBen - a generic, multi-tenant, time-based event scheduler and cron scheduling framework
Kotlin
196
star
12

concord

Concord - workflow orchestration and continuous deployment management
Java
195
star
13

kubeman

The Hero that Kubernetes deserves
TypeScript
164
star
14

system-viz

Graphviz visualization of a component system
Clojure
159
star
15

react-native-orientation-listener

A react-native library for obtaining current device orientation
Java
151
star
16

thorax-seed

JavaScript
131
star
17

vizdeps

Visualize Leiningen dependencies using Graphviz
Clojure
130
star
18

mupd8

Muppet
Scala
126
star
19

active-status

Present status of mulitple 'jobs' in a command line tool, using terminal capability codes
Clojure
118
star
20

schematic

Combine configuration with building a Component system
Clojure
104
star
21

dyn-edn

Dynamic properties in EDN content
Clojure
94
star
22

fruit-loops

Server-side jQuery API renderer.
JavaScript
89
star
23

generator-thorax

Thorax yeoman generator
JavaScript
87
star
24

walmart-cla

Walmart Contributor License Agreement Information
85
star
25

react-native-cropping

Cropping components for react-native
JavaScript
68
star
26

curved-carousel

An infinitely scrolling carousel with configurable curvature
JavaScript
64
star
27

walmart-api

API wrapper for the public Walmart Labs API
JavaScript
62
star
28

gozer

Open source library to parse various X12 file formats for retail/supply chain
Java
60
star
29

cookie-cutter

An opinionated micro-services framework for TypeScript
TypeScript
57
star
30

mock-server

SPA application debug proxy server
JavaScript
56
star
31

test-reporting

Tiny library to assist with reporting some context when a test fails
Clojure
53
star
32

container-query

A responsive layout helper based on the width of the container
JavaScript
52
star
33

react-native-platform-visible

A very simple component visibility switch based on Platform
JavaScript
49
star
34

eslint-config-walmart

A set of default eslint configurations, Walmart Labs style.
JavaScript
48
star
35

clojure-game-geek

Example source code for the Lacinia tutorial
Clojure
47
star
36

babel-plugin-react-cssmoduleify

Babel plugin to transform traditional React element classNames to CSS Modules
JavaScript
45
star
37

generator-release

Yeoman generator for handling Bower/NPM releases.
JavaScript
45
star
38

costanza

Frontend error tracking toolkit: Own your own domain
JavaScript
35
star
39

zFAM

z/OS-based File Access Manager
Assembly
35
star
40

nightcall

Automated Enumeration Script for Pentesting
Python
34
star
41

cond-let

A useful merge of cond and let
Clojure
30
star
42

static

JavaScript
26
star
43

bolt

[DEPRECATED] an opinionated meta task runner for components.
JavaScript
24
star
44

shared-deps

Leiningen plugin to allow sub-modules to more easily share common dependencies
Clojure
24
star
45

ridicule

Mocking everything
JavaScript
22
star
46

linearroad

Walmart version of the Linear Road streaming benchmark.
Java
22
star
47

backbone-historytracker

Backbone plugin for navigation direction tracking
JavaScript
22
star
48

zECS

z/OS-based Enterprise Cache Service
COBOL
21
star
49

pulsar

Text-based dashboard for Elixir CLIs
Elixir
20
star
50

react-native-image-progressbar

An image based progress bar
JavaScript
20
star
51

layout

A simple responsive layout helper
CSS
17
star
52

zUID

z/OS-based Unique Identifier generator
Assembly
16
star
53

showcase-template

A starter template for a showcase of React components
CSS
16
star
54

grunt-release-component

Grunt release helper for bower components
JavaScript
15
star
55

anomaly-detection-walmart

Python
14
star
56

partnerapi_sdk_dotnet

Walmart Partner API SDK for .NET
C#
14
star
57

circus

External Webpack Component Plugin
JavaScript
13
star
58

concord-website

Documentation website source code for Concord
JavaScript
13
star
59

concord-plugins

Java
12
star
60

strati-functional

A lightweight collection of functional classes used to complement core Java.
Java
12
star
61

thorax-boilerplate

A boilerplate project for Thoroax
JavaScript
11
star
62

nocktor

nocktor - your nock doctor
JavaScript
11
star
63

getting-started

How to get started with the WalmartLabs API and tooling
9
star
64

LinearGenerator

Reworked data generator for LinearRoad streaming benchmark that no longer needs mitsim or any database.
Java
9
star
65

json-patchwork

JavaScript
9
star
66

object-diff

A Go library implementing object wise diff and patch.
Go
8
star
67

small-world-graph

Graphing as in Data
C++
8
star
68

chai-shallowly

A chai assertion plugin for enzyme.
JavaScript
8
star
69

typeahead.js-legacy

typeahead.js is a fast and fully-featured autocomplete library
JavaScript
8
star
70

child-pool

child_process pool implementation
JavaScript
7
star
71

thorax-todos

JavaScript
6
star
72

hula-hoop

Server-side rendering components for Thorax + Hapi stacks.
JavaScript
6
star
73

grafana

The tool for beautiful monitoring and metric analytics & dashboards for Graphite, InfluxDB & Prometheus & More
Go
6
star
74

apache-http-client

A Clojure ring compatible http interface for Apache HttpClient
Clojure
5
star
75

lumbar-loader

JavaScript
5
star
76

krabby

JavaScript
4
star
77

js-conceptualizer

JS Conceptualizer is a bit of client-side Javascript that parses out concepts, particularly proper nouns, from HTML on a web page.
JavaScript
4
star
78

babel-plugin-i18n-id-hashing

Namespace the ID of React-Intl keys
JavaScript
4
star
79

express-example

A crazy simple example of using the Walmart API with express
JavaScript
4
star
80

wml-coding-std

A module for keeping consistent JS coding standards at WML
JavaScript
3
star
81

nativedriver

native driver for UI automation
Objective-C
3
star
82

was

Go
3
star
83

thorax-rails

Ruby
3
star
84

hapi-example

A crazy simple example of using the Walmart API with hapi
JavaScript
3
star
85

lumbar-long-expires

Long expires cache buster plugin for Lumbar
JavaScript
3
star
86

component-scan

A component scanner for React
JavaScript
3
star
87

scanomatic-server

Scan-O-Matic Node Server
JavaScript
3
star
88

hadoop-openstack-swifta

hadoop-openstack-swifta
Java
3
star
89

SDJSBridge

Native/Hybrid Javascript Bridge
Objective-C
2
star
90

cordova-starter-kit

A starter kit for using Cordova and the Walmart API
JavaScript
2
star
91

priorityY

Priority Based Connected Components
Python
2
star
92

bolt-standard-flux

electrode bolt standard configs and tasks for flux architecture.
JavaScript
1
star
93

github-util

Github utility methods.
JavaScript
1
star
94

lumbar-tester

Unit testing plugin for Lumbar
JavaScript
1
star
95

apidocs

HTML
1
star
96

circus-stylus

Stylus linker for Circus components
JavaScript
1
star
97

SDUserActivity

An simplified interface for NSUserActivity for apps that want to participate in handoff.
Objective-C
1
star
98

walmartlabs.github.io

Helper to redirect to code.walmartlabs.com
HTML
1
star
99

BurpSuiteDynamicSessionTracker

BurpSuite extension for tracking and manipulating dynamic session cookies
Java
1
star
100

bolt-cli

[DEPRECATED] bolt command line interface.
JavaScript
1
star