@epic-web/workshop-utils 4.17.1 → 4.18.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.
@@ -1,5 +1,12 @@
1
- /// <reference types="chai" resolution-mode="require"/>
2
- export declare const expect: Chai.ExpectStatic;
1
+ import * as dtl from '@testing-library/dom';
2
+ import * as matchers from '@testing-library/jest-dom/matchers';
3
+ import { type ExpectStatic } from '@vitest/expect';
4
+ declare module '@vitest/expect' {
5
+ interface JestAssertion<T = any> extends matchers.TestingLibraryMatchers<ReturnType<typeof expect.stringContaining>, T> {
6
+ }
7
+ }
8
+ export declare const expect: ExpectStatic;
9
+ export { dtl };
3
10
  export declare function testStep<ReturnValue>(title: string | ((result: {
4
11
  type: 'fail';
5
12
  error: Error;
@@ -1 +1 @@
1
- {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/test.ts"],"names":[],"mappings":";AAWA,eAAO,MAAQ,MAAM,mBAAS,CAAA;AAW9B,wBAAsB,QAAQ,CAAC,WAAW,EACzC,KAAK,EACF,MAAM,GACN,CAAC,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,KAAK,MAAM,CAAC,EAC1E,GAAG,EAAE,CAAC,MAAM,WAAW,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,GACrD,OAAO,CAAC,WAAW,CAAC,CA+BtB"}
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAA;AAC3C,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAA;AAC9D,OAAO,EAIN,KAAK,YAAY,EACjB,MAAM,gBAAgB,CAAA;AAiBvB,OAAO,QAAQ,gBAAgB,CAAC;IAC/B,UAAU,aAAa,CAAC,CAAC,GAAG,GAAG,CAC9B,SAAQ,QAAQ,CAAC,sBAAsB,CACtC,UAAU,CAAC,OAAO,MAAM,CAAC,gBAAgB,CAAC,EAC1C,CAAC,CACD;KAAG;CACL;AAOD,eAAO,MAAM,MAAM,cAA8B,CAAA;AACjD,OAAO,EAAE,GAAG,EAAE,CAAA;AAWd,wBAAsB,QAAQ,CAAC,WAAW,EACzC,KAAK,EACF,MAAM,GACN,CAAC,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,KAAK,MAAM,CAAC,EAC1E,GAAG,EAAE,CAAC,MAAM,WAAW,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,GACrD,OAAO,CAAC,WAAW,CAAC,CAmCtB"}
package/dist/esm/test.js CHANGED
@@ -1,12 +1,22 @@
1
- import { configure } from '@testing-library/dom';
1
+ import * as dtl from '@testing-library/dom';
2
+ import * as matchers from '@testing-library/jest-dom/matchers';
3
+ import { JestAsymmetricMatchers, JestChaiExpect, JestExtend, } from '@vitest/expect';
2
4
  import * as chai from 'chai';
3
5
  import chaiDOM from 'chai-dom';
6
+ // allows using expect.extend instead of chai.use to extend plugins
7
+ chai.use(JestExtend);
8
+ // adds all jest matchers to expect
9
+ chai.use(JestChaiExpect);
10
+ // adds asymmetric matchers like stringContaining, objectContaining
11
+ chai.use(JestAsymmetricMatchers);
4
12
  chai.use(chaiDOM);
13
+ chai.expect.extend(chai.expect, matchers);
5
14
  // in the browser logging out the element is not necessary
6
- configure({
15
+ dtl.configure({
7
16
  getElementError: (message) => new Error(message ?? 'Unknown error'),
8
17
  });
9
- export const { expect } = chai;
18
+ export const expect = chai.expect;
19
+ export { dtl };
10
20
  function isError(maybeError) {
11
21
  return (maybeError &&
12
22
  typeof maybeError === 'object' &&
@@ -14,7 +24,6 @@ function isError(maybeError) {
14
24
  typeof maybeError.message === 'string');
15
25
  }
16
26
  export async function testStep(title, get) {
17
- let caughtError;
18
27
  try {
19
28
  const result = await get();
20
29
  const titleString = typeof title === 'function' ? title({ type: 'pass' }) : title;
@@ -31,14 +40,17 @@ export async function testStep(title, get) {
31
40
  }
32
41
  return result;
33
42
  }
34
- catch (e) {
35
- caughtError = e;
43
+ catch (caughtError) {
44
+ const error = isError(caughtError)
45
+ ? caughtError
46
+ : new Error(typeof caughtError === 'string' ? caughtError : 'Unknown error', { cause: caughtError });
47
+ const titleString = typeof title === 'function' ? title({ type: 'fail', error }) : title;
48
+ if (window.parent === window) {
49
+ console.error(`❌ ${titleString}`);
50
+ console.error(error.message);
51
+ }
52
+ error.message = `${titleString}${error.message ? `\n\n${error.message}` : ''}`;
53
+ throw error;
36
54
  }
37
- const error = isError(caughtError)
38
- ? caughtError
39
- : new Error(typeof caughtError === 'string' ? caughtError : 'Unknown error');
40
- const titleString = typeof title === 'function' ? title({ type: 'fail', error }) : title;
41
- error.message = `${titleString}${error.message ? `\n\n${error.message}` : ''}`;
42
- throw error;
43
55
  }
44
56
  //# sourceMappingURL=test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,OAAO,MAAM,UAAU,CAAA;AAE9B,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;AAEjB,0DAA0D;AAC1D,SAAS,CAAC;IACT,eAAe,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,OAAO,IAAI,eAAe,CAAC;CACnE,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;AAE9B,SAAS,OAAO,CAAC,UAAe;IAC/B,OAAO,CACN,UAAU;QACV,OAAO,UAAU,K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G,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;IAC9E,MAAM,KAAK,CAAA;AACZ,CAAC","sourcesContent":["import { configure } from '@testing-library/dom'\nimport * as chai from 'chai'\nimport chaiDOM from 'chai-dom'\n\nchai.use(chaiDOM)\n\n// in the browser logging out the element is not necessary\nconfigure({\n\tgetElementError: (message) => new Error(message ?? 'Unknown error'),\n})\n\nexport const { expect } = chai\n\nfunction isError(maybeError: any): maybeError is Error {\n\treturn (\n\t\tmaybeError &&\n\t\ttypeof maybeError === 'object' &&\n\t\t'message' in maybeError &&\n\t\ttypeof maybeError.message === 'string'\n\t)\n}\n\nexport async function testStep<ReturnValue>(\n\ttitle:\n\t\t| string\n\t\t| ((result: { type: 'fail'; error: Error } | { type: 'pass' }) => string),\n\tget: (() => ReturnValue) | (() => Promise<ReturnValue>),\n): Promise<ReturnValue> {\n\tlet caughtError\n\ttry {\n\t\tconst result = await get()\n\t\tconst titleString =\n\t\t\ttypeof title === 'function' ? title({ type: 'pass' }) : title\n\t\tif (window.parent === window) {\n\t\t\tconsole.log(`✅ ${titleString}`)\n\t\t} else {\n\t\t\twindow.parent.postMessage(\n\t\t\t\t{\n\t\t\t\t\ttype: 'epicshop:test-step-update',\n\t\t\t\t\tstatus: 'pass',\n\t\t\t\t\ttitle: titleString,\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t},\n\t\t\t\t'*',\n\t\t\t)\n\t\t}\n\t\treturn result\n\t} catch (e: unknown) {\n\t\tcaughtError = e\n\t}\n\n\tconst error = isError(caughtError)\n\t\t? caughtError\n\t\t: new Error(typeof caughtError === 'string' ? caughtError : 'Unknown error')\n\tconst titleString =\n\t\ttypeof title === 'function' ? title({ type: 'fail', error }) : title\n\terror.message = `${titleString}${error.message ? `\\n\\n${error.message}` : ''}`\n\tthrow error\n}\n"]}
1
+ {"version":3,"file":"test.js","s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K,CAAA;IACZ,CAAC;AACF,CAAC","sourcesContent":["import * as dtl from '@testing-library/dom'\nimport * as matchers from '@testing-library/jest-dom/matchers'\nimport {\n\tJestAsymmetricMatchers,\n\tJestChaiExpect,\n\tJestExtend,\n\ttype ExpectStatic,\n} from '@vitest/expect'\nimport * as chai from 'chai'\nimport chaiDOM from 'chai-dom'\n\n// allows using expect.extend instead of chai.use to extend plugins\nchai.use(JestExtend)\n// adds all jest matchers to expect\nchai.use(JestChaiExpect)\n// adds asymmetric matchers like stringContaining, objectContaining\nchai.use(JestAsymmetricMatchers)\n\nchai.use(chaiDOM)\n\n// @ts-expect-error weird typescript nonsense\n// I *think* vitest is using the extend API wrong or something 🤷‍♂️\n// this works though so...\n;(chai.expect as ExpectStatic).extend(chai.expect, matchers)\ndeclare module '@vitest/expect' {\n\tinterface JestAssertion<T = any>\n\t\textends matchers.TestingLibraryMatchers<\n\t\t\tReturnType<typeof expect.stringContaining>,\n\t\t\tT\n\t\t> {}\n}\n\n// in the browser logging out the element is not necessary\ndtl.configure({\n\tgetElementError: (message) => new Error(message ?? 'Unknown error'),\n})\n\nexport const expect = chai.expect as ExpectStatic\nexport { dtl }\n\nfunction isError(maybeError: any): maybeError is Error {\n\treturn (\n\t\tmaybeError &&\n\t\ttypeof maybeError === 'object' &&\n\t\t'message' in maybeError &&\n\t\ttypeof maybeError.message === 'string'\n\t)\n}\n\nexport async function testStep<ReturnValue>(\n\ttitle:\n\t\t| string\n\t\t| ((result: { type: 'fail'; error: Error } | { type: 'pass' }) => string),\n\tget: (() => ReturnValue) | (() => Promise<ReturnValue>),\n): Promise<ReturnValue> {\n\ttry {\n\t\tconst result = await get()\n\t\tconst titleString =\n\t\t\ttypeof title === 'function' ? title({ type: 'pass' }) : title\n\t\tif (window.parent === window) {\n\t\t\tconsole.log(`✅ ${titleString}`)\n\t\t} else {\n\t\t\twindow.parent.postMessage(\n\t\t\t\t{\n\t\t\t\t\ttype: 'epicshop:test-step-update',\n\t\t\t\t\tstatus: 'pass',\n\t\t\t\t\ttitle: titleString,\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t},\n\t\t\t\t'*',\n\t\t\t)\n\t\t}\n\t\treturn result\n\t} catch (caughtError: unknown) {\n\t\tconst error = isError(caughtError)\n\t\t\t? caughtError\n\t\t\t: new Error(\n\t\t\t\t\ttypeof caughtError === 'string' ? caughtError : 'Unknown error',\n\t\t\t\t\t{ cause: caughtError },\n\t\t\t\t)\n\t\tconst titleString =\n\t\t\ttypeof title === 'function' ? title({ type: 'fail', error }) : title\n\t\tif (window.parent === window) {\n\t\t\tconsole.error(`❌ ${titleString}`)\n\t\t\tconsole.error(error.message)\n\t\t}\n\t\terror.message = `${titleString}${error.message ? `\\n\\n${error.message}` : ''}`\n\t\tthrow error\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epic-web/workshop-utils",
3
- "version": "4.17.1",
3
+ "version": "4.18.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -128,9 +128,11 @@
128
128
  "@playwright/test": "^1.44.1",
129
129
  "@remix-run/node": "^2.9.2",
130
130
  "@testing-library/dom": "^10.1.0",
131
+ "@testing-library/jest-dom": "^6.4.8",
131
132
  "@total-typescript/ts-reset": "^0.5.1",
132
133
  "@types/chai": "^4.3.17",
133
134
  "@types/chai-dom": "^1.11.3",
135
+ "@vitest/expect": "^2.0.5",
134
136
  "chai": "^5.1.1",
135
137
  "chai-dom": "^1.12.0",
136
138
  "chalk": "^5.3.0",