@wordpress/jest-console 8.26.1-next.719a03cbe.0 → 8.27.1-next.46f643fa0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/declarations.d.js +2 -0
- package/build/declarations.d.js.map +1 -0
- package/build/index.js +3 -4
- package/build/index.js.map +1 -1
- package/build/matchers.js.map +1 -1
- package/build/supported-matchers.js.map +1 -1
- package/build/types.js +6 -0
- package/build/types.js.map +1 -0
- package/build-module/declarations.d.js +2 -0
- package/build-module/declarations.d.js.map +1 -0
- package/build-module/index.js +3 -5
- package/build-module/index.js.map +1 -1
- package/build-module/matchers.js.map +1 -1
- package/build-module/supported-matchers.js.map +1 -1
- package/build-module/types.js +2 -0
- package/build-module/types.js.map +1 -0
- package/build-types/index.d.ts +5 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/matchers.d.ts +2 -0
- package/build-types/matchers.d.ts.map +1 -0
- package/build-types/supported-matchers.d.ts +3 -0
- package/build-types/supported-matchers.d.ts.map +1 -0
- package/build-types/types.d.ts +26 -0
- package/build-types/types.d.ts.map +1 -0
- package/package.json +4 -4
- package/types/index.d.ts +0 -46
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/jest-console/src/declarations.d.ts"],"sourcesContent":["// Definitions originally written by Damien Sorel <https://github.com/mistic100> under MIT license.\n// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f0b72c12f6b561e4342dc8a1cf87432d2ad40ae7/types/wordpress__jest-console/index.d.ts\n\ndeclare namespace jest {\n\tinterface Matchers< R, T > {\n\t\t/**\n\t\t * Ensure that `console.error` function was called.\n\t\t */\n\t\ttoHaveErrored(): R;\n\n\t\t/**\n\t\t * Ensure that `console.error` function was called with specific arguments.\n\t\t */\n\t\ttoHaveErroredWith( ...args: unknown[] ): R;\n\n\t\t/**\n\t\t * Ensure that `console.info` function was called.\n\t\t */\n\t\ttoHaveInformed(): R;\n\n\t\t/**\n\t\t * Ensure that `console.info` function was called with specific arguments.\n\t\t */\n\t\ttoHaveInformedWith( ...args: unknown[] ): R;\n\n\t\t/**\n\t\t * Ensure that `console.log` function was called.\n\t\t */\n\t\ttoHaveLogged(): R;\n\n\t\t/**\n\t\t * Ensure that `console.log` function was called with specific arguments.\n\t\t */\n\t\ttoHaveLoggedWith( ...args: unknown[] ): R;\n\n\t\t/**\n\t\t * Ensure that `console.warn` function was called.\n\t\t */\n\t\ttoHaveWarned(): R;\n\n\t\t/**\n\t\t * Ensure that `console.warn` function was called with specific arguments.\n\t\t */\n\t\ttoHaveWarnedWith( ...args: unknown[] ): R;\n\t}\n}\n"],"mappings":"","ignoreList":[]}
|
package/build/index.js
CHANGED
|
@@ -10,11 +10,10 @@ var _supportedMatchers = _interopRequireDefault(require("./supported-matchers"))
|
|
|
10
10
|
/**
|
|
11
11
|
* Sets spy on the console object's method to make it possible to fail test when method called without assertion.
|
|
12
12
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @param {string} args."0" Name of console method.
|
|
15
|
-
* @param {string} args."1" Name of Jest matcher.
|
|
13
|
+
* @param args
|
|
16
14
|
*/
|
|
17
|
-
const setConsoleMethodSpy =
|
|
15
|
+
const setConsoleMethodSpy = args => {
|
|
16
|
+
const [methodName, matcherName] = args;
|
|
18
17
|
const spy = jest.spyOn(console, methodName).mockName(`console.${methodName}`);
|
|
19
18
|
|
|
20
19
|
/**
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require","_supportedMatchers","_interopRequireDefault","setConsoleMethodSpy","methodName","matcherName","spy","jest","spyOn","console","mockName","resetSpy","mockReset","assertionsNumber","assertExpectedCalls","mock","calls","length","expect","not","beforeAll","beforeEach","afterEach","Object","entries","supportedMatchers","forEach"],"sources":["@wordpress/jest-console/src/index.
|
|
1
|
+
{"version":3,"names":["require","_supportedMatchers","_interopRequireDefault","setConsoleMethodSpy","args","methodName","matcherName","spy","jest","spyOn","console","mockName","resetSpy","mockReset","assertionsNumber","assertExpectedCalls","mock","calls","length","expect","not","beforeAll","beforeEach","afterEach","Object","entries","supportedMatchers","forEach"],"sources":["@wordpress/jest-console/src/index.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport './matchers';\nimport supportedMatchers from './supported-matchers';\nimport type { ExtendedMock } from './types';\n\n/**\n * Sets spy on the console object's method to make it possible to fail test when method called without assertion.\n *\n * @param args\n */\nconst setConsoleMethodSpy = ( args: [ string, string ] ) => {\n\tconst [ methodName, matcherName ] = args;\n\tconst spy = jest\n\t\t.spyOn( console, methodName as 'error' | 'info' | 'log' | 'warn' )\n\t\t.mockName( `console.${ methodName }` ) as ExtendedMock;\n\n\t/**\n\t * Resets the spy to its initial state.\n\t */\n\tfunction resetSpy() {\n\t\tspy.mockReset();\n\t\tspy.assertionsNumber = 0;\n\t}\n\n\t/**\n\t * Verifies that the spy has only been called if expected.\n\t */\n\tfunction assertExpectedCalls() {\n\t\tif ( spy.assertionsNumber === 0 && spy.mock.calls.length > 0 ) {\n\t\t\texpect( console ).not[ matcherName ]();\n\t\t}\n\t}\n\n\tbeforeAll( resetSpy );\n\n\tbeforeEach( () => {\n\t\tassertExpectedCalls();\n\t\tresetSpy();\n\t} );\n\n\tafterEach( assertExpectedCalls );\n};\n\nObject.entries( supportedMatchers ).forEach( setConsoleMethodSpy );\n"],"mappings":";;;AAGAA,OAAA;AACA,IAAAC,kBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAJA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA,MAAMG,mBAAmB,GAAKC,IAAwB,IAAM;EAC3D,MAAM,CAAEC,UAAU,EAAEC,WAAW,CAAE,GAAGF,IAAI;EACxC,MAAMG,GAAG,GAAGC,IAAI,CACdC,KAAK,CAAEC,OAAO,EAAEL,UAAgD,CAAC,CACjEM,QAAQ,CAAE,WAAYN,UAAU,EAAI,CAAiB;;EAEvD;AACD;AACA;EACC,SAASO,QAAQA,CAAA,EAAG;IACnBL,GAAG,CAACM,SAAS,CAAC,CAAC;IACfN,GAAG,CAACO,gBAAgB,GAAG,CAAC;EACzB;;EAEA;AACD;AACA;EACC,SAASC,mBAAmBA,CAAA,EAAG;IAC9B,IAAKR,GAAG,CAACO,gBAAgB,KAAK,CAAC,IAAIP,GAAG,CAACS,IAAI,CAACC,KAAK,CAACC,MAAM,GAAG,CAAC,EAAG;MAC9DC,MAAM,CAAET,OAAQ,CAAC,CAACU,GAAG,CAAEd,WAAW,CAAE,CAAC,CAAC;IACvC;EACD;EAEAe,SAAS,CAAET,QAAS,CAAC;EAErBU,UAAU,CAAE,MAAM;IACjBP,mBAAmB,CAAC,CAAC;IACrBH,QAAQ,CAAC,CAAC;EACX,CAAE,CAAC;EAEHW,SAAS,CAAER,mBAAoB,CAAC;AACjC,CAAC;AAEDS,MAAM,CAACC,OAAO,CAAEC,0BAAkB,CAAC,CAACC,OAAO,CAAExB,mBAAoB,CAAC","ignoreList":[]}
|
package/build/matchers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_jestMatcherUtils","require","_supportedMatchers","_interopRequireDefault","createErrorMessage","spyInfo","spy","pass","calls","matcherName","methodName","expected","hint","message","map","printReceived","printExpected","matcherHint","getMockName","createSpyInfo","mock","JSON","stringify","includes","length","createToHaveBeenCalledMatcher","received","assertionsNumber","createToHaveBeenCalledWith","expect","extend","Object","entries","supportedMatchers","reduce","result","matcherNameWith"],"sources":["@wordpress/jest-console/src/matchers.
|
|
1
|
+
{"version":3,"names":["_jestMatcherUtils","require","_supportedMatchers","_interopRequireDefault","createErrorMessage","spyInfo","spy","pass","calls","matcherName","methodName","expected","hint","message","map","printReceived","printExpected","matcherHint","getMockName","createSpyInfo","mock","JSON","stringify","includes","length","createToHaveBeenCalledMatcher","received","assertionsNumber","createToHaveBeenCalledWith","expect","extend","Object","entries","supportedMatchers","reduce","result","matcherNameWith"],"sources":["@wordpress/jest-console/src/matchers.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';\n\n/**\n * Internal dependencies\n */\nimport supportedMatchers from './supported-matchers';\nimport type { Mock } from 'jest-mock';\nimport type {\n\tExtendedMock,\n\tMatcherFunction,\n\tMatcherResult,\n\tMatcherWithArgsFunction,\n} from './types';\n\ninterface SpyInfo {\n\tspy: Mock;\n\tpass: boolean;\n\tcalls: unknown[][];\n\tmatcherName: string;\n\tmethodName: string;\n\texpected?: unknown[];\n}\n\nconst createErrorMessage = ( spyInfo: SpyInfo ) => {\n\tconst { spy, pass, calls, matcherName, methodName, expected } = spyInfo;\n\tconst hint = pass ? `.not${ matcherName }` : matcherName;\n\tconst message = pass\n\t\t? `Expected mock function not to be called but it was called with:\\n${ calls.map(\n\t\t\t\tprintReceived\n\t\t ) }`\n\t\t: `Expected mock function to be called${\n\t\t\t\texpected ? ` with:\\n${ printExpected( expected ) }\\n` : '.'\n\t\t }\\nbut it was called with:\\n${ calls.map( printReceived ) }`;\n\n\treturn () =>\n\t\t`${ matcherHint( hint, spy.getMockName() ) }` +\n\t\t'\\n\\n' +\n\t\tmessage +\n\t\t'\\n\\n' +\n\t\t`console.${ methodName }() should not be used unless explicitly expected\\n` +\n\t\t'See https://www.npmjs.com/package/@wordpress/jest-console for details.';\n};\n\nconst createSpyInfo = (\n\tspy: Mock,\n\tmatcherName: string,\n\tmethodName: string,\n\texpected?: unknown[]\n) => {\n\tconst calls = spy.mock.calls;\n\n\tconst pass = expected\n\t\t? JSON.stringify( calls ).includes( JSON.stringify( expected ) )\n\t\t: calls.length > 0;\n\n\tconst message = createErrorMessage( {\n\t\tspy,\n\t\tpass,\n\t\tcalls,\n\t\tmatcherName,\n\t\tmethodName,\n\t\texpected,\n\t} );\n\n\treturn {\n\t\tpass,\n\t\tmessage,\n\t};\n};\n\nconst createToHaveBeenCalledMatcher =\n\t( matcherName: string, methodName: string ) =>\n\t( received: Record< string, Mock > ): MatcherResult => {\n\t\tconst spy = received[ methodName ] as ExtendedMock;\n\t\tconst spyInfo = createSpyInfo( spy, matcherName, methodName );\n\t\tspy.assertionsNumber += 1;\n\t\treturn spyInfo;\n\t};\n\nconst createToHaveBeenCalledWith = (\n\tmatcherName: string,\n\tmethodName: string\n) =>\n\tfunction (\n\t\treceived: Record< string, Mock >,\n\t\t...expected: unknown[]\n\t): MatcherResult {\n\t\tconst spy = received[ methodName ] as ExtendedMock;\n\t\tconst spyInfo = createSpyInfo( spy, matcherName, methodName, expected );\n\t\tspy.assertionsNumber += 1;\n\t\treturn spyInfo;\n\t};\n\ntype MatchersObject = Record<\n\tstring,\n\tMatcherFunction | MatcherWithArgsFunction\n>;\n\nexpect.extend(\n\tObject.entries( supportedMatchers ).reduce< MatchersObject >(\n\t\t( result, [ methodName, matcherName ] ) => {\n\t\t\tconst matcherNameWith = `${ matcherName }With`;\n\n\t\t\treturn {\n\t\t\t\t...result,\n\t\t\t\t[ matcherName ]: createToHaveBeenCalledMatcher(\n\t\t\t\t\t`.${ matcherName }`,\n\t\t\t\t\tmethodName\n\t\t\t\t),\n\t\t\t\t[ matcherNameWith ]: createToHaveBeenCalledWith(\n\t\t\t\t\t`.${ matcherNameWith }`,\n\t\t\t\t\tmethodName\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t{}\n\t)\n);\n"],"mappings":";;;AAGA,IAAAA,iBAAA,GAAAC,OAAA;AAKA,IAAAC,kBAAA,GAAAC,sBAAA,CAAAF,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAmBA,MAAMG,kBAAkB,GAAKC,OAAgB,IAAM;EAClD,MAAM;IAAEC,GAAG;IAAEC,IAAI;IAAEC,KAAK;IAAEC,WAAW;IAAEC,UAAU;IAAEC;EAAS,CAAC,GAAGN,OAAO;EACvE,MAAMO,IAAI,GAAGL,IAAI,GAAG,OAAQE,WAAW,EAAG,GAAGA,WAAW;EACxD,MAAMI,OAAO,GAAGN,IAAI,GACjB,oEAAqEC,KAAK,CAACM,GAAG,CAC9EC,+B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AAGf,QAAmB,EACN;EAChB,MAAML,GAAG,GAAGoB,QAAQ,CAAEhB,UAAU,CAAkB;EAClD,MAAML,OAAO,GAAGc,aAAa,CAAEb,GAAG,EAAEG,WAAW,EAAEC,UAAU,EAAEC,QAAS,CAAC;EACvEL,GAAG,CAACqB,gBAAgB,IAAI,CAAC;EACzB,OAAOtB,OAAO;AACf,CAAC;AAOFwB,MAAM,CAACC,MAAM,CACZC,MAAM,CAACC,OAAO,CAAEC,0BAAkB,CAAC,CAACC,MAAM,CACzC,CAAEC,MAAM,EAAE,CAAEzB,UAAU,EAAED,WAAW,CAAE,KAAM;EAC1C,MAAM2B,eAAe,GAAG,GAAI3B,WAAW,MAAO;EAE9C,OAAO;IACN,GAAG0B,MAAM;IACT,CAAE1B,WAAW,GAAIgB,6BAA6B,CAC7C,IAAKhB,WAAW,EAAG,EACnBC,UACD,CAAC;IACD,CAAE0B,eAAe,GAAIR,0BAA0B,CAC9C,IAAKQ,eAAe,EAAG,EACvB1B,UACD;EACD,CAAC;AACF,CAAC,EACD,CAAC,CACF,CACD,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["supportedMatchers","error","info","log","warn","_default","exports","default"],"sources":["@wordpress/jest-console/src/supported-matchers.
|
|
1
|
+
{"version":3,"names":["supportedMatchers","error","info","log","warn","_default","exports","default"],"sources":["@wordpress/jest-console/src/supported-matchers.ts"],"sourcesContent":["const supportedMatchers: Record< string, string > = {\n\terror: 'toHaveErrored',\n\tinfo: 'toHaveInformed',\n\tlog: 'toHaveLogged',\n\twarn: 'toHaveWarned',\n};\n\nexport default supportedMatchers;\n"],"mappings":";;;;;;AAAA,MAAMA,iBAA2C,GAAG;EACnDC,KAAK,EAAE,eAAe;EACtBC,IAAI,EAAE,gBAAgB;EACtBC,GAAG,EAAE,cAAc;EACnBC,IAAI,EAAE;AACP,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaP,iBAAiB","ignoreList":[]}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/jest-console/src/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { Mock } from 'jest-mock';\n\n/**\n * Interface for the extended Jest Mock that includes the assertionsNumber property\n */\nexport interface ExtendedMock extends Mock {\n\tassertionsNumber: number;\n}\n\n/**\n * Interface for the matcher result object\n */\nexport interface MatcherResult {\n\tpass: boolean;\n\tmessage: () => string;\n}\n\n/**\n * Interface for the matcher function\n */\nexport type MatcherFunction = (\n\treceived: Record< string, Mock >\n) => MatcherResult;\n\n/**\n * Interface for the matcher function with arguments\n */\nexport type MatcherWithArgsFunction = (\n\treceived: Record< string, Mock >,\n\t...expected: unknown[]\n) => MatcherResult;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/jest-console/src/declarations.d.ts"],"sourcesContent":["// Definitions originally written by Damien Sorel <https://github.com/mistic100> under MIT license.\n// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f0b72c12f6b561e4342dc8a1cf87432d2ad40ae7/types/wordpress__jest-console/index.d.ts\n\ndeclare namespace jest {\n\tinterface Matchers< R, T > {\n\t\t/**\n\t\t * Ensure that `console.error` function was called.\n\t\t */\n\t\ttoHaveErrored(): R;\n\n\t\t/**\n\t\t * Ensure that `console.error` function was called with specific arguments.\n\t\t */\n\t\ttoHaveErroredWith( ...args: unknown[] ): R;\n\n\t\t/**\n\t\t * Ensure that `console.info` function was called.\n\t\t */\n\t\ttoHaveInformed(): R;\n\n\t\t/**\n\t\t * Ensure that `console.info` function was called with specific arguments.\n\t\t */\n\t\ttoHaveInformedWith( ...args: unknown[] ): R;\n\n\t\t/**\n\t\t * Ensure that `console.log` function was called.\n\t\t */\n\t\ttoHaveLogged(): R;\n\n\t\t/**\n\t\t * Ensure that `console.log` function was called with specific arguments.\n\t\t */\n\t\ttoHaveLoggedWith( ...args: unknown[] ): R;\n\n\t\t/**\n\t\t * Ensure that `console.warn` function was called.\n\t\t */\n\t\ttoHaveWarned(): R;\n\n\t\t/**\n\t\t * Ensure that `console.warn` function was called with specific arguments.\n\t\t */\n\t\ttoHaveWarnedWith( ...args: unknown[] ): R;\n\t}\n}\n"],"mappings":"","ignoreList":[]}
|
package/build-module/index.js
CHANGED
|
@@ -3,15 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import './matchers';
|
|
5
5
|
import supportedMatchers from './supported-matchers';
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* Sets spy on the console object's method to make it possible to fail test when method called without assertion.
|
|
9
8
|
*
|
|
10
|
-
* @param
|
|
11
|
-
* @param {string} args."0" Name of console method.
|
|
12
|
-
* @param {string} args."1" Name of Jest matcher.
|
|
9
|
+
* @param args
|
|
13
10
|
*/
|
|
14
|
-
const setConsoleMethodSpy =
|
|
11
|
+
const setConsoleMethodSpy = args => {
|
|
12
|
+
const [methodName, matcherName] = args;
|
|
15
13
|
const spy = jest.spyOn(console, methodName).mockName(`console.${methodName}`);
|
|
16
14
|
|
|
17
15
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["supportedMatchers","setConsoleMethodSpy","methodName","matcherName","spy","jest","spyOn","console","mockName","resetSpy","mockReset","assertionsNumber","assertExpectedCalls","mock","calls","length","expect","not","beforeAll","beforeEach","afterEach","Object","entries","forEach"],"sources":["@wordpress/jest-console/src/index.
|
|
1
|
+
{"version":3,"names":["supportedMatchers","setConsoleMethodSpy","args","methodName","matcherName","spy","jest","spyOn","console","mockName","resetSpy","mockReset","assertionsNumber","assertExpectedCalls","mock","calls","length","expect","not","beforeAll","beforeEach","afterEach","Object","entries","forEach"],"sources":["@wordpress/jest-console/src/index.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport './matchers';\nimport supportedMatchers from './supported-matchers';\nimport type { ExtendedMock } from './types';\n\n/**\n * Sets spy on the console object's method to make it possible to fail test when method called without assertion.\n *\n * @param args\n */\nconst setConsoleMethodSpy = ( args: [ string, string ] ) => {\n\tconst [ methodName, matcherName ] = args;\n\tconst spy = jest\n\t\t.spyOn( console, methodName as 'error' | 'info' | 'log' | 'warn' )\n\t\t.mockName( `console.${ methodName }` ) as ExtendedMock;\n\n\t/**\n\t * Resets the spy to its initial state.\n\t */\n\tfunction resetSpy() {\n\t\tspy.mockReset();\n\t\tspy.assertionsNumber = 0;\n\t}\n\n\t/**\n\t * Verifies that the spy has only been called if expected.\n\t */\n\tfunction assertExpectedCalls() {\n\t\tif ( spy.assertionsNumber === 0 && spy.mock.calls.length > 0 ) {\n\t\t\texpect( console ).not[ matcherName ]();\n\t\t}\n\t}\n\n\tbeforeAll( resetSpy );\n\n\tbeforeEach( () => {\n\t\tassertExpectedCalls();\n\t\tresetSpy();\n\t} );\n\n\tafterEach( assertExpectedCalls );\n};\n\nObject.entries( supportedMatchers ).forEach( setConsoleMethodSpy );\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,YAAY;AACnB,OAAOA,iBAAiB,MAAM,sBAAsB;AAGpD;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,GAAKC,IAAwB,IAAM;EAC3D,MAAM,CAAEC,UAAU,EAAEC,WAAW,CAAE,GAAGF,IAAI;EACxC,MAAMG,GAAG,GAAGC,IAAI,CACdC,KAAK,CAAEC,OAAO,EAAEL,UAAgD,CAAC,CACjEM,QAAQ,CAAE,WAAYN,UAAU,EAAI,CAAiB;;EAEvD;AACD;AACA;EACC,SAASO,QAAQA,CAAA,EAAG;IACnBL,GAAG,CAACM,SAAS,CAAC,CAAC;IACfN,GAAG,CAACO,gBAAgB,GAAG,CAAC;EACzB;;EAEA;AACD;AACA;EACC,SAASC,mBAAmBA,CAAA,EAAG;IAC9B,IAAKR,GAAG,CAACO,gBAAgB,KAAK,CAAC,IAAIP,GAAG,CAACS,IAAI,CAACC,KAAK,CAACC,MAAM,GAAG,CAAC,EAAG;MAC9DC,MAAM,CAAET,OAAQ,CAAC,CAACU,GAAG,CAAEd,WAAW,CAAE,CAAC,CAAC;IACvC;EACD;EAEAe,SAAS,CAAET,QAAS,CAAC;EAErBU,UAAU,CAAE,MAAM;IACjBP,mBAAmB,CAAC,CAAC;IACrBH,QAAQ,CAAC,CAAC;EACX,CAAE,CAAC;EAEHW,SAAS,CAAER,mBAAoB,CAAC;AACjC,CAAC;AAEDS,MAAM,CAACC,OAAO,CAAEvB,iBAAkB,CAAC,CAACwB,OAAO,CAAEvB,mBAAoB,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["matcherHint","printExpected","printReceived","supportedMatchers","createErrorMessage","spyInfo","spy","pass","calls","matcherName","methodName","expected","hint","message","map","getMockName","createSpyInfo","mock","JSON","stringify","includes","length","createToHaveBeenCalledMatcher","received","assertionsNumber","createToHaveBeenCalledWith","expect","extend","Object","entries","reduce","result","matcherNameWith"],"sources":["@wordpress/jest-console/src/matchers.
|
|
1
|
+
{"version":3,"names":["matcherHint","printExpected","printReceived","supportedMatchers","createErrorMessage","spyInfo","spy","pass","calls","matcherName","methodName","expected","hint","message","map","getMockName","createSpyInfo","mock","JSON","stringify","includes","length","createToHaveBeenCalledMatcher","received","assertionsNumber","createToHaveBeenCalledWith","expect","extend","Object","entries","reduce","result","matcherNameWith"],"sources":["@wordpress/jest-console/src/matchers.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';\n\n/**\n * Internal dependencies\n */\nimport supportedMatchers from './supported-matchers';\nimport type { Mock } from 'jest-mock';\nimport type {\n\tExtendedMock,\n\tMatcherFunction,\n\tMatcherResult,\n\tMatcherWithArgsFunction,\n} from './types';\n\ninterface SpyInfo {\n\tspy: Mock;\n\tpass: boolean;\n\tcalls: unknown[][];\n\tmatcherName: string;\n\tmethodName: string;\n\texpected?: unknown[];\n}\n\nconst createErrorMessage = ( spyInfo: SpyInfo ) => {\n\tconst { spy, pass, calls, matcherName, methodName, expected } = spyInfo;\n\tconst hint = pass ? `.not${ matcherName }` : matcherName;\n\tconst message = pass\n\t\t? `Expected mock function not to be called but it was called with:\\n${ calls.map(\n\t\t\t\tprintReceived\n\t\t ) }`\n\t\t: `Expected mock function to be called${\n\t\t\t\texpected ? ` with:\\n${ printExpected( expected ) }\\n` : '.'\n\t\t }\\nbut it was called with:\\n${ calls.map( printReceived ) }`;\n\n\treturn () =>\n\t\t`${ matcherHint( hint, spy.getMockName() ) }` +\n\t\t'\\n\\n' +\n\t\tmessage +\n\t\t'\\n\\n' +\n\t\t`console.${ methodName }() should not be used unless explicitly expected\\n` +\n\t\t'See https://www.npmjs.com/package/@wordpress/jest-console for details.';\n};\n\nconst createSpyInfo = (\n\tspy: Mock,\n\tmatcherName: string,\n\tmethodName: string,\n\texpected?: unknown[]\n) => {\n\tconst calls = spy.mock.calls;\n\n\tconst pass = expected\n\t\t? JSON.stringify( calls ).includes( JSON.stringify( expected ) )\n\t\t: calls.length > 0;\n\n\tconst message = createErrorMessage( {\n\t\tspy,\n\t\tpass,\n\t\tcalls,\n\t\tmatcherName,\n\t\tmethodName,\n\t\texpected,\n\t} );\n\n\treturn {\n\t\tpass,\n\t\tmessage,\n\t};\n};\n\nconst createToHaveBeenCalledMatcher =\n\t( matcherName: string, methodName: string ) =>\n\t( received: Record< string, Mock > ): MatcherResult => {\n\t\tconst spy = received[ methodName ] as ExtendedMock;\n\t\tconst spyInfo = createSpyInfo( spy, matcherName, methodName );\n\t\tspy.assertionsNumber += 1;\n\t\treturn spyInfo;\n\t};\n\nconst createToHaveBeenCalledWith = (\n\tmatcherName: string,\n\tmethodName: string\n) =>\n\tfunction (\n\t\treceived: Record< string, Mock >,\n\t\t...expected: unknown[]\n\t): MatcherResult {\n\t\tconst spy = received[ methodName ] as ExtendedMock;\n\t\tconst spyInfo = createSpyInfo( spy, matcherName, methodName, expected );\n\t\tspy.assertionsNumber += 1;\n\t\treturn spyInfo;\n\t};\n\ntype MatchersObject = Record<\n\tstring,\n\tMatcherFunction | MatcherWithArgsFunction\n>;\n\nexpect.extend(\n\tObject.entries( supportedMatchers ).reduce< MatchersObject >(\n\t\t( result, [ methodName, matcherName ] ) => {\n\t\t\tconst matcherNameWith = `${ matcherName }With`;\n\n\t\t\treturn {\n\t\t\t\t...result,\n\t\t\t\t[ matcherName ]: createToHaveBeenCalledMatcher(\n\t\t\t\t\t`.${ matcherName }`,\n\t\t\t\t\tmethodName\n\t\t\t\t),\n\t\t\t\t[ matcherNameWith ]: createToHaveBeenCalledWith(\n\t\t\t\t\t`.${ matcherNameWith }`,\n\t\t\t\t\tmethodName\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t{}\n\t)\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,aAAa,EAAEC,aAAa,QAAQ,oBAAoB;;AAE9E;AACA;AACA;AACA,OAAOC,iBAAiB,MAAM,sBAAsB;AAkBpD,MAAMC,kBAAkB,GAAKC,OAAgB,IAAM;EAClD,MAAM;IAAEC,GAAG;IAAEC,IAAI;IAAEC,KAAK;IAAEC,WAAW;IAAEC,UAAU;IAAEC;EAAS,CAAC,GAAGN,OAAO;EACvE,MAAMO,IAAI,GAAGL,IAAI,GAAG,OAAQE,WAAW,EAAG,GAAGA,WAAW;EACxD,MAAMI,OAAO,GAAGN,IAAI,GACjB,oEAAqEC,KAAK,CAACM,GAAG,CAC9EZ,aACA,CAAC,EAAG,GACJ,sCACAS,QAAQ,GAAG,WAAYV,aAAa,CAAEU,QAAS,CAAC,IAAK,GAAG,GAAG,8BAC5BH,KAAK,CAACM,GAAG,CAAEZ,aAAc,CAAC,EAAG;EAE/D,OAAO,MACN,GAAIF,WAAW,CAAEY,IAAI,EAAEN,GAAG,CAACS,WAAW,CAAC,CAAE,CAAC,EAAG,GAC7C,MAAM,GACNF,OAAO,GACP,MAAM,GACN,WAAYH,UAAU,oDAAqD,GAC3E,wEAAwE;AAC1E,CA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B,UAAU,EAAED,WAAW,CAAE,KAAM;EAC1C,MAAMuB,eAAe,GAAG,GAAIvB,WAAW,MAAO;EAE9C,OAAO;IACN,GAAGsB,MAAM;IACT,CAAEtB,WAAW,GAAIa,6BAA6B,CAC7C,IAAKb,WAAW,EAAG,EACnBC,UACD,CAAC;IACD,CAAEsB,eAAe,GAAIP,0BAA0B,CAC9C,IAAKO,eAAe,EAAG,EACvBtB,UACD;EACD,CAAC;AACF,CAAC,EACD,CAAC,CACF,CACD,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["supportedMatchers","error","info","log","warn"],"sources":["@wordpress/jest-console/src/supported-matchers.
|
|
1
|
+
{"version":3,"names":["supportedMatchers","error","info","log","warn"],"sources":["@wordpress/jest-console/src/supported-matchers.ts"],"sourcesContent":["const supportedMatchers: Record< string, string > = {\n\terror: 'toHaveErrored',\n\tinfo: 'toHaveInformed',\n\tlog: 'toHaveLogged',\n\twarn: 'toHaveWarned',\n};\n\nexport default supportedMatchers;\n"],"mappings":"AAAA,MAAMA,iBAA2C,GAAG;EACnDC,KAAK,EAAE,eAAe;EACtBC,IAAI,EAAE,gBAAgB;EACtBC,GAAG,EAAE,cAAc;EACnBC,IAAI,EAAE;AACP,CAAC;AAED,eAAeJ,iBAAiB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/jest-console/src/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { Mock } from 'jest-mock';\n\n/**\n * Interface for the extended Jest Mock that includes the assertionsNumber property\n */\nexport interface ExtendedMock extends Mock {\n\tassertionsNumber: number;\n}\n\n/**\n * Interface for the matcher result object\n */\nexport interface MatcherResult {\n\tpass: boolean;\n\tmessage: () => string;\n}\n\n/**\n * Interface for the matcher function\n */\nexport type MatcherFunction = (\n\treceived: Record< string, Mock >\n) => MatcherResult;\n\n/**\n * Interface for the matcher function with arguments\n */\nexport type MatcherWithArgsFunction = (\n\treceived: Record< string, Mock >,\n\t...expected: unknown[]\n) => MatcherResult;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchers.d.ts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supported-matchers.d.ts","sourceRoot":"","sources":["../src/supported-matchers.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,iBAAiB,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAK9C,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Mock } from 'jest-mock';
|
|
5
|
+
/**
|
|
6
|
+
* Interface for the extended Jest Mock that includes the assertionsNumber property
|
|
7
|
+
*/
|
|
8
|
+
export interface ExtendedMock extends Mock {
|
|
9
|
+
assertionsNumber: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Interface for the matcher result object
|
|
13
|
+
*/
|
|
14
|
+
export interface MatcherResult {
|
|
15
|
+
pass: boolean;
|
|
16
|
+
message: () => string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Interface for the matcher function
|
|
20
|
+
*/
|
|
21
|
+
export type MatcherFunction = (received: Record<string, Mock>) => MatcherResult;
|
|
22
|
+
/**
|
|
23
|
+
* Interface for the matcher function with arguments
|
|
24
|
+
*/
|
|
25
|
+
export type MatcherWithArgsFunction = (received: Record<string, Mock>, ...expected: unknown[]) => MatcherResult;
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,IAAI;IACzC,gBAAgB,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAC7B,QAAQ,EAAE,MAAM,CAAE,MAAM,EAAE,IAAI,CAAE,KAC5B,aAAa,CAAC;AAEnB;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,CACrC,QAAQ,EAAE,MAAM,CAAE,MAAM,EAAE,IAAI,CAAE,EAChC,GAAG,QAAQ,EAAE,OAAO,EAAE,KAClB,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/jest-console",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.27.1-next.46f643fa0.0",
|
|
4
4
|
"description": "Custom Jest matchers for the Console object.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"files": [
|
|
28
28
|
"build",
|
|
29
29
|
"build-module",
|
|
30
|
-
"types"
|
|
30
|
+
"build-types"
|
|
31
31
|
],
|
|
32
32
|
"main": "build/index.js",
|
|
33
33
|
"module": "build-module/index.js",
|
|
34
|
-
"types": "types",
|
|
34
|
+
"types": "build-types",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/runtime": "7.25.7",
|
|
37
37
|
"jest-matcher-utils": "^29.6.2"
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "17e600e091675c5e3d809adfea23ac456bbeae19"
|
|
46
46
|
}
|
package/types/index.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// Definitions originally written by Damien Sorel <https://github.com/mistic100> under MIT license.
|
|
2
|
-
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f0b72c12f6b561e4342dc8a1cf87432d2ad40ae7/types/wordpress__jest-console/index.d.ts
|
|
3
|
-
|
|
4
|
-
declare namespace jest {
|
|
5
|
-
interface Matchers< R, T > {
|
|
6
|
-
/**
|
|
7
|
-
* Ensure that `console.error` function was called.
|
|
8
|
-
*/
|
|
9
|
-
toHaveErrored(): R;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Ensure that `console.error` function was called with specific arguments.
|
|
13
|
-
*/
|
|
14
|
-
toHaveErroredWith( ...args: any[] ): R;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Ensure that `console.info` function was called.
|
|
18
|
-
*/
|
|
19
|
-
toHaveInformed(): R;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Ensure that `console.info` function was called with specific arguments.
|
|
23
|
-
*/
|
|
24
|
-
toHaveInformedWith( ...args: any[] ): R;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Ensure that `console.log` function was called.
|
|
28
|
-
*/
|
|
29
|
-
toHaveLogged(): R;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Ensure that `console.log` function was called with specific arguments.
|
|
33
|
-
*/
|
|
34
|
-
toHaveLoggedWith( ...args: any[] ): R;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Ensure that `console.warn` function was called.
|
|
38
|
-
*/
|
|
39
|
-
toHaveWarned(): R;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Ensure that `console.warn` function was called with specific arguments.
|
|
43
|
-
*/
|
|
44
|
-
toHaveWarnedWith( ...args: any[] ): R;
|
|
45
|
-
}
|
|
46
|
-
}
|