@bemedev/dev-utils 1.1.1 → 1.2.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/README.md +34 -0
- package/lib/_virtual/_rolldown/runtime.cjs +1 -1
- package/lib/build-tests/addTarball.cjs +5 -1
- package/lib/build-tests/addTarball.cjs.map +1 -1
- package/lib/build-tests/addTarball.d.ts +3 -0
- package/lib/build-tests/addTarball.js +5 -1
- package/lib/build-tests/addTarball.js.map +1 -1
- package/lib/build-tests/buildPackageJson.cjs +17 -9
- package/lib/build-tests/buildPackageJson.cjs.map +1 -1
- package/lib/build-tests/buildPackageJson.d.ts +5 -0
- package/lib/build-tests/buildPackageJson.js +17 -9
- package/lib/build-tests/buildPackageJson.js.map +1 -1
- package/lib/build-tests/cleanup.cjs +3 -0
- package/lib/build-tests/cleanup.cjs.map +1 -1
- package/lib/build-tests/cleanup.d.ts +3 -0
- package/lib/build-tests/cleanup.js +3 -0
- package/lib/build-tests/cleanup.js.map +1 -1
- package/lib/build-tests/cli/cli.cjs +6 -0
- package/lib/build-tests/cli/cli.cjs.map +1 -1
- package/lib/build-tests/cli/cli.d.ts +6 -0
- package/lib/build-tests/cli/cli.js +6 -0
- package/lib/build-tests/cli/cli.js.map +1 -1
- package/lib/build-tests/cli/index.cjs.map +1 -1
- package/lib/build-tests/cli/post.cjs +3 -0
- package/lib/build-tests/cli/post.cjs.map +1 -1
- package/lib/build-tests/cli/post.d.ts +3 -0
- package/lib/build-tests/cli/post.js +3 -0
- package/lib/build-tests/cli/post.js.map +1 -1
- package/lib/build-tests/cli/pre.cjs +3 -0
- package/lib/build-tests/cli/pre.cjs.map +1 -1
- package/lib/build-tests/cli/pre.d.ts +3 -0
- package/lib/build-tests/cli/pre.js +3 -0
- package/lib/build-tests/cli/pre.js.map +1 -1
- package/lib/build-tests/cli/test.cjs +3 -0
- package/lib/build-tests/cli/test.cjs.map +1 -1
- package/lib/build-tests/cli/test.d.ts +3 -0
- package/lib/build-tests/cli/test.js +3 -0
- package/lib/build-tests/cli/test.js.map +1 -1
- package/lib/build-tests/constants.cjs +42 -0
- package/lib/build-tests/constants.cjs.map +1 -1
- package/lib/build-tests/constants.d.ts +42 -0
- package/lib/build-tests/constants.js +42 -0
- package/lib/build-tests/constants.js.map +1 -1
- package/lib/build-tests/getRelativePath.cjs +7 -0
- package/lib/build-tests/getRelativePath.cjs.map +1 -1
- package/lib/build-tests/getRelativePath.d.ts +7 -0
- package/lib/build-tests/getRelativePath.js +7 -0
- package/lib/build-tests/getRelativePath.js.map +1 -1
- package/lib/build-tests/getTypescriptOutdir.cjs +5 -0
- package/lib/build-tests/getTypescriptOutdir.cjs.map +1 -1
- package/lib/build-tests/getTypescriptOutdir.d.ts +5 -0
- package/lib/build-tests/getTypescriptOutdir.js +5 -0
- package/lib/build-tests/getTypescriptOutdir.js.map +1 -1
- package/lib/build-tests/import.cjs +9 -0
- package/lib/build-tests/import.cjs.map +1 -1
- package/lib/build-tests/import.d.ts +9 -0
- package/lib/build-tests/import.js +9 -0
- package/lib/build-tests/import.js.map +1 -1
- package/lib/build-tests/imports/create.cjs +7 -0
- package/lib/build-tests/imports/create.cjs.map +1 -1
- package/lib/build-tests/imports/create.d.ts +13 -0
- package/lib/build-tests/imports/create.js +7 -0
- package/lib/build-tests/imports/create.js.map +1 -1
- package/lib/build-tests/imports/helper.cjs +9 -0
- package/lib/build-tests/imports/helper.cjs.map +1 -1
- package/lib/build-tests/imports/helper.d.ts +12 -0
- package/lib/build-tests/imports/helper.js +9 -0
- package/lib/build-tests/imports/helper.js.map +1 -1
- package/lib/build-tests/pack.cjs +7 -1
- package/lib/build-tests/pack.cjs.map +1 -1
- package/lib/build-tests/pack.d.ts +5 -0
- package/lib/build-tests/pack.js +7 -1
- package/lib/build-tests/pack.js.map +1 -1
- package/lib/plugins/index.cjs +3 -0
- package/lib/plugins/index.d.ts +1 -0
- package/lib/plugins/index.js +2 -0
- package/lib/plugins/suppressWarnings.cjs +37 -0
- package/lib/plugins/suppressWarnings.cjs.map +1 -0
- package/lib/plugins/suppressWarnings.d.ts +12 -0
- package/lib/plugins/suppressWarnings.js +36 -0
- package/lib/plugins/suppressWarnings.js.map +1 -0
- package/lib/rolldown-config/config.cjs +13 -5
- package/lib/rolldown-config/config.cjs.map +1 -1
- package/lib/rolldown-config/config.d.ts +7 -0
- package/lib/rolldown-config/config.js +13 -5
- package/lib/rolldown-config/config.js.map +1 -1
- package/lib/rolldown-config/constants.cjs +15 -0
- package/lib/rolldown-config/constants.cjs.map +1 -1
- package/lib/rolldown-config/constants.d.ts +15 -0
- package/lib/rolldown-config/constants.js +15 -0
- package/lib/rolldown-config/constants.js.map +1 -1
- package/lib/rolldown-config/helpers.cjs +16 -1
- package/lib/rolldown-config/helpers.cjs.map +1 -1
- package/lib/rolldown-config/helpers.d.ts +14 -0
- package/lib/rolldown-config/helpers.js +16 -1
- package/lib/rolldown-config/helpers.js.map +1 -1
- package/lib/rolldown-config/input.cjs +8 -0
- package/lib/rolldown-config/input.cjs.map +1 -1
- package/lib/rolldown-config/input.d.ts +8 -0
- package/lib/rolldown-config/input.js +8 -0
- package/lib/rolldown-config/input.js.map +1 -1
- package/lib/rolldown-config/output.cjs +8 -0
- package/lib/rolldown-config/output.cjs.map +1 -1
- package/lib/rolldown-config/output.d.ts +8 -0
- package/lib/rolldown-config/output.js +8 -0
- package/lib/rolldown-config/output.js.map +1 -1
- package/lib/rolldown-config/plugins/circulars.cjs +4 -4
- package/lib/rolldown-config/plugins/circulars.cjs.map +1 -1
- package/lib/rolldown-config/plugins/circulars.d.ts +7 -4
- package/lib/rolldown-config/plugins/circulars.js +4 -4
- package/lib/rolldown-config/plugins/circulars.js.map +1 -1
- package/lib/rolldown-config/plugins/clean.cjs +10 -1
- package/lib/rolldown-config/plugins/clean.cjs.map +1 -1
- package/lib/rolldown-config/plugins/clean.d.ts +10 -0
- package/lib/rolldown-config/plugins/clean.js +10 -1
- package/lib/rolldown-config/plugins/clean.js.map +1 -1
- package/lib/rolldown-config/plugins/externals.cjs +4 -3
- package/lib/rolldown-config/plugins/externals.cjs.map +1 -1
- package/lib/rolldown-config/plugins/externals.d.ts +7 -3
- package/lib/rolldown-config/plugins/externals.js +4 -3
- package/lib/rolldown-config/plugins/externals.js.map +1 -1
- package/lib/rolldown-config/plugins/index.cjs +6 -0
- package/lib/rolldown-config/plugins/index.cjs.map +1 -1
- package/lib/rolldown-config/plugins/index.d.ts +6 -0
- package/lib/rolldown-config/plugins/index.js +6 -0
- package/lib/rolldown-config/plugins/index.js.map +1 -1
- package/lib/rolldown-config/plugins/typescript.cjs +7 -0
- package/lib/rolldown-config/plugins/typescript.cjs.map +1 -1
- package/lib/rolldown-config/plugins/typescript.config.cjs +15 -0
- package/lib/rolldown-config/plugins/typescript.config.cjs.map +1 -1
- package/lib/rolldown-config/plugins/typescript.config.d.ts +15 -0
- package/lib/rolldown-config/plugins/typescript.config.js +15 -0
- package/lib/rolldown-config/plugins/typescript.config.js.map +1 -1
- package/lib/rolldown-config/plugins/typescript.d.ts +10 -0
- package/lib/rolldown-config/plugins/typescript.fast.cjs +9 -1
- package/lib/rolldown-config/plugins/typescript.fast.cjs.map +1 -1
- package/lib/rolldown-config/plugins/typescript.fast.d.ts +10 -0
- package/lib/rolldown-config/plugins/typescript.fast.js +9 -1
- package/lib/rolldown-config/plugins/typescript.fast.js.map +1 -1
- package/lib/rolldown-config/plugins/typescript.js +7 -0
- package/lib/rolldown-config/plugins/typescript.js.map +1 -1
- package/lib/rolldown-config/types.d.ts +18 -0
- package/lib/utils/array.cjs +7 -0
- package/lib/utils/array.cjs.map +1 -1
- package/lib/utils/array.d.ts +8 -0
- package/lib/utils/array.js +7 -0
- package/lib/utils/array.js.map +1 -1
- package/lib/utils/bemedev/globals/types.d.ts +20 -0
- package/lib/utils/bemedev/globals/utils/expandFn.cjs +11 -0
- package/lib/utils/bemedev/globals/utils/expandFn.cjs.map +1 -1
- package/lib/utils/bemedev/globals/utils/expandFn.d.ts +11 -0
- package/lib/utils/bemedev/globals/utils/expandFn.js +11 -0
- package/lib/utils/bemedev/globals/utils/expandFn.js.map +1 -1
- package/lib/utils/identity.cjs +9 -0
- package/lib/utils/identity.cjs.map +1 -1
- package/lib/utils/identity.d.ts +9 -0
- package/lib/utils/identity.js +9 -0
- package/lib/utils/identity.js.map +1 -1
- package/lib/utils/sleep.cjs +7 -0
- package/lib/utils/sleep.cjs.map +1 -1
- package/lib/utils/sleep.d.ts +7 -0
- package/lib/utils/sleep.js +7 -0
- package/lib/utils/sleep.js.map +1 -1
- package/lib/utils/types.d.ts +9 -0
- package/lib/vitest-exclude/constants.cjs +3 -0
- package/lib/vitest-exclude/constants.cjs.map +1 -1
- package/lib/vitest-exclude/constants.d.ts +3 -0
- package/lib/vitest-exclude/constants.js +3 -0
- package/lib/vitest-exclude/constants.js.map +1 -1
- package/lib/vitest-exclude/types.d.ts +11 -0
- package/lib/vitest-exclude/vitest.cjs +25 -12
- package/lib/vitest-exclude/vitest.cjs.map +1 -1
- package/lib/vitest-exclude/vitest.d.ts +9 -8
- package/lib/vitest-exclude/vitest.js +25 -12
- package/lib/vitest-exclude/vitest.js.map +1 -1
- package/lib/vitest-exclude/vitest.utils.cjs +30 -0
- package/lib/vitest-exclude/vitest.utils.cjs.map +1 -1
- package/lib/vitest-exclude/vitest.utils.d.ts +30 -0
- package/lib/vitest-exclude/vitest.utils.js +30 -0
- package/lib/vitest-exclude/vitest.utils.js.map +1 -1
- package/lib/vitest-extended/acceptation.cjs +11 -2
- package/lib/vitest-extended/acceptation.cjs.map +1 -1
- package/lib/vitest-extended/acceptation.d.ts +9 -1
- package/lib/vitest-extended/acceptation.js +11 -2
- package/lib/vitest-extended/acceptation.js.map +1 -1
- package/lib/vitest-extended/createTests.cjs +34 -27
- package/lib/vitest-extended/createTests.cjs.map +1 -1
- package/lib/vitest-extended/createTests.d.ts +20 -37
- package/lib/vitest-extended/createTests.js +34 -27
- package/lib/vitest-extended/createTests.js.map +1 -1
- package/lib/vitest-extended/createTests.types.d.ts +13 -2
- package/lib/vitest-extended/done.cjs +18 -15
- package/lib/vitest-extended/done.cjs.map +1 -1
- package/lib/vitest-extended/done.d.ts +6 -5
- package/lib/vitest-extended/done.js +18 -15
- package/lib/vitest-extended/done.js.map +1 -1
- package/lib/vitest-extended/each/error.cjs +12 -0
- package/lib/vitest-extended/each/error.cjs.map +1 -1
- package/lib/vitest-extended/each/error.d.ts +12 -0
- package/lib/vitest-extended/each/error.js +12 -0
- package/lib/vitest-extended/each/error.js.map +1 -1
- package/lib/vitest-extended/each/error.types.d.ts +17 -0
- package/lib/vitest-extended/each/pass.cjs +9 -20
- package/lib/vitest-extended/each/pass.cjs.map +1 -1
- package/lib/vitest-extended/each/pass.d.ts +9 -20
- package/lib/vitest-extended/each/pass.js +9 -20
- package/lib/vitest-extended/each/pass.js.map +1 -1
- package/lib/vitest-extended/each/pass.types.d.ts +24 -0
- package/lib/vitest-extended/fakeWaiter.cjs +7 -0
- package/lib/vitest-extended/fakeWaiter.cjs.map +1 -1
- package/lib/vitest-extended/fakeWaiter.d.ts +32 -0
- package/lib/vitest-extended/fakeWaiter.js +7 -0
- package/lib/vitest-extended/fakeWaiter.js.map +1 -1
- package/lib/vitest-extended/fixtures/coverage.cjs +11 -0
- package/lib/vitest-extended/fixtures/coverage.cjs.map +1 -1
- package/lib/vitest-extended/fixtures/coverage.js +11 -0
- package/lib/vitest-extended/fixtures/coverage.js.map +1 -1
- package/lib/vitest-extended/fixtures/partialCall.cjs +9 -4
- package/lib/vitest-extended/fixtures/partialCall.cjs.map +1 -1
- package/lib/vitest-extended/fixtures/partialCall.js +9 -4
- package/lib/vitest-extended/fixtures/partialCall.js.map +1 -1
- package/lib/vitest-extended/fixtures/toUpper.cjs +18 -0
- package/lib/vitest-extended/fixtures/toUpper.cjs.map +1 -1
- package/lib/vitest-extended/fixtures/toUpper.js +18 -0
- package/lib/vitest-extended/fixtures/toUpper.js.map +1 -1
- package/lib/vitest-extended/fixtures/vitest.cjs +3 -0
- package/lib/vitest-extended/fixtures/vitest.cjs.map +1 -1
- package/lib/vitest-extended/fixtures/vitest.js +3 -0
- package/lib/vitest-extended/fixtures/vitest.js.map +1 -1
- package/lib/vitest-extended/fixtures/zod.cjs +22 -0
- package/lib/vitest-extended/fixtures/zod.cjs.map +1 -1
- package/lib/vitest-extended/fixtures/zod.js +22 -0
- package/lib/vitest-extended/fixtures/zod.js.map +1 -1
- package/lib/vitest-extended/identity.cjs +18 -0
- package/lib/vitest-extended/identity.cjs.map +1 -1
- package/lib/vitest-extended/identity.d.ts +18 -0
- package/lib/vitest-extended/identity.js +18 -0
- package/lib/vitest-extended/identity.js.map +1 -1
- package/lib/vitest-extended/isDefined.cjs +9 -0
- package/lib/vitest-extended/isDefined.cjs.map +1 -1
- package/lib/vitest-extended/isDefined.d.ts +9 -0
- package/lib/vitest-extended/isDefined.js +9 -0
- package/lib/vitest-extended/isDefined.js.map +1 -1
- package/lib/vitest-extended/isFunction.cjs +7 -0
- package/lib/vitest-extended/isFunction.cjs.map +1 -1
- package/lib/vitest-extended/isFunction.d.ts +7 -0
- package/lib/vitest-extended/isFunction.js +7 -0
- package/lib/vitest-extended/isFunction.js.map +1 -1
- package/lib/vitest-extended/project.cjs +7 -0
- package/lib/vitest-extended/project.cjs.map +1 -1
- package/lib/vitest-extended/project.d.ts +7 -0
- package/lib/vitest-extended/project.js +7 -0
- package/lib/vitest-extended/project.js.map +1 -1
- package/lib/vitest-extended/toArray.cjs +6 -0
- package/lib/vitest-extended/toArray.cjs.map +1 -1
- package/lib/vitest-extended/toArray.d.ts +6 -0
- package/lib/vitest-extended/toArray.js +6 -0
- package/lib/vitest-extended/toArray.js.map +1 -1
- package/lib/vitest-extended/toStringFlat.cjs +8 -0
- package/lib/vitest-extended/toStringFlat.cjs.map +1 -1
- package/lib/vitest-extended/toStringFlat.d.ts +8 -0
- package/lib/vitest-extended/toStringFlat.js +8 -0
- package/lib/vitest-extended/toStringFlat.js.map +1 -1
- package/lib/vitest-extended/types.d.ts +64 -0
- package/package.json +14 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"done.cjs","names":["sleep","test"],"sources":["../../src/vitest-extended/done.ts"],"sourcesContent":["import { expect, test, type TestOptions } from 'vitest';\n\nimport { sleep } from '#utils/sleep';\n\nimport type { TestDoneFunction } from './types';\n\nconst useDone = (ms = 0) => {\n let executed = false;\n const done = () => (executed = true);\n\n const testDone = async () => {\n await sleep(ms);\n expect(executed).toBe(true);\n };\n\n return { done, testDone };\n};\n\nconst min100 = (ms = 0) => Math.max(100, ms);\n\n// #region Preparation\nconst getTimeout = (options?: TestOptions | number) => {\n if (typeof options === 'number') return min100(options);\n return min100(options?.timeout);\n};\n\nconst objectify = (\n options?: TestOptions | number,\n): [TestOptions, number] => {\n const _timeout = getTimeout(options);\n const timeout = _timeout + 100;\n\n let _options = { timeout };\n if (!(typeof options === 'number')) {\n _options = { ...options, timeout };\n }\n\n return [_options, _timeout];\n};\n// #endregion\n\n/**\n * Build a test with a done function
|
|
1
|
+
{"version":3,"file":"done.cjs","names":["sleep","test"],"sources":["../../src/vitest-extended/done.ts"],"sourcesContent":["import { expect, test, type TestOptions } from 'vitest';\n\nimport { sleep } from '#utils/sleep';\n\nimport type { TestDoneFunction } from './types';\n\nconst useDone = (ms = 0) => {\n let executed = false;\n const done = () => (executed = true);\n\n const testDone = async () => {\n await sleep(ms);\n expect(executed).toBe(true);\n };\n\n return { done, testDone };\n};\n\nconst min100 = (ms = 0) => Math.max(100, ms);\n\n// #region Preparation\nconst getTimeout = (options?: TestOptions | number) => {\n if (typeof options === 'number') return min100(options);\n return min100(options?.timeout);\n};\n\nconst objectify = (\n options?: TestOptions | number,\n): [TestOptions, number] => {\n const _timeout = getTimeout(options);\n const timeout = _timeout + 100;\n\n let _options = { timeout };\n if (!(typeof options === 'number')) {\n _options = { ...options, timeout };\n }\n\n return [_options, _timeout];\n};\n// #endregion\n\n/**\n * Build a test with a done callback function and a timeout.\n *\n * @param invite - The description of the test.\n * @param fn - Test callback function of type {@linkcode TestDoneFunction}.\n * @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.\n *\n * @returns A Vitest test execution result.\n */\nexport const doneTest = (\n invite: string,\n fn: TestDoneFunction,\n options: number | TestOptions = 100,\n) => {\n const [_options, ms] = objectify(options);\n\n return test(invite, _options, () => {\n const { done, testDone } = useDone(ms);\n fn(done);\n return testDone();\n });\n};\n\n/**\n * Build a test expected to fail with a done callback function and a timeout.\n *\n * @param invite - The description of the test.\n * @param fn - Test callback function of type {@linkcode TestDoneFunction}.\n * @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.\n *\n * @returns A Vitest test execution result.\n */\ndoneTest.fails = (\n invite: string,\n fn: TestDoneFunction,\n options: number | TestOptions = 100,\n) => {\n const [_options, ms] = objectify(options);\n\n return test.fails(invite, _options, () => {\n const { done, testDone } = useDone(ms);\n fn(done);\n return testDone();\n });\n};\n\n/**\n * Build a concurrent test with a done callback function and a timeout.\n *\n * @param invite - The description of the test.\n * @param fn - Test callback function of type {@linkcode TestDoneFunction}.\n * @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.\n *\n * @returns A Vitest test execution result.\n */\ndoneTest.concurrent = (\n invite: string,\n fn: TestDoneFunction,\n options: number | TestOptions = 100,\n) => {\n const [_options, ms] = objectify(options);\n\n return test.concurrent(invite, _options, () => {\n const { done, testDone } = useDone(ms);\n fn(done);\n return testDone();\n });\n};\n"],"mappings":";;;;AAMA,MAAM,WAAW,KAAK,MAAM;CAC1B,IAAI,WAAW;CACf,MAAM,aAAc,WAAW;CAE/B,MAAM,WAAW,YAAY;EAC3B,MAAMA,oBAAAA,MAAM,EAAE;EACd,CAAA,GAAA,OAAA,OAAA,CAAO,QAAQ,CAAC,CAAC,KAAK,IAAI;CAC5B;CAEA,OAAO;EAAE;EAAM;CAAS;AAC1B;AAEA,MAAM,UAAU,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE;AAG3C,MAAM,cAAc,YAAmC;CACrD,IAAI,OAAO,YAAY,UAAU,OAAO,OAAO,OAAO;CACtD,OAAO,OAAO,SAAS,OAAO;AAChC;AAEA,MAAM,aACJ,YAC0B;CAC1B,MAAM,WAAW,WAAW,OAAO;CACnC,MAAM,UAAU,WAAW;CAE3B,IAAI,WAAW,EAAE,QAAQ;CACzB,IAAI,EAAE,OAAO,YAAY,WACvB,WAAW;EAAE,GAAG;EAAS;CAAQ;CAGnC,OAAO,CAAC,UAAU,QAAQ;AAC5B;;;;;;;;;;AAYA,MAAa,YACX,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,OAAO;CAExC,QAAA,GAAOC,OAAAA,KAAAA,CAAK,QAAQ,gBAAgB;EAClC,MAAM,EAAE,MAAM,aAAa,QAAQ,EAAE;EACrC,GAAG,IAAI;EACP,OAAO,SAAS;CAClB,CAAC;AACH;;;;;;;;;;AAWA,SAAS,SACP,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,OAAO;CAExC,OAAOA,OAAAA,KAAK,MAAM,QAAQ,gBAAgB;EACxC,MAAM,EAAE,MAAM,aAAa,QAAQ,EAAE;EACrC,GAAG,IAAI;EACP,OAAO,SAAS;CAClB,CAAC;AACH;;;;;;;;;;AAWA,SAAS,cACP,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,OAAO;CAExC,OAAOA,OAAAA,KAAK,WAAW,QAAQ,gBAAgB;EAC7C,MAAM,EAAE,MAAM,aAAa,QAAQ,EAAE;EACrC,GAAG,IAAI;EACP,OAAO,SAAS;CAClB,CAAC;AACH"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { type TestOptions } from 'vitest';
|
|
2
2
|
import type { TestDoneFunction } from './types';
|
|
3
3
|
/**
|
|
4
|
-
* Build a test with a done function
|
|
4
|
+
* Build a test with a done callback function and a timeout.
|
|
5
5
|
*
|
|
6
|
-
* @param invite The description of the test
|
|
7
|
-
* @param fn
|
|
8
|
-
* @param options
|
|
9
|
-
*
|
|
6
|
+
* @param invite - The description of the test.
|
|
7
|
+
* @param fn - Test callback function of type {@linkcode TestDoneFunction}.
|
|
8
|
+
* @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.
|
|
9
|
+
*
|
|
10
|
+
* @returns A Vitest test execution result.
|
|
10
11
|
*/
|
|
11
12
|
export declare const doneTest: {
|
|
12
13
|
(invite: string, fn: TestDoneFunction, options?: number | TestOptions): void;
|
|
@@ -29,12 +29,13 @@ const objectify = (options) => {
|
|
|
29
29
|
return [_options, _timeout];
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
|
-
* Build a test with a done function
|
|
32
|
+
* Build a test with a done callback function and a timeout.
|
|
33
33
|
*
|
|
34
|
-
* @param invite The description of the test
|
|
35
|
-
* @param fn
|
|
36
|
-
* @param options
|
|
37
|
-
*
|
|
34
|
+
* @param invite - The description of the test.
|
|
35
|
+
* @param fn - Test callback function of type {@linkcode TestDoneFunction}.
|
|
36
|
+
* @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.
|
|
37
|
+
*
|
|
38
|
+
* @returns A Vitest test execution result.
|
|
38
39
|
*/
|
|
39
40
|
const doneTest = (invite, fn, options = 100) => {
|
|
40
41
|
const [_options, ms] = objectify(options);
|
|
@@ -45,12 +46,13 @@ const doneTest = (invite, fn, options = 100) => {
|
|
|
45
46
|
});
|
|
46
47
|
};
|
|
47
48
|
/**
|
|
48
|
-
* Build a test
|
|
49
|
+
* Build a test expected to fail with a done callback function and a timeout.
|
|
50
|
+
*
|
|
51
|
+
* @param invite - The description of the test.
|
|
52
|
+
* @param fn - Test callback function of type {@linkcode TestDoneFunction}.
|
|
53
|
+
* @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.
|
|
49
54
|
*
|
|
50
|
-
* @
|
|
51
|
-
* @param fn Where you can test, Don't async this function
|
|
52
|
-
* @param options Options for the test like TestAPI from vitest
|
|
53
|
-
* @returns A vitest test
|
|
55
|
+
* @returns A Vitest test execution result.
|
|
54
56
|
*/
|
|
55
57
|
doneTest.fails = (invite, fn, options = 100) => {
|
|
56
58
|
const [_options, ms] = objectify(options);
|
|
@@ -61,12 +63,13 @@ doneTest.fails = (invite, fn, options = 100) => {
|
|
|
61
63
|
});
|
|
62
64
|
};
|
|
63
65
|
/**
|
|
64
|
-
* Build a concurrent test with a done function
|
|
66
|
+
* Build a concurrent test with a done callback function and a timeout.
|
|
67
|
+
*
|
|
68
|
+
* @param invite - The description of the test.
|
|
69
|
+
* @param fn - Test callback function of type {@linkcode TestDoneFunction}.
|
|
70
|
+
* @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.
|
|
65
71
|
*
|
|
66
|
-
* @
|
|
67
|
-
* @param fn Where you can test, Don't async this function
|
|
68
|
-
* @param options Options for the test like TestAPI from vitest
|
|
69
|
-
* @returns A vitest test
|
|
72
|
+
* @returns A Vitest test execution result.
|
|
70
73
|
*/
|
|
71
74
|
doneTest.concurrent = (invite, fn, options = 100) => {
|
|
72
75
|
const [_options, ms] = objectify(options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"done.js","names":[],"sources":["../../src/vitest-extended/done.ts"],"sourcesContent":["import { expect, test, type TestOptions } from 'vitest';\n\nimport { sleep } from '#utils/sleep';\n\nimport type { TestDoneFunction } from './types';\n\nconst useDone = (ms = 0) => {\n let executed = false;\n const done = () => (executed = true);\n\n const testDone = async () => {\n await sleep(ms);\n expect(executed).toBe(true);\n };\n\n return { done, testDone };\n};\n\nconst min100 = (ms = 0) => Math.max(100, ms);\n\n// #region Preparation\nconst getTimeout = (options?: TestOptions | number) => {\n if (typeof options === 'number') return min100(options);\n return min100(options?.timeout);\n};\n\nconst objectify = (\n options?: TestOptions | number,\n): [TestOptions, number] => {\n const _timeout = getTimeout(options);\n const timeout = _timeout + 100;\n\n let _options = { timeout };\n if (!(typeof options === 'number')) {\n _options = { ...options, timeout };\n }\n\n return [_options, _timeout];\n};\n// #endregion\n\n/**\n * Build a test with a done function
|
|
1
|
+
{"version":3,"file":"done.js","names":[],"sources":["../../src/vitest-extended/done.ts"],"sourcesContent":["import { expect, test, type TestOptions } from 'vitest';\n\nimport { sleep } from '#utils/sleep';\n\nimport type { TestDoneFunction } from './types';\n\nconst useDone = (ms = 0) => {\n let executed = false;\n const done = () => (executed = true);\n\n const testDone = async () => {\n await sleep(ms);\n expect(executed).toBe(true);\n };\n\n return { done, testDone };\n};\n\nconst min100 = (ms = 0) => Math.max(100, ms);\n\n// #region Preparation\nconst getTimeout = (options?: TestOptions | number) => {\n if (typeof options === 'number') return min100(options);\n return min100(options?.timeout);\n};\n\nconst objectify = (\n options?: TestOptions | number,\n): [TestOptions, number] => {\n const _timeout = getTimeout(options);\n const timeout = _timeout + 100;\n\n let _options = { timeout };\n if (!(typeof options === 'number')) {\n _options = { ...options, timeout };\n }\n\n return [_options, _timeout];\n};\n// #endregion\n\n/**\n * Build a test with a done callback function and a timeout.\n *\n * @param invite - The description of the test.\n * @param fn - Test callback function of type {@linkcode TestDoneFunction}.\n * @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.\n *\n * @returns A Vitest test execution result.\n */\nexport const doneTest = (\n invite: string,\n fn: TestDoneFunction,\n options: number | TestOptions = 100,\n) => {\n const [_options, ms] = objectify(options);\n\n return test(invite, _options, () => {\n const { done, testDone } = useDone(ms);\n fn(done);\n return testDone();\n });\n};\n\n/**\n * Build a test expected to fail with a done callback function and a timeout.\n *\n * @param invite - The description of the test.\n * @param fn - Test callback function of type {@linkcode TestDoneFunction}.\n * @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.\n *\n * @returns A Vitest test execution result.\n */\ndoneTest.fails = (\n invite: string,\n fn: TestDoneFunction,\n options: number | TestOptions = 100,\n) => {\n const [_options, ms] = objectify(options);\n\n return test.fails(invite, _options, () => {\n const { done, testDone } = useDone(ms);\n fn(done);\n return testDone();\n });\n};\n\n/**\n * Build a concurrent test with a done callback function and a timeout.\n *\n * @param invite - The description of the test.\n * @param fn - Test callback function of type {@linkcode TestDoneFunction}.\n * @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.\n *\n * @returns A Vitest test execution result.\n */\ndoneTest.concurrent = (\n invite: string,\n fn: TestDoneFunction,\n options: number | TestOptions = 100,\n) => {\n const [_options, ms] = objectify(options);\n\n return test.concurrent(invite, _options, () => {\n const { done, testDone } = useDone(ms);\n fn(done);\n return testDone();\n });\n};\n"],"mappings":";;;AAMA,MAAM,WAAW,KAAK,MAAM;CAC1B,IAAI,WAAW;CACf,MAAM,aAAc,WAAW;CAE/B,MAAM,WAAW,YAAY;EAC3B,MAAM,MAAM,EAAE;EACd,OAAO,QAAQ,CAAC,CAAC,KAAK,IAAI;CAC5B;CAEA,OAAO;EAAE;EAAM;CAAS;AAC1B;AAEA,MAAM,UAAU,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE;AAG3C,MAAM,cAAc,YAAmC;CACrD,IAAI,OAAO,YAAY,UAAU,OAAO,OAAO,OAAO;CACtD,OAAO,OAAO,SAAS,OAAO;AAChC;AAEA,MAAM,aACJ,YAC0B;CAC1B,MAAM,WAAW,WAAW,OAAO;CACnC,MAAM,UAAU,WAAW;CAE3B,IAAI,WAAW,EAAE,QAAQ;CACzB,IAAI,EAAE,OAAO,YAAY,WACvB,WAAW;EAAE,GAAG;EAAS;CAAQ;CAGnC,OAAO,CAAC,UAAU,QAAQ;AAC5B;;;;;;;;;;AAYA,MAAa,YACX,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,OAAO;CAExC,OAAO,KAAK,QAAQ,gBAAgB;EAClC,MAAM,EAAE,MAAM,aAAa,QAAQ,EAAE;EACrC,GAAG,IAAI;EACP,OAAO,SAAS;CAClB,CAAC;AACH;;;;;;;;;;AAWA,SAAS,SACP,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,OAAO;CAExC,OAAO,KAAK,MAAM,QAAQ,gBAAgB;EACxC,MAAM,EAAE,MAAM,aAAa,QAAQ,EAAE;EACrC,GAAG,IAAI;EACP,OAAO,SAAS;CAClB,CAAC;AACH;;;;;;;;;;AAWA,SAAS,cACP,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,OAAO;CAExC,OAAO,KAAK,WAAW,QAAQ,gBAAgB;EAC7C,MAAM,EAAE,MAAM,aAAa,QAAQ,EAAE;EACrC,GAAG,IAAI;EACP,OAAO,SAAS;CAClB,CAAC;AACH"}
|
|
@@ -3,6 +3,9 @@ const require_vitest_extended_toArray = require("../toArray.cjs");
|
|
|
3
3
|
const require_vitest_extended_identity = require("../identity.cjs");
|
|
4
4
|
let vitest = require("vitest");
|
|
5
5
|
//#region src/vitest-extended/each/error.ts
|
|
6
|
+
/**
|
|
7
|
+
* Runs error assertions for asynchronous test cases concurrently.
|
|
8
|
+
*/
|
|
6
9
|
const useErrorAsyncEachCases = (f, transform = require_vitest_extended_identity.identity, toError = () => void 0, ...cases) => {
|
|
7
10
|
vitest.test.concurrent.each(require_vitest_extended_toArray.toArrayVitest.error(cases))("%s", async (_, args, _error) => {
|
|
8
11
|
const actual = async () => {
|
|
@@ -12,6 +15,15 @@ const useErrorAsyncEachCases = (f, transform = require_vitest_extended_identity.
|
|
|
12
15
|
await (0, vitest.expect)(actual).rejects.toThrowError(error);
|
|
13
16
|
});
|
|
14
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Higher-order function returning a test runner for asynchronous error assertions.
|
|
20
|
+
*
|
|
21
|
+
* @param f - Function to test.
|
|
22
|
+
* @param transform - Optional transformer applied to the resolved return value.
|
|
23
|
+
* @param toError - Optional function computing expected error message from arguments.
|
|
24
|
+
*
|
|
25
|
+
* @returns Function accepting error test cases to execute.
|
|
26
|
+
*/
|
|
15
27
|
const useErrorAsyncEach = (f, transform, toError) => {
|
|
16
28
|
return (...cases) => useErrorAsyncEachCases(f, transform, toError, ...cases);
|
|
17
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.cjs","names":["identity","toArrayVitest"],"sources":["../../../src/vitest-extended/each/error.ts"],"sourcesContent":["import { expect, test } from 'vitest';\n\nimport { identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type { _UseErrorEach_F, UseErrorEach_F } from './error.types';\n\nexport const useErrorAsyncEachCases: _UseErrorEach_F = (\n f,\n transform = identity as any,\n toError = () => undefined,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest.error(cases))(\n '%s',\n async (_, args, _error) => {\n const actual = async () => {\n const out = await f(...args);\n return transform(out);\n };\n const check = _error === undefined;\n const error = check ? toError(...args) : _error;\n\n await expect(actual).rejects.toThrowError(error);\n },\n );\n};\n\nexport const useErrorAsyncEach: UseErrorEach_F = (\n f,\n transform,\n toError,\n) => {\n return (...cases) =>\n useErrorAsyncEachCases(f, transform, toError, ...cases);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"error.cjs","names":["identity","toArrayVitest","expect"],"sources":["../../../src/vitest-extended/each/error.ts"],"sourcesContent":["import { expect, test } from 'vitest';\n\nimport { identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type { _UseErrorEach_F, UseErrorEach_F } from './error.types';\n\n/**\n * Runs error assertions for asynchronous test cases concurrently.\n */\nexport const useErrorAsyncEachCases: _UseErrorEach_F = (\n f,\n transform = identity as any,\n toError = () => undefined,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest.error(cases))(\n '%s',\n async (_, args, _error) => {\n const actual = async () => {\n const out = await f(...args);\n return transform(out);\n };\n const check = _error === undefined;\n const error = check ? toError(...args) : _error;\n\n await expect(actual).rejects.toThrowError(error);\n },\n );\n};\n\n/**\n * Higher-order function returning a test runner for asynchronous error assertions.\n *\n * @param f - Function to test.\n * @param transform - Optional transformer applied to the resolved return value.\n * @param toError - Optional function computing expected error message from arguments.\n *\n * @returns Function accepting error test cases to execute.\n */\nexport const useErrorAsyncEach: UseErrorEach_F = (\n f,\n transform,\n toError,\n) => {\n return (...cases) =>\n useErrorAsyncEachCases(f, transform, toError, ...cases);\n};\n"],"mappings":";;;;;;;;AASA,MAAa,0BACX,GACA,YAAYA,iCAAAA,UACZ,gBAAgB,KAAA,GAChB,GAAG,UACA;CACH,OAAA,KAAK,WAAW,KAAKC,gCAAAA,cAAc,MAAM,KAAK,CAAC,CAAC,CAC9C,MACA,OAAO,GAAG,MAAM,WAAW;EACzB,MAAM,SAAS,YAAY;GAEzB,OAAO,UAAU,MADC,EAAE,GAAG,IAAI,CACP;EACtB;EAEA,MAAM,QADQ,WAAW,KAAA,IACH,QAAQ,GAAG,IAAI,IAAI;EAEzC,OAAA,GAAMC,OAAAA,OAAAA,CAAO,MAAM,CAAC,CAAC,QAAQ,aAAa,KAAK;CACjD,CACF;AACF;;;;;;;;;;AAWA,MAAa,qBACX,GACA,WACA,YACG;CACH,QAAQ,GAAG,UACT,uBAAuB,GAAG,WAAW,SAAS,GAAG,KAAK;AAC1D"}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
import type { _UseErrorEach_F, UseErrorEach_F } from './error.types';
|
|
2
|
+
/**
|
|
3
|
+
* Runs error assertions for asynchronous test cases concurrently.
|
|
4
|
+
*/
|
|
2
5
|
export declare const useErrorAsyncEachCases: _UseErrorEach_F;
|
|
6
|
+
/**
|
|
7
|
+
* Higher-order function returning a test runner for asynchronous error assertions.
|
|
8
|
+
*
|
|
9
|
+
* @param f - Function to test.
|
|
10
|
+
* @param transform - Optional transformer applied to the resolved return value.
|
|
11
|
+
* @param toError - Optional function computing expected error message from arguments.
|
|
12
|
+
*
|
|
13
|
+
* @returns Function accepting error test cases to execute.
|
|
14
|
+
*/
|
|
3
15
|
export declare const useErrorAsyncEach: UseErrorEach_F;
|
|
@@ -2,6 +2,9 @@ import { toArrayVitest } from "../toArray.js";
|
|
|
2
2
|
import { identity } from "../identity.js";
|
|
3
3
|
import { expect, test } from "vitest";
|
|
4
4
|
//#region src/vitest-extended/each/error.ts
|
|
5
|
+
/**
|
|
6
|
+
* Runs error assertions for asynchronous test cases concurrently.
|
|
7
|
+
*/
|
|
5
8
|
const useErrorAsyncEachCases = (f, transform = identity, toError = () => void 0, ...cases) => {
|
|
6
9
|
test.concurrent.each(toArrayVitest.error(cases))("%s", async (_, args, _error) => {
|
|
7
10
|
const actual = async () => {
|
|
@@ -11,6 +14,15 @@ const useErrorAsyncEachCases = (f, transform = identity, toError = () => void 0,
|
|
|
11
14
|
await expect(actual).rejects.toThrowError(error);
|
|
12
15
|
});
|
|
13
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Higher-order function returning a test runner for asynchronous error assertions.
|
|
19
|
+
*
|
|
20
|
+
* @param f - Function to test.
|
|
21
|
+
* @param transform - Optional transformer applied to the resolved return value.
|
|
22
|
+
* @param toError - Optional function computing expected error message from arguments.
|
|
23
|
+
*
|
|
24
|
+
* @returns Function accepting error test cases to execute.
|
|
25
|
+
*/
|
|
14
26
|
const useErrorAsyncEach = (f, transform, toError) => {
|
|
15
27
|
return (...cases) => useErrorAsyncEachCases(f, transform, toError, ...cases);
|
|
16
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","names":[],"sources":["../../../src/vitest-extended/each/error.ts"],"sourcesContent":["import { expect, test } from 'vitest';\n\nimport { identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type { _UseErrorEach_F, UseErrorEach_F } from './error.types';\n\nexport const useErrorAsyncEachCases: _UseErrorEach_F = (\n f,\n transform = identity as any,\n toError = () => undefined,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest.error(cases))(\n '%s',\n async (_, args, _error) => {\n const actual = async () => {\n const out = await f(...args);\n return transform(out);\n };\n const check = _error === undefined;\n const error = check ? toError(...args) : _error;\n\n await expect(actual).rejects.toThrowError(error);\n },\n );\n};\n\nexport const useErrorAsyncEach: UseErrorEach_F = (\n f,\n transform,\n toError,\n) => {\n return (...cases) =>\n useErrorAsyncEachCases(f, transform, toError, ...cases);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"error.js","names":[],"sources":["../../../src/vitest-extended/each/error.ts"],"sourcesContent":["import { expect, test } from 'vitest';\n\nimport { identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type { _UseErrorEach_F, UseErrorEach_F } from './error.types';\n\n/**\n * Runs error assertions for asynchronous test cases concurrently.\n */\nexport const useErrorAsyncEachCases: _UseErrorEach_F = (\n f,\n transform = identity as any,\n toError = () => undefined,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest.error(cases))(\n '%s',\n async (_, args, _error) => {\n const actual = async () => {\n const out = await f(...args);\n return transform(out);\n };\n const check = _error === undefined;\n const error = check ? toError(...args) : _error;\n\n await expect(actual).rejects.toThrowError(error);\n },\n );\n};\n\n/**\n * Higher-order function returning a test runner for asynchronous error assertions.\n *\n * @param f - Function to test.\n * @param transform - Optional transformer applied to the resolved return value.\n * @param toError - Optional function computing expected error message from arguments.\n *\n * @returns Function accepting error test cases to execute.\n */\nexport const useErrorAsyncEach: UseErrorEach_F = (\n f,\n transform,\n toError,\n) => {\n return (...cases) =>\n useErrorAsyncEachCases(f, transform, toError, ...cases);\n};\n"],"mappings":";;;;;;;AASA,MAAa,0BACX,GACA,YAAY,UACZ,gBAAgB,KAAA,GAChB,GAAG,UACA;CACH,KAAK,WAAW,KAAK,cAAc,MAAM,KAAK,CAAC,CAAC,CAC9C,MACA,OAAO,GAAG,MAAM,WAAW;EACzB,MAAM,SAAS,YAAY;GAEzB,OAAO,UAAU,MADC,EAAE,GAAG,IAAI,CACP;EACtB;EAEA,MAAM,QADQ,WAAW,KAAA,IACH,QAAQ,GAAG,IAAI,IAAI;EAEzC,MAAM,OAAO,MAAM,CAAC,CAAC,QAAQ,aAAa,KAAK;CACjD,CACF;AACF;;;;;;;;;;AAWA,MAAa,qBACX,GACA,WACA,YACG;CACH,QAAQ,GAAG,UACT,uBAAuB,GAAG,WAAW,SAAS,GAAG,KAAK;AAC1D"}
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import type { Fn } from '../../utils/bemedev/globals/types';
|
|
2
2
|
import type { Identity, NextFn, TestErrors } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Function computing an expected error message from function parameters.
|
|
5
|
+
*
|
|
6
|
+
* @template | {@linkcode Fn} `F` - Function type.
|
|
7
|
+
*/
|
|
3
8
|
export type ToError_F<F extends Fn> = (...params: Parameters<F>) => string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Runner function signature for error assertion test cases.
|
|
11
|
+
*
|
|
12
|
+
* @template | {@linkcode Fn} `F` - Target function type.
|
|
13
|
+
* @template | {@linkcode NextFn} `T` - Transformer function type, defaults to {@linkcode Identity}.
|
|
14
|
+
*/
|
|
4
15
|
export type _UseErrorEach_F = <F extends Fn, T extends NextFn<F> = Identity<F>>(f: F, transform?: T, toError?: ToError_F<F>, ...cases: TestErrors<F>) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Higher-order function returning a test runner for error assertion cases.
|
|
18
|
+
*
|
|
19
|
+
* @template | {@linkcode Fn} `F` - Target function type.
|
|
20
|
+
* @template | {@linkcode NextFn} `T` - Transformer function type, defaults to {@linkcode Identity}.
|
|
21
|
+
*/
|
|
5
22
|
export type UseErrorEach_F = <F extends Fn, T extends NextFn<F> = Identity<F>>(f: F, transform?: T, toError?: ToError_F<F>) => Fn<TestErrors<F>, void>;
|
|
@@ -9,26 +9,12 @@ const useEachCases = (func, transform = require_vitest_extended_identity.identit
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Runs parameterized tests with strict equality checks across multiple cases.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* @param func - Function to test.
|
|
15
|
+
* @param transform - Optional transformer applied to the return value.
|
|
15
16
|
*
|
|
16
|
-
* @
|
|
17
|
-
* @type R ReturnType of the function
|
|
18
|
-
* @param func The function to test
|
|
19
|
-
* @param cases The cases to test, The invite is the first arguments. It's
|
|
20
|
-
* an array of Array.
|
|
21
|
-
*
|
|
22
|
-
* - #1 The first arg is the invite of the test
|
|
23
|
-
* - #2 The second arg is the parameters to to pass to the function. It's
|
|
24
|
-
* an array (param array).
|
|
25
|
-
* - #3 The third arg is the expected result
|
|
26
|
-
*
|
|
27
|
-
* Example: For a function like **_(arg1: string)=>any**_, the second arg
|
|
28
|
-
* with be : **_[string]**_
|
|
29
|
-
* @if R are not provided, the return is a function to test with TestArgs arguments
|
|
30
|
-
*
|
|
31
|
-
* @else It tests every cases provided
|
|
17
|
+
* @returns Function accepting test cases to execute.
|
|
32
18
|
*/
|
|
33
19
|
const useEach = (func, transform) => {
|
|
34
20
|
return (...cases) => useEachCases(func, transform, ...cases);
|
|
@@ -39,9 +25,12 @@ const useEachAsyncCases = (f, transform = require_vitest_extended_identity.ident
|
|
|
39
25
|
});
|
|
40
26
|
};
|
|
41
27
|
/**
|
|
42
|
-
*
|
|
28
|
+
* Runs asynchronous parameterized tests with strict equality checks across multiple cases.
|
|
29
|
+
*
|
|
30
|
+
* @param func - Async function to test.
|
|
31
|
+
* @param transform - Optional transformer applied to the resolved return value.
|
|
43
32
|
*
|
|
44
|
-
*
|
|
33
|
+
* @returns Function accepting test cases to execute.
|
|
45
34
|
*/
|
|
46
35
|
const useEachAsync = (func, transform) => {
|
|
47
36
|
return (...cases) => useEachAsyncCases(func, transform, ...cases);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pass.cjs","names":["identity","toArrayVitest","defaultEquality"],"sources":["../../../src/vitest-extended/each/pass.ts"],"sourcesContent":["import { test } from 'vitest';\n\nimport { defaultEquality, identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type {\n _UseAsyncEach_F,\n _UseEach_F,\n UseAsyncEach_F,\n UseEach_F,\n} from './pass.types';\n\n// #region Sync\nconst useEachCases: _UseEach_F = (\n func,\n transform = identity as any,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest(cases))(\n '%s',\n (_, args, expected, test = defaultEquality) => {\n const value = transform(func(...args));\n return test(value, expected);\n },\n );\n};\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"pass.cjs","names":["identity","toArrayVitest","defaultEquality"],"sources":["../../../src/vitest-extended/each/pass.ts"],"sourcesContent":["import { test } from 'vitest';\n\nimport { defaultEquality, identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type {\n _UseAsyncEach_F,\n _UseEach_F,\n UseAsyncEach_F,\n UseEach_F,\n} from './pass.types';\n\n// #region Sync\nconst useEachCases: _UseEach_F = (\n func,\n transform = identity as any,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest(cases))(\n '%s',\n (_, args, expected, test = defaultEquality) => {\n const value = transform(func(...args));\n return test(value, expected);\n },\n );\n};\n\n/**\n * Runs parameterized tests with strict equality checks across multiple cases.\n *\n * @param func - Function to test.\n * @param transform - Optional transformer applied to the return value.\n *\n * @returns Function accepting test cases to execute.\n */\nexport const useEach: UseEach_F = (func, transform) => {\n return (...cases) => useEachCases(func, transform, ...cases);\n};\n// #endregion\n\n// #region Async\nconst useEachAsyncCases: _UseAsyncEach_F = (\n f,\n transform = identity as any,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest(cases))(\n '%s',\n async (_, args, expected, test = defaultEquality) => {\n const _value = await f(...args);\n const value = await transform(_value);\n return test(value, expected);\n },\n );\n};\n\n/**\n * Runs asynchronous parameterized tests with strict equality checks across multiple cases.\n *\n * @param func - Async function to test.\n * @param transform - Optional transformer applied to the resolved return value.\n *\n * @returns Function accepting test cases to execute.\n */\nexport const useEachAsync: UseAsyncEach_F = (func, transform) => {\n return (...cases) => useEachAsyncCases(func, transform, ...cases);\n};\n\n// #endregion\n"],"mappings":";;;;;AAYA,MAAM,gBACJ,MACA,YAAYA,iCAAAA,UACZ,GAAG,UACA;CACH,OAAA,KAAK,WAAW,KAAKC,gCAAAA,cAAc,KAAK,CAAC,CAAC,CACxC,OACC,GAAG,MAAM,UAAU,OAAOC,iCAAAA,oBAAoB;EAE7C,OAAO,KADO,UAAU,KAAK,GAAG,IAAI,CACpB,GAAG,QAAQ;CAC7B,CACF;AACF;;;;;;;;;AAUA,MAAa,WAAsB,MAAM,cAAc;CACrD,QAAQ,GAAG,UAAU,aAAa,MAAM,WAAW,GAAG,KAAK;AAC7D;AAIA,MAAM,qBACJ,GACA,YAAYF,iCAAAA,UACZ,GAAG,UACA;CACH,OAAA,KAAK,WAAW,KAAKC,gCAAAA,cAAc,KAAK,CAAC,CAAC,CACxC,MACA,OAAO,GAAG,MAAM,UAAU,OAAOC,iCAAAA,oBAAoB;EAGnD,OAAO,KAAK,MADQ,UAAU,MADT,EAAE,GAAG,IAAI,CACM,GACjB,QAAQ;CAC7B,CACF;AACF;;;;;;;;;AAUA,MAAa,gBAAgC,MAAM,cAAc;CAC/D,QAAQ,GAAG,UAAU,kBAAkB,MAAM,WAAW,GAAG,KAAK;AAClE"}
|
|
@@ -1,30 +1,19 @@
|
|
|
1
1
|
import type { UseAsyncEach_F, UseEach_F } from './pass.types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Runs parameterized tests with strict equality checks across multiple cases.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* @param func - Function to test.
|
|
6
|
+
* @param transform - Optional transformer applied to the return value.
|
|
6
7
|
*
|
|
7
|
-
* @
|
|
8
|
-
* @type R ReturnType of the function
|
|
9
|
-
* @param func The function to test
|
|
10
|
-
* @param cases The cases to test, The invite is the first arguments. It's
|
|
11
|
-
* an array of Array.
|
|
12
|
-
*
|
|
13
|
-
* - #1 The first arg is the invite of the test
|
|
14
|
-
* - #2 The second arg is the parameters to to pass to the function. It's
|
|
15
|
-
* an array (param array).
|
|
16
|
-
* - #3 The third arg is the expected result
|
|
17
|
-
*
|
|
18
|
-
* Example: For a function like **_(arg1: string)=>any**_, the second arg
|
|
19
|
-
* with be : **_[string]**_
|
|
20
|
-
* @if R are not provided, the return is a function to test with TestArgs arguments
|
|
21
|
-
*
|
|
22
|
-
* @else It tests every cases provided
|
|
8
|
+
* @returns Function accepting test cases to execute.
|
|
23
9
|
*/
|
|
24
10
|
export declare const useEach: UseEach_F;
|
|
25
11
|
/**
|
|
26
|
-
*
|
|
12
|
+
* Runs asynchronous parameterized tests with strict equality checks across multiple cases.
|
|
13
|
+
*
|
|
14
|
+
* @param func - Async function to test.
|
|
15
|
+
* @param transform - Optional transformer applied to the resolved return value.
|
|
27
16
|
*
|
|
28
|
-
*
|
|
17
|
+
* @returns Function accepting test cases to execute.
|
|
29
18
|
*/
|
|
30
19
|
export declare const useEachAsync: UseAsyncEach_F;
|
|
@@ -8,26 +8,12 @@ const useEachCases = (func, transform = identity, ...cases) => {
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Runs parameterized tests with strict equality checks across multiple cases.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* @param func - Function to test.
|
|
14
|
+
* @param transform - Optional transformer applied to the return value.
|
|
14
15
|
*
|
|
15
|
-
* @
|
|
16
|
-
* @type R ReturnType of the function
|
|
17
|
-
* @param func The function to test
|
|
18
|
-
* @param cases The cases to test, The invite is the first arguments. It's
|
|
19
|
-
* an array of Array.
|
|
20
|
-
*
|
|
21
|
-
* - #1 The first arg is the invite of the test
|
|
22
|
-
* - #2 The second arg is the parameters to to pass to the function. It's
|
|
23
|
-
* an array (param array).
|
|
24
|
-
* - #3 The third arg is the expected result
|
|
25
|
-
*
|
|
26
|
-
* Example: For a function like **_(arg1: string)=>any**_, the second arg
|
|
27
|
-
* with be : **_[string]**_
|
|
28
|
-
* @if R are not provided, the return is a function to test with TestArgs arguments
|
|
29
|
-
*
|
|
30
|
-
* @else It tests every cases provided
|
|
16
|
+
* @returns Function accepting test cases to execute.
|
|
31
17
|
*/
|
|
32
18
|
const useEach = (func, transform) => {
|
|
33
19
|
return (...cases) => useEachCases(func, transform, ...cases);
|
|
@@ -38,9 +24,12 @@ const useEachAsyncCases = (f, transform = identity, ...cases) => {
|
|
|
38
24
|
});
|
|
39
25
|
};
|
|
40
26
|
/**
|
|
41
|
-
*
|
|
27
|
+
* Runs asynchronous parameterized tests with strict equality checks across multiple cases.
|
|
28
|
+
*
|
|
29
|
+
* @param func - Async function to test.
|
|
30
|
+
* @param transform - Optional transformer applied to the resolved return value.
|
|
42
31
|
*
|
|
43
|
-
*
|
|
32
|
+
* @returns Function accepting test cases to execute.
|
|
44
33
|
*/
|
|
45
34
|
const useEachAsync = (func, transform) => {
|
|
46
35
|
return (...cases) => useEachAsyncCases(func, transform, ...cases);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pass.js","names":[],"sources":["../../../src/vitest-extended/each/pass.ts"],"sourcesContent":["import { test } from 'vitest';\n\nimport { defaultEquality, identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type {\n _UseAsyncEach_F,\n _UseEach_F,\n UseAsyncEach_F,\n UseEach_F,\n} from './pass.types';\n\n// #region Sync\nconst useEachCases: _UseEach_F = (\n func,\n transform = identity as any,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest(cases))(\n '%s',\n (_, args, expected, test = defaultEquality) => {\n const value = transform(func(...args));\n return test(value, expected);\n },\n );\n};\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"pass.js","names":[],"sources":["../../../src/vitest-extended/each/pass.ts"],"sourcesContent":["import { test } from 'vitest';\n\nimport { defaultEquality, identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type {\n _UseAsyncEach_F,\n _UseEach_F,\n UseAsyncEach_F,\n UseEach_F,\n} from './pass.types';\n\n// #region Sync\nconst useEachCases: _UseEach_F = (\n func,\n transform = identity as any,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest(cases))(\n '%s',\n (_, args, expected, test = defaultEquality) => {\n const value = transform(func(...args));\n return test(value, expected);\n },\n );\n};\n\n/**\n * Runs parameterized tests with strict equality checks across multiple cases.\n *\n * @param func - Function to test.\n * @param transform - Optional transformer applied to the return value.\n *\n * @returns Function accepting test cases to execute.\n */\nexport const useEach: UseEach_F = (func, transform) => {\n return (...cases) => useEachCases(func, transform, ...cases);\n};\n// #endregion\n\n// #region Async\nconst useEachAsyncCases: _UseAsyncEach_F = (\n f,\n transform = identity as any,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest(cases))(\n '%s',\n async (_, args, expected, test = defaultEquality) => {\n const _value = await f(...args);\n const value = await transform(_value);\n return test(value, expected);\n },\n );\n};\n\n/**\n * Runs asynchronous parameterized tests with strict equality checks across multiple cases.\n *\n * @param func - Async function to test.\n * @param transform - Optional transformer applied to the resolved return value.\n *\n * @returns Function accepting test cases to execute.\n */\nexport const useEachAsync: UseAsyncEach_F = (func, transform) => {\n return (...cases) => useEachAsyncCases(func, transform, ...cases);\n};\n\n// #endregion\n"],"mappings":";;;;AAYA,MAAM,gBACJ,MACA,YAAY,UACZ,GAAG,UACA;CACH,KAAK,WAAW,KAAK,cAAc,KAAK,CAAC,CAAC,CACxC,OACC,GAAG,MAAM,UAAU,OAAO,oBAAoB;EAE7C,OAAO,KADO,UAAU,KAAK,GAAG,IAAI,CACpB,GAAG,QAAQ;CAC7B,CACF;AACF;;;;;;;;;AAUA,MAAa,WAAsB,MAAM,cAAc;CACrD,QAAQ,GAAG,UAAU,aAAa,MAAM,WAAW,GAAG,KAAK;AAC7D;AAIA,MAAM,qBACJ,GACA,YAAY,UACZ,GAAG,UACA;CACH,KAAK,WAAW,KAAK,cAAc,KAAK,CAAC,CAAC,CACxC,MACA,OAAO,GAAG,MAAM,UAAU,OAAO,oBAAoB;EAGnD,OAAO,KAAK,MADQ,UAAU,MADT,EAAE,GAAG,IAAI,CACM,GACjB,QAAQ;CAC7B,CACF;AACF;;;;;;;;;AAUA,MAAa,gBAAgC,MAAM,cAAc;CAC/D,QAAQ,GAAG,UAAU,kBAAkB,MAAM,WAAW,GAAG,KAAK;AAClE"}
|
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
import type { Fn } from '../../utils/bemedev/globals/types';
|
|
2
2
|
import type { ChainedFn, Identity, NextFn, TestArgs } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Runner function signature for synchronous parameterized tests.
|
|
5
|
+
*
|
|
6
|
+
* @template | {@linkcode Fn} `F` - Source function under test.
|
|
7
|
+
* @template | {@linkcode NextFn} `T` - Output transformer type, defaults to {@linkcode Identity}.
|
|
8
|
+
*/
|
|
3
9
|
export type _UseEach_F = <F extends Fn, T extends NextFn<F> = Identity<F>>(f: F, transform?: T, ...cases: TestArgs<ChainedFn<F, T>>) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Higher-order function returning a test runner for synchronous parameterized tests.
|
|
12
|
+
*
|
|
13
|
+
* @template | {@linkcode Fn} `F` - Source function under test.
|
|
14
|
+
* @template | {@linkcode NextFn} `T` - Output transformer type, defaults to {@linkcode Identity}.
|
|
15
|
+
*/
|
|
4
16
|
export type UseEach_F = <F extends Fn, T extends NextFn<F> = Identity<F>>(f: F, transform?: T) => (...cases: TestArgs<ChainedFn<F, T>>) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Runner function signature for asynchronous parameterized tests.
|
|
19
|
+
*
|
|
20
|
+
* @template | {@linkcode Fn} `F` - Source async function under test.
|
|
21
|
+
* @template | {@linkcode NextFn} `T` - Output transformer type, defaults to {@linkcode Identity}.
|
|
22
|
+
*/
|
|
5
23
|
export type _UseAsyncEach_F = <F extends Fn<any, Promise<any>>, T extends NextFn<F> = Identity<F>>(f: F, transform?: T, ...cases: TestArgs<ChainedFn<F, T>>) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Higher-order function returning a test runner for asynchronous parameterized tests.
|
|
26
|
+
*
|
|
27
|
+
* @template | {@linkcode Fn} `F` - Source async function under test.
|
|
28
|
+
* @template | {@linkcode NextFn} `T` - Output transformer type, defaults to {@linkcode Identity}.
|
|
29
|
+
*/
|
|
6
30
|
export type UseAsyncEach_F = <F extends Fn<any, Promise<any>>, T extends NextFn<F> = Identity<F>>(f: F, transform?: T) => (...cases: TestArgs<ChainedFn<F, T>>) => void;
|
|
@@ -2,6 +2,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_utils_sleep = require("../utils/sleep.cjs");
|
|
3
3
|
//#region src/vitest-extended/fakeWaiter.ts
|
|
4
4
|
const buildInvite = (index = 0, ms = 0, times = 1) => `#${index} Wait for ${ms}ms times ${times}`;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a timer-advancing waiter function that supports both fake timers and real delays.
|
|
7
|
+
*
|
|
8
|
+
* @param vi - Vitest utilities instance of type {@linkcode VitestUtils}.
|
|
9
|
+
*
|
|
10
|
+
* @returns An asynchronous waiting function.
|
|
11
|
+
*/
|
|
5
12
|
const createFakeWaiter = (vi) => {
|
|
6
13
|
return async (ms = 0, times = 1) => {
|
|
7
14
|
const check = vi.isFakeTimers();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fakeWaiter.cjs","names":["sleep"],"sources":["../../src/vitest-extended/fakeWaiter.ts"],"sourcesContent":["import type { VitestUtils } from 'vitest';\n\nimport { sleep } from '#utils/sleep';\n\nexport type FakeWaiter1_F = (\n vi: VitestUtils,\n) => (ms?: number, times?: number) => Promise<void>;\n\nexport type FakeWaiter2_F = (\n vi: VitestUtils,\n ms?: number,\n) => (index: number, times?: number) => [string, () => Promise<void>];\n\nexport type FakeWaiter3_F = (\n vi: VitestUtils,\n) => (\n index: number,\n ms?: number,\n times?: number,\n) => [string, () => Promise<void>];\n\nexport type FakeWaiter = FakeWaiter1_F & {\n withDefaultDelay: FakeWaiter2_F;\n all: FakeWaiter3_F;\n};\n\nconst buildInvite = (index = 0, ms = 0, times = 1) =>\n `#${index} Wait for ${ms}ms times ${times}`;\n\nexport const createFakeWaiter: FakeWaiter = vi => {\n return async (ms = 0, times = 1) => {\n const check = vi.isFakeTimers();\n for (let i = 0; i < times; i++) {\n if (check) await vi.advanceTimersByTimeAsync(ms);\n else await sleep(ms);\n }\n };\n};\n\ncreateFakeWaiter.withDefaultDelay = (vi, ms = 0) => {\n return (index, times = 1) => {\n const invite = buildInvite(index, ms, times);\n const fn = () => createFakeWaiter(vi)(ms, times);\n return [invite, fn] as const;\n };\n};\n\ncreateFakeWaiter.all = vi => {\n return (index, ms = 0, times = 1) => {\n const invite = buildInvite(index, ms, times);\n const fn = () => createFakeWaiter(vi)(ms, times);\n return [invite, fn] as const;\n };\n};\n"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"fakeWaiter.cjs","names":["sleep"],"sources":["../../src/vitest-extended/fakeWaiter.ts"],"sourcesContent":["import type { VitestUtils } from 'vitest';\n\nimport { sleep } from '#utils/sleep';\n\n/**\n * Function creating a waiter using Vitest utilities.\n *\n * @param vi - Vitest utilities object of type {@linkcode VitestUtils}.\n *\n * @returns An async function accepting delay `ms` and repeat `times`.\n */\nexport type FakeWaiter1_F = (\n vi: VitestUtils,\n) => (ms?: number, times?: number) => Promise<void>;\n\n/**\n * Function creating a waiter with a fixed default delay.\n *\n * @param vi - Vitest utilities object of type {@linkcode VitestUtils}.\n * @param ms - Delay in milliseconds.\n *\n * @returns A function taking index and times that returns a test invite and execution callback tuple.\n */\nexport type FakeWaiter2_F = (\n vi: VitestUtils,\n ms?: number,\n) => (index: number, times?: number) => [string, () => Promise<void>];\n\n/**\n * Function creating a waiter accepting index, delay, and repeat count.\n *\n * @param vi - Vitest utilities object of type {@linkcode VitestUtils}.\n *\n * @returns A function taking index, ms, and times that returns a test invite and execution callback tuple.\n */\nexport type FakeWaiter3_F = (\n vi: VitestUtils,\n) => (\n index: number,\n ms?: number,\n times?: number,\n) => [string, () => Promise<void>];\n\n/**\n * Composite fake waiter function with helper properties.\n */\nexport type FakeWaiter = FakeWaiter1_F & {\n withDefaultDelay: FakeWaiter2_F;\n all: FakeWaiter3_F;\n};\n\nconst buildInvite = (index = 0, ms = 0, times = 1) =>\n `#${index} Wait for ${ms}ms times ${times}`;\n\n/**\n * Creates a timer-advancing waiter function that supports both fake timers and real delays.\n *\n * @param vi - Vitest utilities instance of type {@linkcode VitestUtils}.\n *\n * @returns An asynchronous waiting function.\n */\nexport const createFakeWaiter: FakeWaiter = vi => {\n return async (ms = 0, times = 1) => {\n const check = vi.isFakeTimers();\n for (let i = 0; i < times; i++) {\n if (check) await vi.advanceTimersByTimeAsync(ms);\n else await sleep(ms);\n }\n };\n};\n\ncreateFakeWaiter.withDefaultDelay = (vi, ms = 0) => {\n return (index, times = 1) => {\n const invite = buildInvite(index, ms, times);\n const fn = () => createFakeWaiter(vi)(ms, times);\n return [invite, fn] as const;\n };\n};\n\ncreateFakeWaiter.all = vi => {\n return (index, ms = 0, times = 1) => {\n const invite = buildInvite(index, ms, times);\n const fn = () => createFakeWaiter(vi)(ms, times);\n return [invite, fn] as const;\n };\n};\n"],"mappings":";;;AAmDA,MAAM,eAAe,QAAQ,GAAG,KAAK,GAAG,QAAQ,MAC9C,IAAI,MAAM,YAAY,GAAG,WAAW;;;;;;;;AAStC,MAAa,oBAA+B,OAAM;CAChD,OAAO,OAAO,KAAK,GAAG,QAAQ,MAAM;EAClC,MAAM,QAAQ,GAAG,aAAa;EAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KACzB,IAAI,OAAO,MAAM,GAAG,yBAAyB,EAAE;OAC1C,MAAMA,oBAAAA,MAAM,EAAE;CAEvB;AACF;AAEA,iBAAiB,oBAAoB,IAAI,KAAK,MAAM;CAClD,QAAQ,OAAO,QAAQ,MAAM;EAC3B,MAAM,SAAS,YAAY,OAAO,IAAI,KAAK;EAC3C,MAAM,WAAW,iBAAiB,EAAE,CAAC,CAAC,IAAI,KAAK;EAC/C,OAAO,CAAC,QAAQ,EAAE;CACpB;AACF;AAEA,iBAAiB,OAAM,OAAM;CAC3B,QAAQ,OAAO,KAAK,GAAG,QAAQ,MAAM;EACnC,MAAM,SAAS,YAAY,OAAO,IAAI,KAAK;EAC3C,MAAM,WAAW,iBAAiB,EAAE,CAAC,CAAC,IAAI,KAAK;EAC/C,OAAO,CAAC,QAAQ,EAAE;CACpB;AACF"}
|
|
@@ -1,9 +1,41 @@
|
|
|
1
1
|
import type { VitestUtils } from 'vitest';
|
|
2
|
+
/**
|
|
3
|
+
* Function creating a waiter using Vitest utilities.
|
|
4
|
+
*
|
|
5
|
+
* @param vi - Vitest utilities object of type {@linkcode VitestUtils}.
|
|
6
|
+
*
|
|
7
|
+
* @returns An async function accepting delay `ms` and repeat `times`.
|
|
8
|
+
*/
|
|
2
9
|
export type FakeWaiter1_F = (vi: VitestUtils) => (ms?: number, times?: number) => Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Function creating a waiter with a fixed default delay.
|
|
12
|
+
*
|
|
13
|
+
* @param vi - Vitest utilities object of type {@linkcode VitestUtils}.
|
|
14
|
+
* @param ms - Delay in milliseconds.
|
|
15
|
+
*
|
|
16
|
+
* @returns A function taking index and times that returns a test invite and execution callback tuple.
|
|
17
|
+
*/
|
|
3
18
|
export type FakeWaiter2_F = (vi: VitestUtils, ms?: number) => (index: number, times?: number) => [string, () => Promise<void>];
|
|
19
|
+
/**
|
|
20
|
+
* Function creating a waiter accepting index, delay, and repeat count.
|
|
21
|
+
*
|
|
22
|
+
* @param vi - Vitest utilities object of type {@linkcode VitestUtils}.
|
|
23
|
+
*
|
|
24
|
+
* @returns A function taking index, ms, and times that returns a test invite and execution callback tuple.
|
|
25
|
+
*/
|
|
4
26
|
export type FakeWaiter3_F = (vi: VitestUtils) => (index: number, ms?: number, times?: number) => [string, () => Promise<void>];
|
|
27
|
+
/**
|
|
28
|
+
* Composite fake waiter function with helper properties.
|
|
29
|
+
*/
|
|
5
30
|
export type FakeWaiter = FakeWaiter1_F & {
|
|
6
31
|
withDefaultDelay: FakeWaiter2_F;
|
|
7
32
|
all: FakeWaiter3_F;
|
|
8
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Creates a timer-advancing waiter function that supports both fake timers and real delays.
|
|
36
|
+
*
|
|
37
|
+
* @param vi - Vitest utilities instance of type {@linkcode VitestUtils}.
|
|
38
|
+
*
|
|
39
|
+
* @returns An asynchronous waiting function.
|
|
40
|
+
*/
|
|
9
41
|
export declare const createFakeWaiter: FakeWaiter;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { sleep } from "../utils/sleep.js";
|
|
2
2
|
//#region src/vitest-extended/fakeWaiter.ts
|
|
3
3
|
const buildInvite = (index = 0, ms = 0, times = 1) => `#${index} Wait for ${ms}ms times ${times}`;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a timer-advancing waiter function that supports both fake timers and real delays.
|
|
6
|
+
*
|
|
7
|
+
* @param vi - Vitest utilities instance of type {@linkcode VitestUtils}.
|
|
8
|
+
*
|
|
9
|
+
* @returns An asynchronous waiting function.
|
|
10
|
+
*/
|
|
4
11
|
const createFakeWaiter = (vi) => {
|
|
5
12
|
return async (ms = 0, times = 1) => {
|
|
6
13
|
const check = vi.isFakeTimers();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fakeWaiter.js","names":[],"sources":["../../src/vitest-extended/fakeWaiter.ts"],"sourcesContent":["import type { VitestUtils } from 'vitest';\n\nimport { sleep } from '#utils/sleep';\n\nexport type FakeWaiter1_F = (\n vi: VitestUtils,\n) => (ms?: number, times?: number) => Promise<void>;\n\nexport type FakeWaiter2_F = (\n vi: VitestUtils,\n ms?: number,\n) => (index: number, times?: number) => [string, () => Promise<void>];\n\nexport type FakeWaiter3_F = (\n vi: VitestUtils,\n) => (\n index: number,\n ms?: number,\n times?: number,\n) => [string, () => Promise<void>];\n\nexport type FakeWaiter = FakeWaiter1_F & {\n withDefaultDelay: FakeWaiter2_F;\n all: FakeWaiter3_F;\n};\n\nconst buildInvite = (index = 0, ms = 0, times = 1) =>\n `#${index} Wait for ${ms}ms times ${times}`;\n\nexport const createFakeWaiter: FakeWaiter = vi => {\n return async (ms = 0, times = 1) => {\n const check = vi.isFakeTimers();\n for (let i = 0; i < times; i++) {\n if (check) await vi.advanceTimersByTimeAsync(ms);\n else await sleep(ms);\n }\n };\n};\n\ncreateFakeWaiter.withDefaultDelay = (vi, ms = 0) => {\n return (index, times = 1) => {\n const invite = buildInvite(index, ms, times);\n const fn = () => createFakeWaiter(vi)(ms, times);\n return [invite, fn] as const;\n };\n};\n\ncreateFakeWaiter.all = vi => {\n return (index, ms = 0, times = 1) => {\n const invite = buildInvite(index, ms, times);\n const fn = () => createFakeWaiter(vi)(ms, times);\n return [invite, fn] as const;\n };\n};\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"fakeWaiter.js","names":[],"sources":["../../src/vitest-extended/fakeWaiter.ts"],"sourcesContent":["import type { VitestUtils } from 'vitest';\n\nimport { sleep } from '#utils/sleep';\n\n/**\n * Function creating a waiter using Vitest utilities.\n *\n * @param vi - Vitest utilities object of type {@linkcode VitestUtils}.\n *\n * @returns An async function accepting delay `ms` and repeat `times`.\n */\nexport type FakeWaiter1_F = (\n vi: VitestUtils,\n) => (ms?: number, times?: number) => Promise<void>;\n\n/**\n * Function creating a waiter with a fixed default delay.\n *\n * @param vi - Vitest utilities object of type {@linkcode VitestUtils}.\n * @param ms - Delay in milliseconds.\n *\n * @returns A function taking index and times that returns a test invite and execution callback tuple.\n */\nexport type FakeWaiter2_F = (\n vi: VitestUtils,\n ms?: number,\n) => (index: number, times?: number) => [string, () => Promise<void>];\n\n/**\n * Function creating a waiter accepting index, delay, and repeat count.\n *\n * @param vi - Vitest utilities object of type {@linkcode VitestUtils}.\n *\n * @returns A function taking index, ms, and times that returns a test invite and execution callback tuple.\n */\nexport type FakeWaiter3_F = (\n vi: VitestUtils,\n) => (\n index: number,\n ms?: number,\n times?: number,\n) => [string, () => Promise<void>];\n\n/**\n * Composite fake waiter function with helper properties.\n */\nexport type FakeWaiter = FakeWaiter1_F & {\n withDefaultDelay: FakeWaiter2_F;\n all: FakeWaiter3_F;\n};\n\nconst buildInvite = (index = 0, ms = 0, times = 1) =>\n `#${index} Wait for ${ms}ms times ${times}`;\n\n/**\n * Creates a timer-advancing waiter function that supports both fake timers and real delays.\n *\n * @param vi - Vitest utilities instance of type {@linkcode VitestUtils}.\n *\n * @returns An asynchronous waiting function.\n */\nexport const createFakeWaiter: FakeWaiter = vi => {\n return async (ms = 0, times = 1) => {\n const check = vi.isFakeTimers();\n for (let i = 0; i < times; i++) {\n if (check) await vi.advanceTimersByTimeAsync(ms);\n else await sleep(ms);\n }\n };\n};\n\ncreateFakeWaiter.withDefaultDelay = (vi, ms = 0) => {\n return (index, times = 1) => {\n const invite = buildInvite(index, ms, times);\n const fn = () => createFakeWaiter(vi)(ms, times);\n return [invite, fn] as const;\n };\n};\n\ncreateFakeWaiter.all = vi => {\n return (index, ms = 0, times = 1) => {\n const invite = buildInvite(index, ms, times);\n const fn = () => createFakeWaiter(vi)(ms, times);\n return [invite, fn] as const;\n };\n};\n"],"mappings":";;AAmDA,MAAM,eAAe,QAAQ,GAAG,KAAK,GAAG,QAAQ,MAC9C,IAAI,MAAM,YAAY,GAAG,WAAW;;;;;;;;AAStC,MAAa,oBAA+B,OAAM;CAChD,OAAO,OAAO,KAAK,GAAG,QAAQ,MAAM;EAClC,MAAM,QAAQ,GAAG,aAAa;EAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KACzB,IAAI,OAAO,MAAM,GAAG,yBAAyB,EAAE;OAC1C,MAAM,MAAM,EAAE;CAEvB;AACF;AAEA,iBAAiB,oBAAoB,IAAI,KAAK,MAAM;CAClD,QAAQ,OAAO,QAAQ,MAAM;EAC3B,MAAM,SAAS,YAAY,OAAO,IAAI,KAAK;EAC3C,MAAM,WAAW,iBAAiB,EAAE,CAAC,CAAC,IAAI,KAAK;EAC/C,OAAO,CAAC,QAAQ,EAAE;CACpB;AACF;AAEA,iBAAiB,OAAM,OAAM;CAC3B,QAAQ,OAAO,KAAK,GAAG,QAAQ,MAAM;EACnC,MAAM,SAAS,YAAY,OAAO,IAAI,KAAK;EAC3C,MAAM,WAAW,iBAAiB,EAAE,CAAC,CAAC,IAAI,KAAK;EAC/C,OAAO,CAAC,QAAQ,EAAE;CACpB;AACF"}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/vitest-extended/fixtures/coverage.ts
|
|
3
|
+
/**
|
|
4
|
+
* Test fixture constant.
|
|
5
|
+
*/
|
|
3
6
|
const expected = "done!";
|
|
7
|
+
/**
|
|
8
|
+
* Test fixture returning a constant string.
|
|
9
|
+
*
|
|
10
|
+
* @returns Expected constant string.
|
|
11
|
+
*/
|
|
4
12
|
const noArgs = () => expected;
|
|
13
|
+
/**
|
|
14
|
+
* Test fixture adding multiple numbers together.
|
|
15
|
+
*/
|
|
5
16
|
const addMany = (...numbers) => numbers.reduce((acc, value) => acc + value, 0);
|
|
6
17
|
//#endregion
|
|
7
18
|
exports.addMany = addMany;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coverage.cjs","names":[],"sources":["../../../src/vitest-extended/fixtures/coverage.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"coverage.cjs","names":[],"sources":["../../../src/vitest-extended/fixtures/coverage.ts"],"sourcesContent":["/**\n * Test fixture constant.\n */\nexport const expected = 'done!';\n\n/**\n * Test fixture returning a constant string.\n *\n * @returns Expected constant string.\n */\nexport const noArgs = () => expected;\n\ntype AddMany = (...params: number[]) => number;\n\n/**\n * Test fixture adding multiple numbers together.\n */\nexport const addMany: AddMany = (...numbers) =>\n numbers.reduce((acc, value) => acc + value, 0);\n"],"mappings":";;;;;AAGA,MAAa,WAAW;;;;;;AAOxB,MAAa,eAAe;;;;AAO5B,MAAa,WAAoB,GAAG,YAClC,QAAQ,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC"}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
//#region src/vitest-extended/fixtures/coverage.ts
|
|
2
|
+
/**
|
|
3
|
+
* Test fixture constant.
|
|
4
|
+
*/
|
|
2
5
|
const expected = "done!";
|
|
6
|
+
/**
|
|
7
|
+
* Test fixture returning a constant string.
|
|
8
|
+
*
|
|
9
|
+
* @returns Expected constant string.
|
|
10
|
+
*/
|
|
3
11
|
const noArgs = () => expected;
|
|
12
|
+
/**
|
|
13
|
+
* Test fixture adding multiple numbers together.
|
|
14
|
+
*/
|
|
4
15
|
const addMany = (...numbers) => numbers.reduce((acc, value) => acc + value, 0);
|
|
5
16
|
//#endregion
|
|
6
17
|
export { addMany, expected, noArgs };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coverage.js","names":[],"sources":["../../../src/vitest-extended/fixtures/coverage.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"coverage.js","names":[],"sources":["../../../src/vitest-extended/fixtures/coverage.ts"],"sourcesContent":["/**\n * Test fixture constant.\n */\nexport const expected = 'done!';\n\n/**\n * Test fixture returning a constant string.\n *\n * @returns Expected constant string.\n */\nexport const noArgs = () => expected;\n\ntype AddMany = (...params: number[]) => number;\n\n/**\n * Test fixture adding multiple numbers together.\n */\nexport const addMany: AddMany = (...numbers) =>\n numbers.reduce((acc, value) => acc + value, 0);\n"],"mappings":";;;;AAGA,MAAa,WAAW;;;;;;AAOxB,MAAa,eAAe;;;;AAO5B,MAAa,WAAoB,GAAG,YAClC,QAAQ,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC"}
|