Skip to content

Commit

Permalink
Use import-all macro instead of explicit imports (jest-community#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
tejasbubane authored and mattphillips committed Jul 30, 2018
1 parent 5ffe04c commit a45463f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 95 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jest": "^21.2.0",
"husky": "^0.14.3",
"import-all.macro": "^2.0.3",
"jest": "^23.0.1",
"jest-each": "^0.5.0",
"lint-staged": "^6.0.0",
Expand Down Expand Up @@ -97,7 +98,8 @@
"transform-object-rest-spread",
"transform-async-to-generator",
"babel-jest-assertions",
"gwt"
"gwt",
"macros"
]
}
}
98 changes: 4 additions & 94 deletions src/matchers/index.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,5 @@
import toBeEven from './toBeEven';
import toBeTrue from './toBeTrue';
import toSatisfy from './toSatisfy';
import toBeFalse from './toBeFalse';
import toContainValue from './toContainValue';
import toContainValues from './toContainValues';
import toBeArray from './toBeArray';
import toBeArrayOfSize from './toBeArrayOfSize';
import toEqualCaseInsensitive from './toEqualCaseInsensitive';
import toStartWith from './toStartWith';
import toBeNegative from './toBeNegative';
import toBeOneOf from './toBeOneOf';
import toContainKey from './toContainKey';
import toBeString from './toBeString';
import toBeExtensible from './toBeExtensible';
import toBeWithin from './toBeWithin';
import toIncludeMultiple from './toIncludeMultiple';
import toEndWith from './toEndWith';
import toBeFrozen from './toBeFrozen';
import toBeObject from './toBeObject';
import toContainAllKeys from './toContainAllKeys';
import toContainAnyKeys from './toContainAnyKeys';
import toContainKeys from './toContainKeys';
import toBeFinite from './toBeFinite';
import toIncludeAnyMembers from './toIncludeAnyMembers';
import toIncludeAllMembers from './toIncludeAllMembers';
import toBeNaN from './toBeNaN';
import toBePositive from './toBePositive';
import toInclude from './toInclude';
import toBeBoolean from './toBeBoolean';
import toBeFunction from './toBeFunction';
import toBeNumber from './toBeNumber';
import toBeOdd from './toBeOdd';
import toContainAllValues from './toContainAllValues';
import toContainEntry from './toContainEntry';
import toContainAllEntries from './toContainAllEntries';
import toContainEntries from './toContainEntries';
import toContainAnyEntries from './toContainAnyEntries';
import toContainAnyValues from './toContainAnyValues';
import toBeNil from './toBeNil';
import toSatisfyAll from './toSatisfyAll';
import toBeEmpty from './toBeEmpty';
import toBeSealed from './toBeSealed';
import toIncludeRepeated from './toIncludeRepeated';
import toHaveBeenCalledBefore from './toHaveBeenCalledBefore';
import toBeDate from './toBeDate';
import importAll from 'import-all.macro';

export default [
toBeEven,
toBeTrue,
toBeFalse,
toContainValue,
toContainValues,
toBeArray,
toBeArrayOfSize,
toEqualCaseInsensitive,
toStartWith,
toBeNegative,
toBeOneOf,
toContainKey,
toBeExtensible,
toBeString,
toBeWithin,
toIncludeMultiple,
toEndWith,
toBeFrozen,
toBeObject,
toContainAllKeys,
toContainAnyKeys,
toContainKeys,
toBeFinite,
toIncludeAnyMembers,
toIncludeAllMembers,
toBeNaN,
toBePositive,
toInclude,
toBeBoolean,
toBeFunction,
toBeNumber,
toBeOdd,
toContainAllValues,
toContainEntry,
toContainAllEntries,
toContainEntries,
toContainAnyEntries,
toContainAnyValues,
toBeNil,
toSatisfyAll,
toBeEmpty,
toBeSealed,
toSatisfy,
toIncludeRepeated,
toHaveBeenCalledBefore,
toBeDate
].reduce((acc, matcher) => ({ ...acc, ...matcher }), {});
const imports = importAll.sync('./*/index.js');

export default Object.values(imports).reduce((acc, matcher) => ({ ...acc, ...matcher.default }), {});
18 changes: 18 additions & 0 deletions src/matchers/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import matchers from './index';

expect.extend(matchers);

// This does not test all matchers, just couple random ones to check
// if imports work correctly.

describe('positive matcher', () => {
test('.toBeEven', () => {
expect(2).toBeEven();
});
});

describe('negative matcher', () => {
test('.not.toBeWithin', () => {
expect(1).not.toBeWithin(10, 20);
});
});
33 changes: 33 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ babel-plugin-jest-hoist@^23.0.1:
version "23.0.1"
resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-23.0.1.tgz#eaa11c964563aea9c21becef2bdf7853f7f3c148"

babel-plugin-macros@^2.0.0:
version "2.2.2"
resolved "https://registry.yarnpkg.com/babel-plugin-macros/-/babel-plugin-macros-2.2.2.tgz#049c93f4b934453688a6ec38bba529c55bf0fa1f"
dependencies:
cosmiconfig "^4.0.0"

babel-plugin-syntax-async-functions@^6.8.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95"
Expand Down Expand Up @@ -951,6 +957,15 @@ cosmiconfig@^3.1.0:
parse-json "^3.0.0"
require-from-string "^2.0.1"

cosmiconfig@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-4.0.0.tgz#760391549580bbd2df1e562bc177b13c290972dc"
dependencies:
is-directory "^0.3.1"
js-yaml "^3.9.0"
parse-json "^4.0.0"
require-from-string "^2.0.1"

cross-spawn@^5.0.1, cross-spawn@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
Expand Down Expand Up @@ -1837,6 +1852,13 @@ ignore@^3.3.3:
version "3.3.5"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.5.tgz#c4e715455f6073a8d7e5dae72d2fc9d71663dba6"

import-all.macro@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/import-all.macro/-/import-all.macro-2.0.3.tgz#3e5de28920eb7237badb85acf15eb71c8d5b04f6"
dependencies:
babel-plugin-macros "^2.0.0"
glob "^7.1.2"

import-local@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/import-local/-/import-local-1.0.0.tgz#5e4ffdc03f4fe6c009c6729beb29631c2f8227bc"
Expand Down Expand Up @@ -2616,6 +2638,10 @@ jsesc@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-1.3.0.tgz#46c3fec8c1892b12b0833db9bc7622176dbab34b"

json-parse-better-errors@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"

json-schema-traverse@^0.3.0:
version "0.3.1"
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz#349a6d44c53a51de89b40805c5d5e59b417d3340"
Expand Down Expand Up @@ -3265,6 +3291,13 @@ parse-json@^3.0.0:
dependencies:
error-ex "^1.3.1"

parse-json@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-4.0.0.tgz#be35f5425be1f7f6c747184f98a788cb99477ee0"
dependencies:
error-ex "^1.3.1"
json-parse-better-errors "^1.0.1"

[email protected]:
version "4.0.0"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-4.0.0.tgz#6d78656e3da8d78b4ec0b906f7c08ef1dfe3f608"
Expand Down

0 comments on commit a45463f

Please sign in to comment.