@voidzero-dev/vite-plus-test 0.1.8 → 0.1.10
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/LICENSE.md +181 -1
- package/dist/@vitest/browser/client/.vite/manifest.json +6 -6
- package/dist/@vitest/browser/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.svg +49 -4
- package/dist/@vitest/browser/client/__vitest__/index.html +2 -2
- package/dist/@vitest/browser/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/@vitest/browser/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
- package/dist/@vitest/browser/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/@vitest/browser/client/favicon.svg +49 -4
- package/dist/@vitest/browser/client/orchestrator.html +2 -2
- package/dist/@vitest/browser/client/tester/tester.html +2 -2
- package/dist/@vitest/browser/client.js +20 -13
- package/dist/@vitest/browser/context.d.ts +160 -10
- package/dist/@vitest/browser/context.js +108 -22
- package/dist/@vitest/browser/expect-element.js +23 -28
- package/dist/@vitest/browser/index-5Pe7X7sp.js +7 -0
- package/dist/@vitest/browser/index.d.ts +20 -2
- package/dist/@vitest/browser/index.js +5706 -159
- package/dist/@vitest/browser/locators.d.ts +14 -3
- package/dist/@vitest/browser/locators.js +1 -1
- package/dist/@vitest/browser-playwright/index.d.ts +22 -5
- package/dist/@vitest/browser-playwright/index.js +169 -61
- package/dist/@vitest/browser-preview/index.d.ts +14 -1
- package/dist/@vitest/browser-preview/locators.js +31 -18
- package/dist/@vitest/browser-webdriverio/index.d.ts +17 -3
- package/dist/@vitest/browser-webdriverio/index.js +22 -2
- package/dist/@vitest/browser-webdriverio/locators.js +84 -7
- package/dist/@vitest/expect/index.d.ts +172 -54
- package/dist/@vitest/expect/index.js +124 -67
- package/dist/@vitest/mocker/auto-register.js +1 -0
- package/dist/@vitest/mocker/automock.d.ts +1 -0
- package/dist/@vitest/mocker/automock.js +5 -0
- package/dist/@vitest/mocker/browser.d.ts +4 -4
- package/dist/@vitest/mocker/browser.js +1 -0
- package/dist/@vitest/mocker/chunk-automock.js +182 -14
- package/dist/@vitest/mocker/chunk-helpers.js +44 -0
- package/dist/@vitest/mocker/chunk-hoistMocks.js +659 -0
- package/dist/@vitest/mocker/chunk-mocker.js +41 -30
- package/dist/@vitest/mocker/chunk-registry.js +21 -7
- package/dist/@vitest/mocker/chunk-utils.js +18 -7
- package/dist/@vitest/mocker/hoistMocks.d-w2ILr1dG.d.ts +739 -0
- package/dist/@vitest/mocker/{index.d-C-sLYZi-.d.ts → index.d-B41z0AuW.d.ts} +1 -1
- package/dist/@vitest/mocker/index.d.ts +2 -2
- package/dist/@vitest/mocker/index.js +18 -3
- package/dist/@vitest/mocker/{mocker.d-TnKRhz7N.d.ts → mocker.d-QEntlm6J.d.ts} +10 -5
- package/dist/@vitest/mocker/node.d.ts +5 -734
- package/dist/@vitest/mocker/node.js +29 -587
- package/dist/@vitest/mocker/redirect.js +4 -4
- package/dist/@vitest/mocker/register.d.ts +3 -3
- package/dist/@vitest/mocker/register.js +1 -0
- package/dist/@vitest/mocker/transforms.d.ts +6 -0
- package/dist/@vitest/mocker/transforms.js +8 -0
- package/dist/@vitest/mocker/{types.d-B8CCKmHt.d.ts → types.d-BjI5eAwu.d.ts} +23 -7
- package/dist/@vitest/pretty-format/index.d.ts +11 -1
- package/dist/@vitest/pretty-format/index.js +33 -4
- package/dist/@vitest/runner/chunk-tasks.js +305 -37
- package/dist/@vitest/runner/index.d.ts +5 -6
- package/dist/@vitest/runner/index.js +1146 -455
- package/dist/@vitest/runner/{tasks.d-C7UxawJ9.d.ts → tasks.d-D2GKpdwQ.d.ts} +726 -55
- package/dist/@vitest/runner/types.d.ts +2 -182
- package/dist/@vitest/runner/utils.d.ts +16 -8
- package/dist/@vitest/runner/utils.js +1 -1
- package/dist/@vitest/snapshot/{environment.d-DHdQ1Csl.d.ts → environment.d-DOJxxZV9.d.ts} +2 -7
- package/dist/@vitest/snapshot/environment.d.ts +2 -1
- package/dist/@vitest/snapshot/environment.js +1 -1
- package/dist/@vitest/snapshot/index.d.ts +4 -3
- package/dist/@vitest/snapshot/index.js +21 -550
- package/dist/@vitest/snapshot/manager.d.ts +3 -2
- package/dist/@vitest/snapshot/manager.js +1 -1
- package/dist/@vitest/snapshot/{rawSnapshot.d-lFsMJFUd.d.ts → rawSnapshot.d-U2kJUxDr.d.ts} +1 -1
- package/dist/@vitest/spy/index.d.ts +34 -4
- package/dist/@vitest/spy/index.js +69 -19
- package/dist/@vitest/utils/diff.js +11 -9
- package/dist/@vitest/utils/display.d.ts +2 -1
- package/dist/@vitest/utils/display.js +38 -5
- package/dist/@vitest/utils/error.d.ts +2 -1
- package/dist/@vitest/utils/error.js +1 -2
- package/dist/@vitest/utils/helpers.d.ts +4 -1
- package/dist/@vitest/utils/helpers.js +43 -1
- package/dist/@vitest/utils/resolver.js +1 -2
- package/dist/@vitest/utils/serialize.js +6 -6
- package/dist/@vitest/utils/source-map/node.d.ts +6 -0
- package/dist/@vitest/utils/source-map/node.js +23 -0
- package/dist/@vitest/utils/source-map.js +15 -5
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +2 -2
- package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
- package/dist/chunks/{base.CJ0Y4ePK.js → base.DM0-RqVb.js} +54 -16
- package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.D0SlKNbZ.js} +1 -1
- package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.X3SXoOCV.d.ts} +4 -1
- package/dist/chunks/{cac.DVeoLl0M.js → cac.CWGDZnXT.js} +979 -20
- package/dist/chunks/{cli-api.B7PN_QUv.js → cli-api.DuT9iuvY.js} +8764 -7898
- package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.EJLVE3es.d.ts} +30 -15
- package/dist/chunks/{console.Cf-YriPC.js → console.3WNpx0tS.js} +3 -2
- package/dist/chunks/{constants.D_Q9UYh-.js → constants.CPYnjOGj.js} +4 -2
- package/dist/chunks/coverage.Bri33R1t.js +1050 -0
- package/dist/chunks/{creator.DAmOKTvJ.js → creator.DgVhQm5q.js} +35 -4
- package/dist/chunks/{defaults.BOqNVLsY.js → defaults.CdU2lD-q.js} +4 -3
- package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.x-ILCfAE.d.ts} +1 -2
- package/dist/chunks/{globals.DOayXfHP.js → globals.BXNGLnTL.js} +11 -10
- package/dist/chunks/{coverage.AVPTjMgw.js → index.BCY_7LL2.js} +5 -959
- package/dist/chunks/{index.C5r1PdPD.js → index.CEzQDJGb.js} +1 -1
- package/dist/chunks/{index.D3XRDfWc.js → index.CMESou6r.js} +26 -1
- package/dist/chunks/{index.6Qv1eEA6.js → index.DGNSnENe.js} +95 -9
- package/dist/chunks/{index.M8mOzt4Y.js → index.DXMFO5MJ.js} +3279 -2914
- package/dist/chunks/{index.Z5E_ObnR.js → index.DlDSLQD3.js} +7 -3
- package/dist/chunks/{index.CyBMJtT7.js → index.EY6TCHpo.js} +10 -8
- package/dist/chunks/{index.D4KonVSU.js → index.og1WyBLx.js} +18 -3
- package/dist/chunks/{init-forks._y3TW739.js → init-forks.DeArv0jT.js} +1 -1
- package/dist/chunks/{init-threads.DBO2kn-p.js → init-threads.-2OUl4Nn.js} +1 -1
- package/dist/chunks/{init.B6MLFIaN.js → init.DICorXCo.js} +52 -13
- package/dist/chunks/native.DPzPHdi5.js +148 -0
- package/dist/chunks/nativeModuleMocker.DndvSdL6.js +206 -0
- package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
- package/dist/chunks/{node.Ce0vMQM7.js → node.COQbm6gK.js} +1 -1
- package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.BuW-flqo.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.DVUYHHhe.d.ts} +328 -79
- package/dist/chunks/rpc.MzXet3jl.js +144 -0
- package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.BFMWpdph.d.ts} +10 -2
- package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.B41N_kPE.js} +3 -3
- package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startVitestModuleRunner.C3ZR-4J3.js} +265 -405
- package/dist/chunks/{suite.d.BJWk38HB.d.ts → suite.d.udJtyAgw.d.ts} +1 -1
- package/dist/chunks/{vi.2VT5v0um.js → test.CTcmp4Su.js} +538 -181
- package/dist/chunks/{utils.DvEY5TfP.js → utils.BX5Fg8C4.js} +8 -1
- package/dist/chunks/{vm.D3epNOPZ.js → vm.Dh2rTtmP.js} +48 -8
- package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.B84sVRy0.d.ts} +2 -2
- package/dist/cli.js +6 -5
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/favicon.svg +49 -4
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
- package/dist/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/client/favicon.svg +49 -4
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -2
- package/dist/client.js +20 -13
- package/dist/config.cjs +3 -2
- package/dist/config.d.ts +13 -12
- package/dist/config.js +2 -2
- package/dist/context.js +108 -22
- package/dist/coverage.d.ts +12 -8
- package/dist/coverage.js +8 -5
- package/dist/environments.js +3 -1
- package/dist/expect-element.js +23 -23
- package/dist/index-5Pe7X7sp.js +7 -0
- package/dist/index.d.ts +66 -27
- package/dist/index.js +10 -9
- package/dist/locators.d.ts +14 -3
- package/dist/locators.js +1 -1
- package/dist/module-evaluator.d.ts +11 -1
- package/dist/module-evaluator.js +43 -26
- package/dist/node.d.ts +28 -14
- package/dist/node.js +42 -40
- package/dist/nodejs-worker-loader.js +41 -0
- package/dist/plugins/mocker-transforms.mjs +2 -0
- package/dist/plugins/utils-source-map-node.mjs +2 -0
- package/dist/reporters.d.ts +8 -8
- package/dist/reporters.js +7 -5
- package/dist/runners.d.ts +24 -5
- package/dist/runners.js +6 -6
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +35 -0
- package/dist/snapshot.js +4 -2
- package/dist/suite.d.ts +1 -1
- package/dist/suite.js +4 -2
- package/dist/vendor/blazediff_core.d.mts +1 -0
- package/dist/vendor/blazediff_core.mjs +117 -0
- package/dist/vendor/chai.mjs +4 -249
- package/dist/vendor/convert-source-map.d.mts +1 -0
- package/dist/vendor/convert-source-map.mjs +150 -0
- package/dist/vendor/expect-type.d.mts +14 -7
- package/dist/vendor/expect-type.mjs +5 -5
- package/dist/vendor/std-env.d.mts +131 -40
- package/dist/vendor/std-env.mjs +114 -117
- package/dist/worker.d.ts +6 -6
- package/dist/worker.js +27 -21
- package/dist/workers/forks.js +23 -17
- package/dist/workers/runVmTests.js +18 -16
- package/dist/workers/threads.js +23 -17
- package/dist/workers/vmForks.js +15 -12
- package/dist/workers/vmThreads.js +15 -12
- package/globals.d.ts +2 -0
- package/package.json +36 -27
- package/suppress-warnings.cjs +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/@vitest/browser/index-D6m36C6U.js +0 -11
- package/dist/@vitest/utils/chunk-_commonjsHelpers.js +0 -5
- package/dist/@vitest/utils/highlight.d.ts +0 -9
- package/dist/@vitest/utils/highlight.js +0 -538
- package/dist/chunks/date.Bq6ZW5rf.js +0 -73
- package/dist/chunks/rpc.BoxB0q7B.js +0 -76
- package/dist/chunks/test.B8ej_ZHS.js +0 -254
- package/dist/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/index-D6m36C6U.js +0 -6
- package/dist/mocker.d.ts +0 -1
- package/dist/mocker.js +0 -1
- package/dist/module-runner.js +0 -17
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { toArray } from '../@vitest/utils/helpers.js';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { normalize } from '../vendor/pathe.mjs';
|
|
4
|
-
import c from '../vendor/tinyrainbow.mjs';
|
|
5
|
-
import {
|
|
6
|
-
import { R as ReportersMap } from './index.
|
|
4
|
+
import c$2 from '../vendor/tinyrainbow.mjs';
|
|
5
|
+
import { b as defaultPort, d as defaultBrowserPort } from './constants.CPYnjOGj.js';
|
|
6
|
+
import { R as ReportersMap } from './index.DXMFO5MJ.js';
|
|
7
|
+
import assert from 'node:assert';
|
|
7
8
|
|
|
8
9
|
function toArr(any) {
|
|
9
10
|
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
@@ -619,7 +620,7 @@ class CAC extends EventEmitter {
|
|
|
619
620
|
|
|
620
621
|
const cac = (name = "") => new CAC(name);
|
|
621
622
|
|
|
622
|
-
var version = process.env.VITE_PLUS_VERSION || "4.0
|
|
623
|
+
var version = process.env.VITE_PLUS_VERSION || "4.1.0";
|
|
623
624
|
|
|
624
625
|
const apiConfig = (port) => ({
|
|
625
626
|
port: {
|
|
@@ -631,6 +632,8 @@ const apiConfig = (port) => ({
|
|
|
631
632
|
argument: "[host]"
|
|
632
633
|
},
|
|
633
634
|
strictPort: { description: "Set to true to exit if port is already in use, instead of automatically trying the next available port" },
|
|
635
|
+
allowExec: { description: "Allow API to execute code. (Be careful when enabling this option in untrusted environments)" },
|
|
636
|
+
allowWrite: { description: "Allow API to edit files. (Be careful when enabling this option in untrusted environments)" },
|
|
634
637
|
middlewareMode: null
|
|
635
638
|
});
|
|
636
639
|
function watermarkTransform(value) {
|
|
@@ -656,7 +659,8 @@ const cliOptionsConfig = {
|
|
|
656
659
|
},
|
|
657
660
|
update: {
|
|
658
661
|
shorthand: "u",
|
|
659
|
-
description: "Update snapshot"
|
|
662
|
+
description: "Update snapshot (accepts boolean, \"new\", \"all\" or \"none\")",
|
|
663
|
+
argument: "[type]"
|
|
660
664
|
},
|
|
661
665
|
watch: {
|
|
662
666
|
shorthand: "w",
|
|
@@ -677,7 +681,11 @@ const cliOptionsConfig = {
|
|
|
677
681
|
api: {
|
|
678
682
|
argument: "[port]",
|
|
679
683
|
description: `Specify server port. Note if the port is already being used, Vite will automatically try the next available port so this may not be the actual port the server ends up listening on. If true will be set to ${defaultPort}`,
|
|
680
|
-
subcommands: apiConfig(defaultPort)
|
|
684
|
+
subcommands: apiConfig(defaultPort),
|
|
685
|
+
transform(portOrOptions) {
|
|
686
|
+
if (typeof portOrOptions === "number") return { port: portOrOptions };
|
|
687
|
+
return portOrOptions;
|
|
688
|
+
}
|
|
681
689
|
},
|
|
682
690
|
silent: {
|
|
683
691
|
description: "Silent console output from tests. Use `'passed-only'` to see logs from failing tests only.",
|
|
@@ -730,7 +738,7 @@ const cliOptionsConfig = {
|
|
|
730
738
|
normalize: true
|
|
731
739
|
},
|
|
732
740
|
reporter: {
|
|
733
|
-
description: "Coverage reporters to use. Visit [`coverage.reporter`](https://vitest.dev/config
|
|
741
|
+
description: "Coverage reporters to use. Visit [`coverage.reporter`](https://vitest.dev/config/coverage#coverage-reporter) for more information (default: `[\"text\", \"html\", \"clover\", \"json\"]`)",
|
|
734
742
|
argument: "<name>",
|
|
735
743
|
subcommands: null,
|
|
736
744
|
array: true
|
|
@@ -811,6 +819,15 @@ const cliOptionsConfig = {
|
|
|
811
819
|
transform: watermarkTransform
|
|
812
820
|
}
|
|
813
821
|
}
|
|
822
|
+
},
|
|
823
|
+
changed: {
|
|
824
|
+
description: "Collect coverage only for files changed since a specified commit or branch (e.g., `origin/main` or `HEAD~1`). Inherits value from `--changed` by default.",
|
|
825
|
+
argument: "<commit/branch>",
|
|
826
|
+
transform(value) {
|
|
827
|
+
if (value === "true" || value === "yes" || value === true) return true;
|
|
828
|
+
if (value === "false" || value === "no" || value === false) return false;
|
|
829
|
+
return value;
|
|
830
|
+
}
|
|
814
831
|
}
|
|
815
832
|
}
|
|
816
833
|
},
|
|
@@ -845,6 +862,10 @@ const cliOptionsConfig = {
|
|
|
845
862
|
},
|
|
846
863
|
isolate: { description: "Run every browser test file in isolation. To disable isolation, use `--browser.isolate=false` (default: `true`)" },
|
|
847
864
|
ui: { description: "Show Vitest UI when running tests (default: `!process.env.CI`)" },
|
|
865
|
+
detailsPanelPosition: {
|
|
866
|
+
description: "Default position for the details panel in browser mode. Either `right` (horizontal split) or `bottom` (vertical split) (default: `right`)",
|
|
867
|
+
argument: "<position>"
|
|
868
|
+
},
|
|
848
869
|
fileParallelism: { description: "Should browser test files run in parallel. Use `--browser.fileParallelism=false` to disable (default: `true`)" },
|
|
849
870
|
connectTimeout: {
|
|
850
871
|
description: "If connection to the browser takes longer, the test suite will fail (default: `60_000`)",
|
|
@@ -897,6 +918,7 @@ const cliOptionsConfig = {
|
|
|
897
918
|
},
|
|
898
919
|
passWithNoTests: { description: "Pass when no tests are found" },
|
|
899
920
|
logHeapUsage: { description: "Show the size of heap for each test when running in node" },
|
|
921
|
+
detectAsyncLeaks: { description: "Detect asynchronous resources leaking from the test file (default: `false`)" },
|
|
900
922
|
allowOnly: { description: "Allow tests and suites that are marked as only (default: `!process.env.CI`)" },
|
|
901
923
|
dangerouslyIgnoreUnhandledErrors: { description: "Ignore any unhandled errors that occur" },
|
|
902
924
|
shard: {
|
|
@@ -925,7 +947,7 @@ const cliOptionsConfig = {
|
|
|
925
947
|
argument: "<seed>"
|
|
926
948
|
},
|
|
927
949
|
hooks: {
|
|
928
|
-
description: "Changes the order in which hooks are executed. Accepted values are: \"stack\", \"list\" and \"parallel\". Visit [`sequence.hooks`](https://vitest.dev/config
|
|
950
|
+
description: "Changes the order in which hooks are executed. Accepted values are: \"stack\", \"list\" and \"parallel\". Visit [`sequence.hooks`](https://vitest.dev/config/sequence#sequence-hooks) for more information (default: `\"parallel\"`)",
|
|
929
951
|
argument: "<order>"
|
|
930
952
|
},
|
|
931
953
|
setupFiles: {
|
|
@@ -968,7 +990,25 @@ const cliOptionsConfig = {
|
|
|
968
990
|
},
|
|
969
991
|
retry: {
|
|
970
992
|
description: "Retry the test specific number of times if it fails (default: `0`)",
|
|
971
|
-
argument: "<times>"
|
|
993
|
+
argument: "<times>",
|
|
994
|
+
subcommands: {
|
|
995
|
+
count: {
|
|
996
|
+
description: "Number of times to retry a test if it fails (default: `0`)",
|
|
997
|
+
argument: "<times>"
|
|
998
|
+
},
|
|
999
|
+
delay: {
|
|
1000
|
+
description: "Delay in milliseconds between retry attempts (default: `0`)",
|
|
1001
|
+
argument: "<ms>"
|
|
1002
|
+
},
|
|
1003
|
+
condition: {
|
|
1004
|
+
description: "Regex pattern to match error messages that should trigger a retry. Only errors matching this pattern will cause a retry (default: retry on all errors)",
|
|
1005
|
+
argument: "<pattern>",
|
|
1006
|
+
transform: (value) => {
|
|
1007
|
+
if (typeof value === "string") return new RegExp(value, "i");
|
|
1008
|
+
return value;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
972
1012
|
},
|
|
973
1013
|
diff: {
|
|
974
1014
|
description: "DiffOptions object or a path to a module which exports DiffOptions object",
|
|
@@ -1079,7 +1119,7 @@ const cliOptionsConfig = {
|
|
|
1079
1119
|
}
|
|
1080
1120
|
},
|
|
1081
1121
|
maxConcurrency: {
|
|
1082
|
-
description: "Maximum number of concurrent tests
|
|
1122
|
+
description: "Maximum number of concurrent tests and suites during test file execution (default: `5`)",
|
|
1083
1123
|
argument: "<number>"
|
|
1084
1124
|
},
|
|
1085
1125
|
expect: {
|
|
@@ -1136,7 +1176,17 @@ const cliOptionsConfig = {
|
|
|
1136
1176
|
return value;
|
|
1137
1177
|
}
|
|
1138
1178
|
},
|
|
1179
|
+
listTags: {
|
|
1180
|
+
description: "List all available tags instead of running tests. `--list-tags=json` will output tags in JSON format, unless there are no tags.",
|
|
1181
|
+
argument: "[type]"
|
|
1182
|
+
},
|
|
1139
1183
|
clearCache: { description: "Delete all Vitest caches, including `experimental.fsModuleCache`, without running any tests. This will reduce the performance in the subsequent test run." },
|
|
1184
|
+
tagsFilter: {
|
|
1185
|
+
description: "Run only tests with the specified tags. You can use logical operators `&&` (and), `||` (or) and `!` (not) to create complex expressions, see [Test Tags](https://vitest.dev/guide/test-tags#syntax) for more information.",
|
|
1186
|
+
argument: "<expression>",
|
|
1187
|
+
array: true
|
|
1188
|
+
},
|
|
1189
|
+
strictTags: { description: "Should Vitest throw an error if test has a tag that is not defined in the config. (default: `true`)" },
|
|
1140
1190
|
experimental: {
|
|
1141
1191
|
description: "Experimental features.",
|
|
1142
1192
|
argument: "<features>",
|
|
@@ -1144,7 +1194,45 @@ const cliOptionsConfig = {
|
|
|
1144
1194
|
fsModuleCache: { description: "Enable caching of modules on the file system between reruns." },
|
|
1145
1195
|
fsModuleCachePath: null,
|
|
1146
1196
|
openTelemetry: null,
|
|
1147
|
-
|
|
1197
|
+
importDurations: {
|
|
1198
|
+
description: "Configure import duration collection and CLI display. Note that UI's \"Module Graph\" tab can always show import breakdown regardless of the `print` setting.",
|
|
1199
|
+
argument: "",
|
|
1200
|
+
transform(value) {
|
|
1201
|
+
if (typeof value === "boolean") return { print: value };
|
|
1202
|
+
return value;
|
|
1203
|
+
},
|
|
1204
|
+
subcommands: {
|
|
1205
|
+
print: {
|
|
1206
|
+
description: "When to print import breakdown to CLI terminal. Use `true` to always print, `false` to never print, or `on-warn` to print only when imports exceed the warn threshold (default: false).",
|
|
1207
|
+
argument: "<boolean|on-warn>",
|
|
1208
|
+
transform(value) {
|
|
1209
|
+
if (value === "on-warn") return "on-warn";
|
|
1210
|
+
return value;
|
|
1211
|
+
}
|
|
1212
|
+
},
|
|
1213
|
+
limit: {
|
|
1214
|
+
description: "Maximum number of imports to collect and display (default: 0, or 10 if print or UI is enabled).",
|
|
1215
|
+
argument: "<number>"
|
|
1216
|
+
},
|
|
1217
|
+
failOnDanger: { description: "Fail the test run if any import exceeds the danger threshold (default: false)." },
|
|
1218
|
+
thresholds: {
|
|
1219
|
+
description: "Duration thresholds in milliseconds for coloring and warnings.",
|
|
1220
|
+
argument: "",
|
|
1221
|
+
subcommands: {
|
|
1222
|
+
warn: {
|
|
1223
|
+
description: "Warning threshold - imports exceeding this are shown in yellow/orange (default: 100).",
|
|
1224
|
+
argument: "<number>"
|
|
1225
|
+
},
|
|
1226
|
+
danger: {
|
|
1227
|
+
description: "Danger threshold - imports exceeding this are shown in red (default: 500).",
|
|
1228
|
+
argument: "<number>"
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
},
|
|
1234
|
+
viteModuleRunner: { description: "Control whether Vitest uses Vite's module runner to run the code or fallback to the native `import`. (default: `true`)" },
|
|
1235
|
+
nodeLoader: { description: "Controls whether Vitest will use Node.js Loader API to process in-source or mocked files. This has no effect if `viteModuleRunner` is enabled. Disabling this can increase performance. (default: `true`)" }
|
|
1148
1236
|
}
|
|
1149
1237
|
},
|
|
1150
1238
|
cliExclude: null,
|
|
@@ -1179,8 +1267,11 @@ const cliOptionsConfig = {
|
|
|
1179
1267
|
json: null,
|
|
1180
1268
|
provide: null,
|
|
1181
1269
|
filesOnly: null,
|
|
1270
|
+
staticParse: null,
|
|
1271
|
+
staticParseConcurrency: null,
|
|
1182
1272
|
projects: null,
|
|
1183
|
-
watchTriggerPatterns: null
|
|
1273
|
+
watchTriggerPatterns: null,
|
|
1274
|
+
tags: null
|
|
1184
1275
|
};
|
|
1185
1276
|
const benchCliOptionsConfig = {
|
|
1186
1277
|
compare: {
|
|
@@ -1199,12 +1290,876 @@ const collectCliOptionsConfig = {
|
|
|
1199
1290
|
argument: "[true/path]"
|
|
1200
1291
|
},
|
|
1201
1292
|
filesOnly: { description: "Print only test files with out the test cases" },
|
|
1293
|
+
staticParse: { description: "Parse files statically instead of running them to collect tests (default: false)" },
|
|
1294
|
+
staticParseConcurrency: {
|
|
1295
|
+
description: "How many tests to process at the same time (default: os.availableParallelism())",
|
|
1296
|
+
argument: "<limit>"
|
|
1297
|
+
},
|
|
1202
1298
|
changed: {
|
|
1203
1299
|
description: "Print only tests that are affected by the changed files (default: `false`)",
|
|
1204
1300
|
argument: "[since]"
|
|
1205
1301
|
}
|
|
1206
1302
|
};
|
|
1207
1303
|
|
|
1304
|
+
const a={ShellCompDirectiveError:1,ShellCompDirectiveNoSpace:2,ShellCompDirectiveNoFileComp:4,ShellCompDirectiveFilterFileExt:8,ShellCompDirectiveFilterDirs:16,ShellCompDirectiveKeepOrder:32,ShellCompDirectiveDefault:0};var o$1=class o{name;variadic;command;handler;constructor(e,t,n,r=false){this.command=e,this.name=t,this.handler=n,this.variadic=r;}},s$1=class s{value;description;command;handler;alias;isBoolean;constructor(e,t,n,r,i,a){this.command=e,this.value=t,this.description=n,this.handler=r,this.alias=i,this.isBoolean=a;}},c$1=class c{value;description;options=new Map;arguments=new Map;parent;constructor(e,t){this.value=e,this.description=t;}option(e,t,n,r){let i,a,o;typeof n==`function`?(i=n,a=r,o=false):typeof n==`string`?(i=void 0,a=n,o=true):(i=void 0,a=void 0,o=true);let c=new s$1(this,e,t,i,a,o);return this.options.set(e,c),this}argument(e,t,n=false){let r=new o$1(this,e,t,n);return this.arguments.set(e,r),this}},l$1=class l extends c$1{commands=new Map;completions=[];directive=a.ShellCompDirectiveDefault;constructor(){super(``,``);}command(e,t){let n=new c$1(e,t);return this.commands.set(e,n),n}stripOptions(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.startsWith(`-`)){n++;let t=false,i=this.findOption(this,r);if(i)t=i.isBoolean??false;else for(let[,e]of this.commands){let n=this.findOption(e,r);if(n){t=n.isBoolean??false;break}}!t&&n<e.length&&!e[n].startsWith(`-`)&&n++;}else t.push(r),n++;}return t}matchCommand(e){e=this.stripOptions(e);let t=[],n=[],r=null;for(let i=0;i<e.length;i++){let a=e[i];t.push(a);let o=this.commands.get(t.join(` `));if(o)r=o;else {n=e.slice(i,e.length);break}}return [r||this,n]}shouldCompleteFlags(e,t){if(t.startsWith(`-`))return true;if(e?.startsWith(`-`)){let t=this.findOption(this,e);if(!t){for(let[,n]of this.commands)if(t=this.findOption(n,e),t)break}return !(t&&t.isBoolean)}return false}shouldCompleteCommands(e){return !e.startsWith(`-`)}handleFlagCompletion(e,t,n,r){let i;if(n.includes(`=`)){let[e]=n.split(`=`);i=e;}else if(r?.startsWith(`-`)){let t=this.findOption(e,r);t&&!t.isBoolean&&(i=r);}if(i){let t=this.findOption(e,i);if(t?.handler){let n=[];t.handler.call(t,(e,t)=>n.push({value:e,description:t}),e.options),this.completions=n;}return}if(n.startsWith(`-`)){let t=n.startsWith(`-`)&&!n.startsWith(`--`),r=n.replace(/^-+/,``);for(let[i,a]of e.options)t&&a.alias&&`-${a.alias}`.startsWith(n)?this.completions.push({value:`-${a.alias}`,description:a.description}):!t&&i.startsWith(r)&&this.completions.push({value:`--${i}`,description:a.description});}}findOption(e,t){let n=e.options.get(t);if(n||(n=e.options.get(t.replace(/^-+/,``)),n))return n;for(let[n,r]of e.options)if(r.alias&&`-${r.alias}`===t)return r}handleCommandCompletion(e,t){let n=this.stripOptions(e);for(let[e,r]of this.commands){if(e===``)continue;let i=e.split(` `);i.slice(0,n.length).every((e,t)=>e===n[t])&&i[n.length]?.startsWith(t)&&this.completions.push({value:i[n.length],description:r.description});}}handlePositionalCompletion(e,t){let n=e.value.split(` `).length,r=Math.max(0,t.length-n),i=Array.from(e.arguments.entries());if(i.length>0){let t;if(r<i.length){let[e,n]=i[r];t=n;}else {let e=i[i.length-1][1];e.variadic&&(t=e);}if(t&&t.handler&&typeof t.handler==`function`){let n=[];t.handler.call(t,(e,t)=>n.push({value:e,description:t}),e.options),this.completions.push(...n);}}}complete(e){this.directive=a.ShellCompDirectiveNoFileComp;let t=new Set;this.completions.filter(e=>t.has(e.value)?false:(t.add(e.value),true)).filter(t=>{if(e.includes(`=`)){let[,n]=e.split(`=`);return t.value.startsWith(n)}return t.value.startsWith(e)}).forEach(e=>console.log(`${e.value}\t${e.description??``}`)),console.log(`:${this.directive}`);}parse(e){this.completions=[];let t=e[e.length-1]===``;t&&e.pop();let n=e[e.length-1]||``,r=e.slice(0,-1);t&&(n!==``&&r.push(n),n=``);let[i]=this.matchCommand(r),a=r[r.length-1];if(this.shouldCompleteFlags(a,n))this.handleFlagCompletion(i,r,n,a);else {if(a?.startsWith(`-`)&&n===``&&t){let e=this.findOption(this,a);if(!e){for(let[,t]of this.commands)if(e=this.findOption(t,a),e)break}if(e&&e.isBoolean){this.complete(n);return}}this.shouldCompleteCommands(n)&&this.handleCommandCompletion(r,n),i&&i.arguments.size>0&&this.handlePositionalCompletion(i,r);}this.complete(n);}setup(a,o,s){switch(assert(s===`zsh`||s===`bash`||s===`fish`||s===`powershell`,`Unsupported shell`),s){case `zsh`:{let t$1=t(a,o);console.log(t$1);break}case `bash`:{let e=n(a,o);console.log(e);break}case `fish`:{let e=r(a,o);console.log(e);break}case `powershell`:{let e=i(a,o);console.log(e);break}}}};const u$1=new l$1;
|
|
1305
|
+
|
|
1306
|
+
function t(t,n){return `#compdef ${t}
|
|
1307
|
+
compdef _${t} ${t}
|
|
1308
|
+
|
|
1309
|
+
# zsh completion for ${t} -*- shell-script -*-
|
|
1310
|
+
|
|
1311
|
+
__${t}_debug() {
|
|
1312
|
+
local file="$BASH_COMP_DEBUG_FILE"
|
|
1313
|
+
if [[ -n \${file} ]]; then
|
|
1314
|
+
echo "$*" >> "\${file}"
|
|
1315
|
+
fi
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
_${t}() {
|
|
1319
|
+
local shellCompDirectiveError=${a.ShellCompDirectiveError}
|
|
1320
|
+
local shellCompDirectiveNoSpace=${a.ShellCompDirectiveNoSpace}
|
|
1321
|
+
local shellCompDirectiveNoFileComp=${a.ShellCompDirectiveNoFileComp}
|
|
1322
|
+
local shellCompDirectiveFilterFileExt=${a.ShellCompDirectiveFilterFileExt}
|
|
1323
|
+
local shellCompDirectiveFilterDirs=${a.ShellCompDirectiveFilterDirs}
|
|
1324
|
+
local shellCompDirectiveKeepOrder=${a.ShellCompDirectiveKeepOrder}
|
|
1325
|
+
|
|
1326
|
+
local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder
|
|
1327
|
+
local -a completions
|
|
1328
|
+
|
|
1329
|
+
__${t}_debug "\\n========= starting completion logic =========="
|
|
1330
|
+
__${t}_debug "CURRENT: \${CURRENT}, words[*]: \${words[*]}"
|
|
1331
|
+
|
|
1332
|
+
# The user could have moved the cursor backwards on the command-line.
|
|
1333
|
+
# We need to trigger completion from the $CURRENT location, so we need
|
|
1334
|
+
# to truncate the command-line ($words) up to the $CURRENT location.
|
|
1335
|
+
# (We cannot use $CURSOR as its value does not work when a command is an alias.)
|
|
1336
|
+
words=( "\${=words[1,CURRENT]}" )
|
|
1337
|
+
__${t}_debug "Truncated words[*]: \${words[*]},"
|
|
1338
|
+
|
|
1339
|
+
lastParam=\${words[-1]}
|
|
1340
|
+
lastChar=\${lastParam[-1]}
|
|
1341
|
+
__${t}_debug "lastParam: \${lastParam}, lastChar: \${lastChar}"
|
|
1342
|
+
|
|
1343
|
+
# For zsh, when completing a flag with an = (e.g., ${t} -n=<TAB>)
|
|
1344
|
+
# completions must be prefixed with the flag
|
|
1345
|
+
setopt local_options BASH_REMATCH
|
|
1346
|
+
if [[ "\${lastParam}" =~ '-.*=' ]]; then
|
|
1347
|
+
# We are dealing with a flag with an =
|
|
1348
|
+
flagPrefix="-P \${BASH_REMATCH}"
|
|
1349
|
+
fi
|
|
1350
|
+
|
|
1351
|
+
# Prepare the command to obtain completions, ensuring arguments are quoted for eval
|
|
1352
|
+
local -a args_to_quote=("\${(@)words[2,-1]}")
|
|
1353
|
+
if [ "\${lastChar}" = "" ]; then
|
|
1354
|
+
# If the last parameter is complete (there is a space following it)
|
|
1355
|
+
# We add an extra empty parameter so we can indicate this to the go completion code.
|
|
1356
|
+
__${t}_debug "Adding extra empty parameter"
|
|
1357
|
+
args_to_quote+=("")
|
|
1358
|
+
fi
|
|
1359
|
+
|
|
1360
|
+
# Use Zsh's (q) flag to quote each argument safely for eval
|
|
1361
|
+
local quoted_args=("\${(@q)args_to_quote}")
|
|
1362
|
+
|
|
1363
|
+
# Join the main command and the quoted arguments into a single string for eval
|
|
1364
|
+
requestComp="${n} complete -- \${quoted_args[*]}"
|
|
1365
|
+
|
|
1366
|
+
__${t}_debug "About to call: eval \${requestComp}"
|
|
1367
|
+
|
|
1368
|
+
# Use eval to handle any environment variables and such
|
|
1369
|
+
out=$(eval \${requestComp} 2>/dev/null)
|
|
1370
|
+
__${t}_debug "completion output: \${out}"
|
|
1371
|
+
|
|
1372
|
+
# Extract the directive integer following a : from the last line
|
|
1373
|
+
local lastLine
|
|
1374
|
+
while IFS='\n' read -r line; do
|
|
1375
|
+
lastLine=\${line}
|
|
1376
|
+
done < <(printf "%s\n" "\${out[@]}")
|
|
1377
|
+
__${t}_debug "last line: \${lastLine}"
|
|
1378
|
+
|
|
1379
|
+
if [ "\${lastLine[1]}" = : ]; then
|
|
1380
|
+
directive=\${lastLine[2,-1]}
|
|
1381
|
+
# Remove the directive including the : and the newline
|
|
1382
|
+
local suffix
|
|
1383
|
+
(( suffix=\${#lastLine}+2))
|
|
1384
|
+
out=\${out[1,-$suffix]}
|
|
1385
|
+
else
|
|
1386
|
+
# There is no directive specified. Leave $out as is.
|
|
1387
|
+
__${t}_debug "No directive found. Setting to default"
|
|
1388
|
+
directive=0
|
|
1389
|
+
fi
|
|
1390
|
+
|
|
1391
|
+
__${t}_debug "directive: \${directive}"
|
|
1392
|
+
__${t}_debug "completions: \${out}"
|
|
1393
|
+
__${t}_debug "flagPrefix: \${flagPrefix}"
|
|
1394
|
+
|
|
1395
|
+
if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
|
|
1396
|
+
__${t}_debug "Completion received error. Ignoring completions."
|
|
1397
|
+
return
|
|
1398
|
+
fi
|
|
1399
|
+
|
|
1400
|
+
local activeHelpMarker="%"
|
|
1401
|
+
local endIndex=\${#activeHelpMarker}
|
|
1402
|
+
local startIndex=$((\${#activeHelpMarker}+1))
|
|
1403
|
+
local hasActiveHelp=0
|
|
1404
|
+
while IFS='\n' read -r comp; do
|
|
1405
|
+
# Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker)
|
|
1406
|
+
if [ "\${comp[1,$endIndex]}" = "$activeHelpMarker" ];then
|
|
1407
|
+
__${t}_debug "ActiveHelp found: $comp"
|
|
1408
|
+
comp="\${comp[$startIndex,-1]}"
|
|
1409
|
+
if [ -n "$comp" ]; then
|
|
1410
|
+
compadd -x "\${comp}"
|
|
1411
|
+
__${t}_debug "ActiveHelp will need delimiter"
|
|
1412
|
+
hasActiveHelp=1
|
|
1413
|
+
fi
|
|
1414
|
+
continue
|
|
1415
|
+
fi
|
|
1416
|
+
|
|
1417
|
+
if [ -n "$comp" ]; then
|
|
1418
|
+
# If requested, completions are returned with a description.
|
|
1419
|
+
# The description is preceded by a TAB character.
|
|
1420
|
+
# For zsh's _describe, we need to use a : instead of a TAB.
|
|
1421
|
+
# We first need to escape any : as part of the completion itself.
|
|
1422
|
+
comp=\${comp//:/\\:}
|
|
1423
|
+
|
|
1424
|
+
local tab="$(printf '\\t')"
|
|
1425
|
+
comp=\${comp//$tab/:}
|
|
1426
|
+
|
|
1427
|
+
__${t}_debug "Adding completion: \${comp}"
|
|
1428
|
+
completions+=\${comp}
|
|
1429
|
+
lastComp=$comp
|
|
1430
|
+
fi
|
|
1431
|
+
done < <(printf "%s\n" "\${out[@]}")
|
|
1432
|
+
|
|
1433
|
+
# Add a delimiter after the activeHelp statements, but only if:
|
|
1434
|
+
# - there are completions following the activeHelp statements, or
|
|
1435
|
+
# - file completion will be performed (so there will be choices after the activeHelp)
|
|
1436
|
+
if [ $hasActiveHelp -eq 1 ]; then
|
|
1437
|
+
if [ \${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then
|
|
1438
|
+
__${t}_debug "Adding activeHelp delimiter"
|
|
1439
|
+
compadd -x "--"
|
|
1440
|
+
hasActiveHelp=0
|
|
1441
|
+
fi
|
|
1442
|
+
fi
|
|
1443
|
+
|
|
1444
|
+
if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
|
|
1445
|
+
__${t}_debug "Activating nospace."
|
|
1446
|
+
noSpace="-S ''"
|
|
1447
|
+
fi
|
|
1448
|
+
|
|
1449
|
+
if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then
|
|
1450
|
+
__${t}_debug "Activating keep order."
|
|
1451
|
+
keepOrder="-V"
|
|
1452
|
+
fi
|
|
1453
|
+
|
|
1454
|
+
if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
|
|
1455
|
+
# File extension filtering
|
|
1456
|
+
local filteringCmd
|
|
1457
|
+
filteringCmd='_files'
|
|
1458
|
+
for filter in \${completions[@]}; do
|
|
1459
|
+
if [ \${filter[1]} != '*' ]; then
|
|
1460
|
+
# zsh requires a glob pattern to do file filtering
|
|
1461
|
+
filter="\\*.$filter"
|
|
1462
|
+
fi
|
|
1463
|
+
filteringCmd+=" -g $filter"
|
|
1464
|
+
done
|
|
1465
|
+
filteringCmd+=" \${flagPrefix}"
|
|
1466
|
+
|
|
1467
|
+
__${t}_debug "File filtering command: $filteringCmd"
|
|
1468
|
+
_arguments '*:filename:'"$filteringCmd"
|
|
1469
|
+
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
|
|
1470
|
+
# File completion for directories only
|
|
1471
|
+
local subdir
|
|
1472
|
+
subdir="\${completions[1]}"
|
|
1473
|
+
if [ -n "$subdir" ]; then
|
|
1474
|
+
__${t}_debug "Listing directories in $subdir"
|
|
1475
|
+
pushd "\${subdir}" >/dev/null 2>&1
|
|
1476
|
+
else
|
|
1477
|
+
__${t}_debug "Listing directories in ."
|
|
1478
|
+
fi
|
|
1479
|
+
|
|
1480
|
+
local result
|
|
1481
|
+
_arguments '*:dirname:_files -/'" \${flagPrefix}"
|
|
1482
|
+
result=$?
|
|
1483
|
+
if [ -n "$subdir" ]; then
|
|
1484
|
+
popd >/dev/null 2>&1
|
|
1485
|
+
fi
|
|
1486
|
+
return $result
|
|
1487
|
+
else
|
|
1488
|
+
__${t}_debug "Calling _describe"
|
|
1489
|
+
if eval _describe $keepOrder "completions" completions -Q \${flagPrefix} \${noSpace}; then
|
|
1490
|
+
__${t}_debug "_describe found some completions"
|
|
1491
|
+
|
|
1492
|
+
# Return the success of having called _describe
|
|
1493
|
+
return 0
|
|
1494
|
+
else
|
|
1495
|
+
__${t}_debug "_describe did not find completions."
|
|
1496
|
+
__${t}_debug "Checking if we should do file completion."
|
|
1497
|
+
if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
|
|
1498
|
+
__${t}_debug "deactivating file completion"
|
|
1499
|
+
|
|
1500
|
+
# Return 0 to indicate completion is finished and prevent zsh from
|
|
1501
|
+
# trying other completion algorithms (which could cause hanging).
|
|
1502
|
+
# We use NoFileComp directive to explicitly disable file completion.
|
|
1503
|
+
return 0
|
|
1504
|
+
else
|
|
1505
|
+
# Perform file completion
|
|
1506
|
+
__${t}_debug "Activating file completion"
|
|
1507
|
+
|
|
1508
|
+
# We must return the result of this command, so it must be the
|
|
1509
|
+
# last command, or else we must store its result to return it.
|
|
1510
|
+
_arguments '*:filename:_files'" \${flagPrefix}"
|
|
1511
|
+
fi
|
|
1512
|
+
fi
|
|
1513
|
+
fi
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
# don't run the completion function when being sourced or eval-ed
|
|
1517
|
+
if [ "\${funcstack[1]}" = "_${t}" ]; then
|
|
1518
|
+
_${t}
|
|
1519
|
+
fi
|
|
1520
|
+
`}function n(t,n){let r=t.replace(/[-:]/g,`_`);return `# bash completion for ${t}
|
|
1521
|
+
|
|
1522
|
+
# Define shell completion directives
|
|
1523
|
+
readonly ShellCompDirectiveError=${a.ShellCompDirectiveError}
|
|
1524
|
+
readonly ShellCompDirectiveNoSpace=${a.ShellCompDirectiveNoSpace}
|
|
1525
|
+
readonly ShellCompDirectiveNoFileComp=${a.ShellCompDirectiveNoFileComp}
|
|
1526
|
+
readonly ShellCompDirectiveFilterFileExt=${a.ShellCompDirectiveFilterFileExt}
|
|
1527
|
+
readonly ShellCompDirectiveFilterDirs=${a.ShellCompDirectiveFilterDirs}
|
|
1528
|
+
readonly ShellCompDirectiveKeepOrder=${a.ShellCompDirectiveKeepOrder}
|
|
1529
|
+
|
|
1530
|
+
# Function to debug completion
|
|
1531
|
+
__${r}_debug() {
|
|
1532
|
+
if [[ -n \${BASH_COMP_DEBUG_FILE:-} ]]; then
|
|
1533
|
+
echo "$*" >> "\${BASH_COMP_DEBUG_FILE}"
|
|
1534
|
+
fi
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
# Function to handle completions
|
|
1538
|
+
__${r}_complete() {
|
|
1539
|
+
local cur prev words cword
|
|
1540
|
+
_get_comp_words_by_ref -n "=:" cur prev words cword
|
|
1541
|
+
|
|
1542
|
+
local requestComp out directive
|
|
1543
|
+
|
|
1544
|
+
# Build the command to get completions
|
|
1545
|
+
requestComp="${n} complete -- \${words[@]:1}"
|
|
1546
|
+
|
|
1547
|
+
# Add an empty parameter if the last parameter is complete
|
|
1548
|
+
if [[ -z "$cur" ]]; then
|
|
1549
|
+
requestComp="$requestComp ''"
|
|
1550
|
+
fi
|
|
1551
|
+
|
|
1552
|
+
# Get completions from the program
|
|
1553
|
+
out=$(eval "$requestComp" 2>/dev/null)
|
|
1554
|
+
|
|
1555
|
+
# Extract directive if present
|
|
1556
|
+
directive=0
|
|
1557
|
+
if [[ "$out" == *:* ]]; then
|
|
1558
|
+
directive=\${out##*:}
|
|
1559
|
+
out=\${out%:*}
|
|
1560
|
+
fi
|
|
1561
|
+
|
|
1562
|
+
# Process completions based on directive
|
|
1563
|
+
if [[ $((directive & $ShellCompDirectiveError)) -ne 0 ]]; then
|
|
1564
|
+
# Error, no completion
|
|
1565
|
+
return
|
|
1566
|
+
fi
|
|
1567
|
+
|
|
1568
|
+
# Apply directives
|
|
1569
|
+
if [[ $((directive & $ShellCompDirectiveNoSpace)) -ne 0 ]]; then
|
|
1570
|
+
compopt -o nospace
|
|
1571
|
+
fi
|
|
1572
|
+
if [[ $((directive & $ShellCompDirectiveKeepOrder)) -ne 0 ]]; then
|
|
1573
|
+
compopt -o nosort
|
|
1574
|
+
fi
|
|
1575
|
+
if [[ $((directive & $ShellCompDirectiveNoFileComp)) -ne 0 ]]; then
|
|
1576
|
+
compopt +o default
|
|
1577
|
+
fi
|
|
1578
|
+
|
|
1579
|
+
# Handle file extension filtering
|
|
1580
|
+
if [[ $((directive & $ShellCompDirectiveFilterFileExt)) -ne 0 ]]; then
|
|
1581
|
+
local filter=""
|
|
1582
|
+
for ext in $out; do
|
|
1583
|
+
filter="$filter|$ext"
|
|
1584
|
+
done
|
|
1585
|
+
filter="\\.($filter)"
|
|
1586
|
+
compopt -o filenames
|
|
1587
|
+
COMPREPLY=( $(compgen -f -X "!$filter" -- "$cur") )
|
|
1588
|
+
return
|
|
1589
|
+
fi
|
|
1590
|
+
|
|
1591
|
+
# Handle directory filtering
|
|
1592
|
+
if [[ $((directive & $ShellCompDirectiveFilterDirs)) -ne 0 ]]; then
|
|
1593
|
+
compopt -o dirnames
|
|
1594
|
+
COMPREPLY=( $(compgen -d -- "$cur") )
|
|
1595
|
+
return
|
|
1596
|
+
fi
|
|
1597
|
+
|
|
1598
|
+
# Process completions
|
|
1599
|
+
local IFS=$'\\n'
|
|
1600
|
+
local tab=$(printf '\\t')
|
|
1601
|
+
|
|
1602
|
+
# Parse completions with descriptions
|
|
1603
|
+
local completions=()
|
|
1604
|
+
while read -r comp; do
|
|
1605
|
+
if [[ "$comp" == *$tab* ]]; then
|
|
1606
|
+
# Split completion and description
|
|
1607
|
+
local value=\${comp%%$tab*}
|
|
1608
|
+
local desc=\${comp#*$tab}
|
|
1609
|
+
completions+=("$value")
|
|
1610
|
+
else
|
|
1611
|
+
completions+=("$comp")
|
|
1612
|
+
fi
|
|
1613
|
+
done <<< "$out"
|
|
1614
|
+
|
|
1615
|
+
# Return completions
|
|
1616
|
+
COMPREPLY=( $(compgen -W "\${completions[*]}" -- "$cur") )
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
# Register completion function
|
|
1620
|
+
complete -F __${r}_complete ${t}
|
|
1621
|
+
`}function r(t,n){let r=t.replace(/[-:]/g,`_`),i=a.ShellCompDirectiveError,a$1=a.ShellCompDirectiveNoSpace,o=a.ShellCompDirectiveNoFileComp,s=a.ShellCompDirectiveFilterFileExt,c=a.ShellCompDirectiveFilterDirs;return `# fish completion for ${t} -*- shell-script -*-
|
|
1622
|
+
|
|
1623
|
+
function __${r}_debug
|
|
1624
|
+
set -l file "$BASH_COMP_DEBUG_FILE"
|
|
1625
|
+
if test -n "$file"
|
|
1626
|
+
echo "$argv" >> $file
|
|
1627
|
+
end
|
|
1628
|
+
end
|
|
1629
|
+
|
|
1630
|
+
function __${r}_perform_completion
|
|
1631
|
+
__${r}_debug "Starting __${r}_perform_completion"
|
|
1632
|
+
|
|
1633
|
+
# Extract all args except the last one
|
|
1634
|
+
set -l args (commandline -opc)
|
|
1635
|
+
# Extract the last arg and escape it in case it is a space or wildcard
|
|
1636
|
+
set -l lastArg (string escape -- (commandline -ct))
|
|
1637
|
+
|
|
1638
|
+
__${r}_debug "args: $args"
|
|
1639
|
+
__${r}_debug "last arg: $lastArg"
|
|
1640
|
+
|
|
1641
|
+
# Build the completion request command
|
|
1642
|
+
set -l requestComp "${n} complete -- (string join ' ' -- (string escape -- $args[2..-1])) $lastArg"
|
|
1643
|
+
|
|
1644
|
+
__${r}_debug "Calling $requestComp"
|
|
1645
|
+
set -l results (eval $requestComp 2> /dev/null)
|
|
1646
|
+
|
|
1647
|
+
# Some programs may output extra empty lines after the directive.
|
|
1648
|
+
# Let's ignore them or else it will break completion.
|
|
1649
|
+
# Ref: https://github.com/spf13/cobra/issues/1279
|
|
1650
|
+
for line in $results[-1..1]
|
|
1651
|
+
if test (string trim -- $line) = ""
|
|
1652
|
+
# Found an empty line, remove it
|
|
1653
|
+
set results $results[1..-2]
|
|
1654
|
+
else
|
|
1655
|
+
# Found non-empty line, we have our proper output
|
|
1656
|
+
break
|
|
1657
|
+
end
|
|
1658
|
+
end
|
|
1659
|
+
|
|
1660
|
+
set -l comps $results[1..-2]
|
|
1661
|
+
set -l directiveLine $results[-1]
|
|
1662
|
+
|
|
1663
|
+
# For Fish, when completing a flag with an = (e.g., <program> -n=<TAB>)
|
|
1664
|
+
# completions must be prefixed with the flag
|
|
1665
|
+
set -l flagPrefix (string match -r -- '-.*=' "$lastArg")
|
|
1666
|
+
|
|
1667
|
+
__${r}_debug "Comps: $comps"
|
|
1668
|
+
__${r}_debug "DirectiveLine: $directiveLine"
|
|
1669
|
+
__${r}_debug "flagPrefix: $flagPrefix"
|
|
1670
|
+
|
|
1671
|
+
for comp in $comps
|
|
1672
|
+
printf "%s%s\\n" "$flagPrefix" "$comp"
|
|
1673
|
+
end
|
|
1674
|
+
|
|
1675
|
+
printf "%s\\n" "$directiveLine"
|
|
1676
|
+
end
|
|
1677
|
+
|
|
1678
|
+
# This function limits calls to __${r}_perform_completion, by caching the result
|
|
1679
|
+
function __${r}_perform_completion_once
|
|
1680
|
+
__${r}_debug "Starting __${r}_perform_completion_once"
|
|
1681
|
+
|
|
1682
|
+
if test -n "$__${r}_perform_completion_once_result"
|
|
1683
|
+
__${r}_debug "Seems like a valid result already exists, skipping __${r}_perform_completion"
|
|
1684
|
+
return 0
|
|
1685
|
+
end
|
|
1686
|
+
|
|
1687
|
+
set --global __${r}_perform_completion_once_result (__${r}_perform_completion)
|
|
1688
|
+
if test -z "$__${r}_perform_completion_once_result"
|
|
1689
|
+
__${r}_debug "No completions, probably due to a failure"
|
|
1690
|
+
return 1
|
|
1691
|
+
end
|
|
1692
|
+
|
|
1693
|
+
__${r}_debug "Performed completions and set __${r}_perform_completion_once_result"
|
|
1694
|
+
return 0
|
|
1695
|
+
end
|
|
1696
|
+
|
|
1697
|
+
# This function is used to clear the cached result after completions are run
|
|
1698
|
+
function __${r}_clear_perform_completion_once_result
|
|
1699
|
+
__${r}_debug ""
|
|
1700
|
+
__${r}_debug "========= clearing previously set __${r}_perform_completion_once_result variable =========="
|
|
1701
|
+
set --erase __${r}_perform_completion_once_result
|
|
1702
|
+
__${r}_debug "Successfully erased the variable __${r}_perform_completion_once_result"
|
|
1703
|
+
end
|
|
1704
|
+
|
|
1705
|
+
function __${r}_requires_order_preservation
|
|
1706
|
+
__${r}_debug ""
|
|
1707
|
+
__${r}_debug "========= checking if order preservation is required =========="
|
|
1708
|
+
|
|
1709
|
+
__${r}_perform_completion_once
|
|
1710
|
+
if test -z "$__${r}_perform_completion_once_result"
|
|
1711
|
+
__${r}_debug "Error determining if order preservation is required"
|
|
1712
|
+
return 1
|
|
1713
|
+
end
|
|
1714
|
+
|
|
1715
|
+
set -l directive (string sub --start 2 $__${r}_perform_completion_once_result[-1])
|
|
1716
|
+
__${r}_debug "Directive is: $directive"
|
|
1717
|
+
|
|
1718
|
+
set -l shellCompDirectiveKeepOrder ${a.ShellCompDirectiveKeepOrder}
|
|
1719
|
+
set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) % 2)
|
|
1720
|
+
__${r}_debug "Keeporder is: $keeporder"
|
|
1721
|
+
|
|
1722
|
+
if test $keeporder -ne 0
|
|
1723
|
+
__${r}_debug "This does require order preservation"
|
|
1724
|
+
return 0
|
|
1725
|
+
end
|
|
1726
|
+
|
|
1727
|
+
__${r}_debug "This doesn't require order preservation"
|
|
1728
|
+
return 1
|
|
1729
|
+
end
|
|
1730
|
+
|
|
1731
|
+
# This function does two things:
|
|
1732
|
+
# - Obtain the completions and store them in the global __${r}_comp_results
|
|
1733
|
+
# - Return false if file completion should be performed
|
|
1734
|
+
function __${r}_prepare_completions
|
|
1735
|
+
__${r}_debug ""
|
|
1736
|
+
__${r}_debug "========= starting completion logic =========="
|
|
1737
|
+
|
|
1738
|
+
# Start fresh
|
|
1739
|
+
set --erase __${r}_comp_results
|
|
1740
|
+
|
|
1741
|
+
__${r}_perform_completion_once
|
|
1742
|
+
__${r}_debug "Completion results: $__${r}_perform_completion_once_result"
|
|
1743
|
+
|
|
1744
|
+
if test -z "$__${r}_perform_completion_once_result"
|
|
1745
|
+
__${r}_debug "No completion, probably due to a failure"
|
|
1746
|
+
# Might as well do file completion, in case it helps
|
|
1747
|
+
return 1
|
|
1748
|
+
end
|
|
1749
|
+
|
|
1750
|
+
set -l directive (string sub --start 2 $__${r}_perform_completion_once_result[-1])
|
|
1751
|
+
set --global __${r}_comp_results $__${r}_perform_completion_once_result[1..-2]
|
|
1752
|
+
|
|
1753
|
+
__${r}_debug "Completions are: $__${r}_comp_results"
|
|
1754
|
+
__${r}_debug "Directive is: $directive"
|
|
1755
|
+
|
|
1756
|
+
set -l shellCompDirectiveError ${i}
|
|
1757
|
+
set -l shellCompDirectiveNoSpace ${a$1}
|
|
1758
|
+
set -l shellCompDirectiveNoFileComp ${o}
|
|
1759
|
+
set -l shellCompDirectiveFilterFileExt ${s}
|
|
1760
|
+
set -l shellCompDirectiveFilterDirs ${c}
|
|
1761
|
+
|
|
1762
|
+
if test -z "$directive"
|
|
1763
|
+
set directive 0
|
|
1764
|
+
end
|
|
1765
|
+
|
|
1766
|
+
set -l compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2)
|
|
1767
|
+
if test $compErr -eq 1
|
|
1768
|
+
__${r}_debug "Received error directive: aborting."
|
|
1769
|
+
# Might as well do file completion, in case it helps
|
|
1770
|
+
return 1
|
|
1771
|
+
end
|
|
1772
|
+
|
|
1773
|
+
set -l filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2)
|
|
1774
|
+
set -l dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2)
|
|
1775
|
+
if test $filefilter -eq 1; or test $dirfilter -eq 1
|
|
1776
|
+
__${r}_debug "File extension filtering or directory filtering not supported"
|
|
1777
|
+
# Do full file completion instead
|
|
1778
|
+
return 1
|
|
1779
|
+
end
|
|
1780
|
+
|
|
1781
|
+
set -l nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2)
|
|
1782
|
+
set -l nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2)
|
|
1783
|
+
|
|
1784
|
+
__${r}_debug "nospace: $nospace, nofiles: $nofiles"
|
|
1785
|
+
|
|
1786
|
+
# If we want to prevent a space, or if file completion is NOT disabled,
|
|
1787
|
+
# we need to count the number of valid completions.
|
|
1788
|
+
# To do so, we will filter on prefix as the completions we have received
|
|
1789
|
+
# may not already be filtered so as to allow fish to match on different
|
|
1790
|
+
# criteria than the prefix.
|
|
1791
|
+
if test $nospace -ne 0; or test $nofiles -eq 0
|
|
1792
|
+
set -l prefix (commandline -t | string escape --style=regex)
|
|
1793
|
+
__${r}_debug "prefix: $prefix"
|
|
1794
|
+
|
|
1795
|
+
set -l completions (string match -r -- "^$prefix.*" $__${r}_comp_results)
|
|
1796
|
+
set --global __${r}_comp_results $completions
|
|
1797
|
+
__${r}_debug "Filtered completions are: $__${r}_comp_results"
|
|
1798
|
+
|
|
1799
|
+
# Important not to quote the variable for count to work
|
|
1800
|
+
set -l numComps (count $__${r}_comp_results)
|
|
1801
|
+
__${r}_debug "numComps: $numComps"
|
|
1802
|
+
|
|
1803
|
+
if test $numComps -eq 1; and test $nospace -ne 0
|
|
1804
|
+
# We must first split on \\t to get rid of the descriptions to be
|
|
1805
|
+
# able to check what the actual completion will be.
|
|
1806
|
+
# We don't need descriptions anyway since there is only a single
|
|
1807
|
+
# real completion which the shell will expand immediately.
|
|
1808
|
+
set -l split (string split --max 1 "\\t" $__${r}_comp_results[1])
|
|
1809
|
+
|
|
1810
|
+
# Fish won't add a space if the completion ends with any
|
|
1811
|
+
# of the following characters: @=/:.,
|
|
1812
|
+
set -l lastChar (string sub -s -1 -- $split)
|
|
1813
|
+
if not string match -r -q "[@=/:.,]" -- "$lastChar"
|
|
1814
|
+
# In other cases, to support the "nospace" directive we trick the shell
|
|
1815
|
+
# by outputting an extra, longer completion.
|
|
1816
|
+
__${r}_debug "Adding second completion to perform nospace directive"
|
|
1817
|
+
set --global __${r}_comp_results $split[1] $split[1].
|
|
1818
|
+
__${r}_debug "Completions are now: $__${r}_comp_results"
|
|
1819
|
+
end
|
|
1820
|
+
end
|
|
1821
|
+
|
|
1822
|
+
if test $numComps -eq 0; and test $nofiles -eq 0
|
|
1823
|
+
# To be consistent with bash and zsh, we only trigger file
|
|
1824
|
+
# completion when there are no other completions
|
|
1825
|
+
__${r}_debug "Requesting file completion"
|
|
1826
|
+
return 1
|
|
1827
|
+
end
|
|
1828
|
+
end
|
|
1829
|
+
|
|
1830
|
+
return 0
|
|
1831
|
+
end
|
|
1832
|
+
|
|
1833
|
+
# Since Fish completions are only loaded once the user triggers them, we trigger them ourselves
|
|
1834
|
+
# so we can properly delete any completions provided by another script.
|
|
1835
|
+
# Only do this if the program can be found, or else fish may print some errors; besides,
|
|
1836
|
+
# the existing completions will only be loaded if the program can be found.
|
|
1837
|
+
if type -q "${t}"
|
|
1838
|
+
# The space after the program name is essential to trigger completion for the program
|
|
1839
|
+
# and not completion of the program name itself.
|
|
1840
|
+
# Also, we use '> /dev/null 2>&1' since '&>' is not supported in older versions of fish.
|
|
1841
|
+
complete --do-complete "${t} " > /dev/null 2>&1
|
|
1842
|
+
end
|
|
1843
|
+
|
|
1844
|
+
# Remove any pre-existing completions for the program since we will be handling all of them.
|
|
1845
|
+
complete -c ${t} -e
|
|
1846
|
+
|
|
1847
|
+
# This will get called after the two calls below and clear the cached result
|
|
1848
|
+
complete -c ${t} -n '__${r}_clear_perform_completion_once_result'
|
|
1849
|
+
# The call to __${r}_prepare_completions will setup __${r}_comp_results
|
|
1850
|
+
# which provides the program's completion choices.
|
|
1851
|
+
# If this doesn't require order preservation, we don't use the -k flag
|
|
1852
|
+
complete -c ${t} -n 'not __${r}_requires_order_preservation && __${r}_prepare_completions' -f -a '$__${r}_comp_results'
|
|
1853
|
+
# Otherwise we use the -k flag
|
|
1854
|
+
complete -k -c ${t} -n '__${r}_requires_order_preservation && __${r}_prepare_completions' -f -a '$__${r}_comp_results'
|
|
1855
|
+
`}function i(t,n){let r=t.replace(/[-:]/g,`_`);return `# powershell completion for ${t} -*- shell-script -*-
|
|
1856
|
+
|
|
1857
|
+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
1858
|
+
function __${t}_debug {
|
|
1859
|
+
if ($env:BASH_COMP_DEBUG_FILE) {
|
|
1860
|
+
"$args" | Out-File -Append -FilePath "$env:BASH_COMP_DEBUG_FILE"
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
filter __${t}_escapeStringWithSpecialChars {
|
|
1865
|
+
$_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|"|\\||<|>|&','\`$&'
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
[scriptblock]$__${r}CompleterBlock = {
|
|
1869
|
+
param(
|
|
1870
|
+
$WordToComplete,
|
|
1871
|
+
$CommandAst,
|
|
1872
|
+
$CursorPosition
|
|
1873
|
+
)
|
|
1874
|
+
|
|
1875
|
+
# Get the current command line and convert into a string
|
|
1876
|
+
$Command = $CommandAst.CommandElements
|
|
1877
|
+
$Command = "$Command"
|
|
1878
|
+
|
|
1879
|
+
__${t}_debug ""
|
|
1880
|
+
__${t}_debug "========= starting completion logic =========="
|
|
1881
|
+
__${t}_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition"
|
|
1882
|
+
|
|
1883
|
+
# The user could have moved the cursor backwards on the command-line.
|
|
1884
|
+
# We need to trigger completion from the $CursorPosition location, so we need
|
|
1885
|
+
# to truncate the command-line ($Command) up to the $CursorPosition location.
|
|
1886
|
+
# Make sure the $Command is longer then the $CursorPosition before we truncate.
|
|
1887
|
+
# This happens because the $Command does not include the last space.
|
|
1888
|
+
if ($Command.Length -gt $CursorPosition) {
|
|
1889
|
+
$Command = $Command.Substring(0, $CursorPosition)
|
|
1890
|
+
}
|
|
1891
|
+
__${t}_debug "Truncated command: $Command"
|
|
1892
|
+
|
|
1893
|
+
$ShellCompDirectiveError=${a.ShellCompDirectiveError}
|
|
1894
|
+
$ShellCompDirectiveNoSpace=${a.ShellCompDirectiveNoSpace}
|
|
1895
|
+
$ShellCompDirectiveNoFileComp=${a.ShellCompDirectiveNoFileComp}
|
|
1896
|
+
$ShellCompDirectiveFilterFileExt=${a.ShellCompDirectiveFilterFileExt}
|
|
1897
|
+
$ShellCompDirectiveFilterDirs=${a.ShellCompDirectiveFilterDirs}
|
|
1898
|
+
$ShellCompDirectiveKeepOrder=${a.ShellCompDirectiveKeepOrder}
|
|
1899
|
+
|
|
1900
|
+
# Prepare the command to request completions for the program.
|
|
1901
|
+
# Split the command at the first space to separate the program and arguments.
|
|
1902
|
+
$Program, $Arguments = $Command.Split(" ", 2)
|
|
1903
|
+
|
|
1904
|
+
$QuotedArgs = ($Arguments -split ' ' | ForEach-Object { "'" + ($_ -replace "'", "''") + "'" }) -join ' '
|
|
1905
|
+
__${t}_debug "QuotedArgs: $QuotedArgs"
|
|
1906
|
+
|
|
1907
|
+
$RequestComp = "& ${n} complete '--' $QuotedArgs"
|
|
1908
|
+
__${t}_debug "RequestComp: $RequestComp"
|
|
1909
|
+
|
|
1910
|
+
# we cannot use $WordToComplete because it
|
|
1911
|
+
# has the wrong values if the cursor was moved
|
|
1912
|
+
# so use the last argument
|
|
1913
|
+
if ($WordToComplete -ne "" ) {
|
|
1914
|
+
$WordToComplete = $Arguments.Split(" ")[-1]
|
|
1915
|
+
}
|
|
1916
|
+
__${t}_debug "New WordToComplete: $WordToComplete"
|
|
1917
|
+
|
|
1918
|
+
|
|
1919
|
+
# Check for flag with equal sign
|
|
1920
|
+
$IsEqualFlag = ($WordToComplete -Like "--*=*" )
|
|
1921
|
+
if ( $IsEqualFlag ) {
|
|
1922
|
+
__${t}_debug "Completing equal sign flag"
|
|
1923
|
+
# Remove the flag part
|
|
1924
|
+
$Flag, $WordToComplete = $WordToComplete.Split("=", 2)
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
if ( $WordToComplete -eq "" -And ( -Not $IsEqualFlag )) {
|
|
1928
|
+
# If the last parameter is complete (there is a space following it)
|
|
1929
|
+
# We add an extra empty parameter so we can indicate this to the go method.
|
|
1930
|
+
__${t}_debug "Adding extra empty parameter"
|
|
1931
|
+
# PowerShell 7.2+ changed the way how the arguments are passed to executables,
|
|
1932
|
+
# so for pre-7.2 or when Legacy argument passing is enabled we need to use
|
|
1933
|
+
if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or
|
|
1934
|
+
($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -or
|
|
1935
|
+
(($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -and
|
|
1936
|
+
$PSNativeCommandArgumentPassing -eq 'Legacy')) {
|
|
1937
|
+
$RequestComp="$RequestComp" + ' \`"\`"'
|
|
1938
|
+
} else {
|
|
1939
|
+
$RequestComp = "$RequestComp" + ' ""'
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
__${t}_debug "Calling $RequestComp"
|
|
1944
|
+
# First disable ActiveHelp which is not supported for Powershell
|
|
1945
|
+
$env:ActiveHelp = 0
|
|
1946
|
+
|
|
1947
|
+
# call the command store the output in $out and redirect stderr and stdout to null
|
|
1948
|
+
# $Out is an array contains each line per element
|
|
1949
|
+
Invoke-Expression -OutVariable out "$RequestComp" 2>&1 | Out-Null
|
|
1950
|
+
|
|
1951
|
+
# get directive from last line
|
|
1952
|
+
[int]$Directive = $Out[-1].TrimStart(':')
|
|
1953
|
+
if ($Directive -eq "") {
|
|
1954
|
+
# There is no directive specified
|
|
1955
|
+
$Directive = 0
|
|
1956
|
+
}
|
|
1957
|
+
__${t}_debug "The completion directive is: $Directive"
|
|
1958
|
+
|
|
1959
|
+
# remove directive (last element) from out
|
|
1960
|
+
$Out = $Out | Where-Object { $_ -ne $Out[-1] }
|
|
1961
|
+
__${t}_debug "The completions are: $Out"
|
|
1962
|
+
|
|
1963
|
+
if (($Directive -band $ShellCompDirectiveError) -ne 0 ) {
|
|
1964
|
+
# Error code. No completion.
|
|
1965
|
+
__${t}_debug "Received error from custom completion go code"
|
|
1966
|
+
return
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
$Longest = 0
|
|
1970
|
+
[Array]$Values = $Out | ForEach-Object {
|
|
1971
|
+
# Split the output in name and description
|
|
1972
|
+
$Name, $Description = $_.Split("\`t", 2)
|
|
1973
|
+
__${t}_debug "Name: $Name Description: $Description"
|
|
1974
|
+
|
|
1975
|
+
# Look for the longest completion so that we can format things nicely
|
|
1976
|
+
if ($Longest -lt $Name.Length) {
|
|
1977
|
+
$Longest = $Name.Length
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
# Set the description to a one space string if there is none set.
|
|
1981
|
+
# This is needed because the CompletionResult does not accept an empty string as argument
|
|
1982
|
+
if (-Not $Description) {
|
|
1983
|
+
$Description = " "
|
|
1984
|
+
}
|
|
1985
|
+
@{ Name = "$Name"; Description = "$Description" }
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
|
|
1989
|
+
$Space = " "
|
|
1990
|
+
if (($Directive -band $ShellCompDirectiveNoSpace) -ne 0 ) {
|
|
1991
|
+
# remove the space here
|
|
1992
|
+
__${t}_debug "ShellCompDirectiveNoSpace is called"
|
|
1993
|
+
$Space = ""
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
if ((($Directive -band $ShellCompDirectiveFilterFileExt) -ne 0 ) -or
|
|
1997
|
+
(($Directive -band $ShellCompDirectiveFilterDirs) -ne 0 )) {
|
|
1998
|
+
__${t}_debug "ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported"
|
|
1999
|
+
|
|
2000
|
+
# return here to prevent the completion of the extensions
|
|
2001
|
+
return
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
$Values = $Values | Where-Object {
|
|
2005
|
+
# filter the result
|
|
2006
|
+
$_.Name -like "$WordToComplete*"
|
|
2007
|
+
|
|
2008
|
+
# Join the flag back if we have an equal sign flag
|
|
2009
|
+
if ( $IsEqualFlag ) {
|
|
2010
|
+
__${t}_debug "Join the equal sign flag back to the completion value"
|
|
2011
|
+
$_.Name = $Flag + "=" + $_.Name
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
# we sort the values in ascending order by name if keep order isn't passed
|
|
2016
|
+
if (($Directive -band $ShellCompDirectiveKeepOrder) -eq 0 ) {
|
|
2017
|
+
$Values = $Values | Sort-Object -Property Name
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) {
|
|
2021
|
+
__${t}_debug "ShellCompDirectiveNoFileComp is called"
|
|
2022
|
+
|
|
2023
|
+
if ($Values.Length -eq 0) {
|
|
2024
|
+
# Just print an empty string here so the
|
|
2025
|
+
# shell does not start to complete paths.
|
|
2026
|
+
# We cannot use CompletionResult here because
|
|
2027
|
+
# it does not accept an empty string as argument.
|
|
2028
|
+
""
|
|
2029
|
+
return
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
# Get the current mode
|
|
2034
|
+
$Mode = (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Tab" }).Function
|
|
2035
|
+
__${t}_debug "Mode: $Mode"
|
|
2036
|
+
|
|
2037
|
+
$Values | ForEach-Object {
|
|
2038
|
+
|
|
2039
|
+
# store temporary because switch will overwrite $_
|
|
2040
|
+
$comp = $_
|
|
2041
|
+
|
|
2042
|
+
# PowerShell supports three different completion modes
|
|
2043
|
+
# - TabCompleteNext (default windows style - on each key press the next option is displayed)
|
|
2044
|
+
# - Complete (works like bash)
|
|
2045
|
+
# - MenuComplete (works like zsh)
|
|
2046
|
+
# You set the mode with Set-PSReadLineKeyHandler -Key Tab -Function <mode>
|
|
2047
|
+
|
|
2048
|
+
# CompletionResult Arguments:
|
|
2049
|
+
# 1) CompletionText text to be used as the auto completion result
|
|
2050
|
+
# 2) ListItemText text to be displayed in the suggestion list
|
|
2051
|
+
# 3) ResultType type of completion result
|
|
2052
|
+
# 4) ToolTip text for the tooltip with details about the object
|
|
2053
|
+
|
|
2054
|
+
switch ($Mode) {
|
|
2055
|
+
|
|
2056
|
+
# bash like
|
|
2057
|
+
"Complete" {
|
|
2058
|
+
|
|
2059
|
+
if ($Values.Length -eq 1) {
|
|
2060
|
+
__${t}_debug "Only one completion left"
|
|
2061
|
+
|
|
2062
|
+
# insert space after value
|
|
2063
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${t}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
2064
|
+
|
|
2065
|
+
} else {
|
|
2066
|
+
# Add the proper number of spaces to align the descriptions
|
|
2067
|
+
while($comp.Name.Length -lt $Longest) {
|
|
2068
|
+
$comp.Name = $comp.Name + " "
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
# Check for empty description and only add parentheses if needed
|
|
2072
|
+
if ($($comp.Description) -eq " " ) {
|
|
2073
|
+
$Description = ""
|
|
2074
|
+
} else {
|
|
2075
|
+
$Description = " ($($comp.Description))"
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
[System.Management.Automation.CompletionResult]::new("$($comp.Name)$Description", "$($comp.Name)$Description", 'ParameterValue', "$($comp.Description)")
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
# zsh like
|
|
2083
|
+
"MenuComplete" {
|
|
2084
|
+
# insert space after value
|
|
2085
|
+
# MenuComplete will automatically show the ToolTip of
|
|
2086
|
+
# the highlighted value at the bottom of the suggestions.
|
|
2087
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${t}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
# TabCompleteNext and in case we get something unknown
|
|
2091
|
+
Default {
|
|
2092
|
+
# Like MenuComplete but we don't want to add a space here because
|
|
2093
|
+
# the user need to press space anyway to get the completion.
|
|
2094
|
+
# Description will not be shown because that's not possible with TabCompleteNext
|
|
2095
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${t}_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
Register-ArgumentCompleter -CommandName '${t}' -ScriptBlock $__${r}CompleterBlock
|
|
2103
|
+
`}
|
|
2104
|
+
|
|
2105
|
+
function e(e=`cli`){if(process.argv.indexOf(`--`)===-1){let t=`Error: You need to use -- to separate completion arguments.\nExample: ${e} complete -- <args>`;console.error(t),process.exit(1);}}
|
|
2106
|
+
|
|
2107
|
+
const o=process.execPath,s=process.argv.slice(1),c=f(o),l=s.map(f),u=`${c} ${process.execArgv.map(f).join(` `)} ${l[0]}`,d=/<[^>]+>|\[[^\]]+\]/;function f(e){return e.includes(` `)?`'${e}'`:e}async function p(c,l){for(let e of [c.globalCommand,...c.commands]){if(e.name===`complete`)continue;let t=(e.rawName.match(/\[.*?\]|<.*?>/g)||[]).map(e=>e.startsWith(`[`)),n=e.name===`@@global@@`,r=n?l:l?.subCommands?.[e.name],a=n?``:e.name,o=n?u$1:u$1.command(a,e.description||``);if(o){let n=(e.rawName.match(/<([^>]+)>|\[\.\.\.([^\]]+)\]/g)||[]).map(e=>e.startsWith(`<`)&&e.endsWith(`>`)?e.slice(1,-1):e.startsWith(`[...`)&&e.endsWith(`]`)?e.slice(4,-1):e);t.forEach((e,t)=>{let i=n[t]||`arg${t}`,a=r?.args?.[i];a?o.argument(i,a,e):o.argument(i,void 0,e);});}for(let t of [...c.globalCommand.options,...e.options]){let e=t.rawName.match(/^-([a-zA-Z]), --/)?.[1],a=t.name,s=n?u$1:o;if(s){let n=r?.options?.[a],i=t.required||d.test(t.rawName);n?e?s.option(a,t.description||``,n,e):s.option(a,t.description||``,n):i?e?s.option(a,t.description||``,async()=>[],e):s.option(a,t.description||``,async()=>[]):e?s.option(a,t.description||``,e):s.option(a,t.description||``);}}}return c.command(`complete [shell]`).action(async(l,d)=>{switch(l){case `zsh`:{let t$1=t(c.name,u);console.log(t$1);break}case `bash`:{let e=n(c.name,u);console.log(e);break}case `fish`:{let e=r(c.name,u);console.log(e);break}case `powershell`:{let e=i(c.name,u);console.log(e);break}default:{e(c.name);let e$1=d[`--`]||[];return c.showHelpOnExit=false,c.unsetMatchedCommand(),c.parse([o,s[0],...e$1],{run:false}),u$1.parse(e$1)}}}),u$1}
|
|
2108
|
+
|
|
2109
|
+
async function setupTabCompletions(cli) {
|
|
2110
|
+
await p(cli, {
|
|
2111
|
+
subCommands: {},
|
|
2112
|
+
options: {
|
|
2113
|
+
environment(complete) {
|
|
2114
|
+
complete("node", "Node.js environment");
|
|
2115
|
+
complete("jsdom", "JSDOM environment");
|
|
2116
|
+
complete("happy-dom", "Happy DOM environment");
|
|
2117
|
+
complete("edge-runtime", "Edge runtime environment");
|
|
2118
|
+
},
|
|
2119
|
+
pool(complete) {
|
|
2120
|
+
complete("threads", "Threads pool");
|
|
2121
|
+
complete("forks", "Forks pool");
|
|
2122
|
+
complete("vmThreads", "VM threads pool");
|
|
2123
|
+
complete("vmForks", "VM forks pool");
|
|
2124
|
+
},
|
|
2125
|
+
reporter(complete) {
|
|
2126
|
+
complete("default", "Default reporter");
|
|
2127
|
+
complete("verbose", "Verbose reporter");
|
|
2128
|
+
complete("dot", "Dot reporter");
|
|
2129
|
+
complete("json", "JSON reporter");
|
|
2130
|
+
complete("junit", "JUnit reporter");
|
|
2131
|
+
complete("html", "HTML reporter");
|
|
2132
|
+
complete("tap", "TAP reporter");
|
|
2133
|
+
complete("tap-flat", "TAP flat reporter");
|
|
2134
|
+
complete("hanging-process", "Hanging process reporter");
|
|
2135
|
+
},
|
|
2136
|
+
"coverage.reporter": function(complete) {
|
|
2137
|
+
complete("text", "Text coverage reporter");
|
|
2138
|
+
complete("html", "HTML coverage reporter");
|
|
2139
|
+
complete("clover", "Clover coverage reporter");
|
|
2140
|
+
complete("json", "JSON coverage reporter");
|
|
2141
|
+
complete("json-summary", "JSON summary coverage reporter");
|
|
2142
|
+
complete("lcov", "LCOV coverage reporter");
|
|
2143
|
+
complete("lcovonly", "LCOV only coverage reporter");
|
|
2144
|
+
complete("teamcity", "TeamCity coverage reporter");
|
|
2145
|
+
complete("cobertura", "Cobertura coverage reporter");
|
|
2146
|
+
},
|
|
2147
|
+
"browser.name": function(complete) {
|
|
2148
|
+
complete("chromium", "Chromium");
|
|
2149
|
+
complete("firefox", "Mozilla Firefox");
|
|
2150
|
+
complete("safari", "Safari");
|
|
2151
|
+
complete("chrome", "Google Chrome");
|
|
2152
|
+
complete("edge", "Microsoft Edge");
|
|
2153
|
+
},
|
|
2154
|
+
silent(complete) {
|
|
2155
|
+
complete("true", "Enable silent mode");
|
|
2156
|
+
complete("false", "Disable silent mode");
|
|
2157
|
+
complete("passed-only", "Show logs from failing tests only");
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
|
|
1208
2163
|
function addCommand(cli, name, option) {
|
|
1209
2164
|
const commandName = option.alias || name;
|
|
1210
2165
|
let command = option.shorthand ? `-${option.shorthand}, --${commandName}` : `--${commandName}`;
|
|
@@ -1287,6 +2242,7 @@ function createCLI(options = {}) {
|
|
|
1287
2242
|
cli.command("init <project>", void 0, options).action(init);
|
|
1288
2243
|
addCliOptions(cli.command("list [...filters]", void 0, options).action((filters, options) => collect("test", filters, options)), collectCliOptionsConfig);
|
|
1289
2244
|
cli.command("[...filters]", void 0, options).action((filters, options) => start("test", filters, options));
|
|
2245
|
+
setupTabCompletions(cli);
|
|
1290
2246
|
return cli;
|
|
1291
2247
|
}
|
|
1292
2248
|
function removeQuotes(str) {
|
|
@@ -1338,7 +2294,7 @@ async function run(cliFilters, options) {
|
|
|
1338
2294
|
await start("test", cliFilters, options);
|
|
1339
2295
|
}
|
|
1340
2296
|
async function benchmark(cliFilters, options) {
|
|
1341
|
-
console.warn(c.yellow("Benchmarking is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it."));
|
|
2297
|
+
console.warn(c$2.yellow("Benchmarking is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it."));
|
|
1342
2298
|
await start("benchmark", cliFilters, options);
|
|
1343
2299
|
}
|
|
1344
2300
|
function normalizeCliOptions(cliFilters, argv) {
|
|
@@ -1348,7 +2304,7 @@ function normalizeCliOptions(cliFilters, argv) {
|
|
|
1348
2304
|
}
|
|
1349
2305
|
if (cliFilters.some((filter) => filter.includes(":"))) argv.includeTaskLocation ??= true;
|
|
1350
2306
|
if (typeof argv.typecheck?.only === "boolean") argv.typecheck.enabled ??= true;
|
|
1351
|
-
if (argv.clearCache) {
|
|
2307
|
+
if (argv.clearCache || argv.listTags) {
|
|
1352
2308
|
argv.watch = false;
|
|
1353
2309
|
argv.run = true;
|
|
1354
2310
|
}
|
|
@@ -1356,11 +2312,11 @@ function normalizeCliOptions(cliFilters, argv) {
|
|
|
1356
2312
|
}
|
|
1357
2313
|
async function start(mode, cliFilters, options) {
|
|
1358
2314
|
try {
|
|
1359
|
-
const { startVitest } = await import('./cli-api.
|
|
2315
|
+
const { startVitest } = await import('./cli-api.DuT9iuvY.js').then(function (n) { return n.q; });
|
|
1360
2316
|
const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
|
|
1361
2317
|
if (!ctx.shouldKeepServer()) await ctx.exit();
|
|
1362
2318
|
} catch (e) {
|
|
1363
|
-
const { errorBanner } = await import('./index.
|
|
2319
|
+
const { errorBanner } = await import('./index.DXMFO5MJ.js').then(function (n) { return n.C; });
|
|
1364
2320
|
console.error(`\n${errorBanner("Startup Error")}`);
|
|
1365
2321
|
console.error(e);
|
|
1366
2322
|
console.error("\n\n");
|
|
@@ -1373,19 +2329,22 @@ async function init(project) {
|
|
|
1373
2329
|
console.error(/* @__PURE__ */ new Error("Only the \"browser\" project is supported. Use \"vitest init browser\" to create a new project."));
|
|
1374
2330
|
process.exit(1);
|
|
1375
2331
|
}
|
|
1376
|
-
const { create } = await import('./creator.
|
|
2332
|
+
const { create } = await import('./creator.DgVhQm5q.js');
|
|
1377
2333
|
await create();
|
|
1378
2334
|
}
|
|
1379
2335
|
async function collect(mode, cliFilters, options) {
|
|
1380
2336
|
try {
|
|
1381
|
-
const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.
|
|
2337
|
+
const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.DuT9iuvY.js').then(function (n) { return n.q; });
|
|
1382
2338
|
const ctx = await prepareVitest(mode, {
|
|
1383
2339
|
...normalizeCliOptions(cliFilters, options),
|
|
1384
2340
|
watch: false,
|
|
1385
2341
|
run: true
|
|
1386
2342
|
}, void 0, void 0, cliFilters);
|
|
1387
2343
|
if (!options.filesOnly) {
|
|
1388
|
-
const { testModules: tests, unhandledErrors: errors } = await ctx.collect(cliFilters.map(normalize)
|
|
2344
|
+
const { testModules: tests, unhandledErrors: errors } = await ctx.collect(cliFilters.map(normalize), {
|
|
2345
|
+
staticParse: options.staticParse,
|
|
2346
|
+
staticParseConcurrency: options.staticParseConcurrency
|
|
2347
|
+
});
|
|
1389
2348
|
if (errors.length) {
|
|
1390
2349
|
console.error("\nThere were unhandled errors during test collection");
|
|
1391
2350
|
errors.forEach((e) => console.error(e));
|
|
@@ -1397,7 +2356,7 @@ async function collect(mode, cliFilters, options) {
|
|
|
1397
2356
|
} else outputFileList(await ctx.getRelevantTestSpecifications(cliFilters.map(normalize)), options);
|
|
1398
2357
|
await ctx.close();
|
|
1399
2358
|
} catch (e) {
|
|
1400
|
-
const { errorBanner } = await import('./index.
|
|
2359
|
+
const { errorBanner } = await import('./index.DXMFO5MJ.js').then(function (n) { return n.C; });
|
|
1401
2360
|
console.error(`\n${errorBanner("Collect Error")}`);
|
|
1402
2361
|
console.error(e);
|
|
1403
2362
|
console.error("\n\n");
|