[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

perf: reduce the number of unused imports (#8508)

authored by

Vladimir and committed by
GitHub
(Sep 8, 2025, 7:20 PM +0200) 9a79b90c 2e491895

+629 -549
+28 -41
pnpm-lock.yaml
··· 13 13 specifier: ^1.2.9 14 14 version: 1.2.9 15 15 '@jridgewell/trace-mapping': 16 - specifier: ^0.3.30 16 + specifier: 0.3.30 17 17 version: 0.3.30 18 18 '@types/chai': 19 19 specifier: ^5.2.2 ··· 103 103 specifier: ^0.2.15 104 104 version: 0.2.15 105 105 tinyrainbow: 106 - specifier: ^2.0.0 107 - version: 2.0.0 106 + specifier: ^3.0.3 107 + version: 3.0.3 108 108 unocss: 109 109 specifier: ^66.5.1 110 110 version: 66.5.1 ··· 464 464 version: 3.0.2 465 465 tinyrainbow: 466 466 specifier: 'catalog:' 467 - version: 2.0.0 467 + version: 3.0.3 468 468 ws: 469 469 specifier: 'catalog:' 470 470 version: 8.18.3 ··· 537 537 version: 0.3.5 538 538 tinyrainbow: 539 539 specifier: 'catalog:' 540 - version: 2.0.0 540 + version: 3.0.3 541 541 devDependencies: 542 542 '@types/debug': 543 543 specifier: 'catalog:' ··· 598 598 version: 3.9.0 599 599 tinyrainbow: 600 600 specifier: 'catalog:' 601 - version: 2.0.0 601 + version: 3.0.3 602 602 devDependencies: 603 603 '@types/debug': 604 604 specifier: 'catalog:' ··· 641 641 version: 6.0.1 642 642 tinyrainbow: 643 643 specifier: 'catalog:' 644 - version: 2.0.0 644 + version: 3.0.3 645 645 devDependencies: 646 646 '@vitest/runner': 647 647 specifier: workspace:* ··· 682 682 dependencies: 683 683 tinyrainbow: 684 684 specifier: 'catalog:' 685 - version: 2.0.0 685 + version: 3.0.3 686 686 devDependencies: 687 687 '@types/react-is': 688 688 specifier: ^19.0.0 ··· 702 702 pathe: 703 703 specifier: 'catalog:' 704 704 version: 2.0.3 705 - strip-literal: 706 - specifier: 'catalog:' 707 - version: 3.0.0 708 705 709 706 packages/snapshot: 710 707 dependencies: ··· 752 749 version: 0.2.15 753 750 tinyrainbow: 754 751 specifier: 'catalog:' 755 - version: 2.0.0 752 + version: 3.0.3 756 753 vitest: 757 754 specifier: workspace:* 758 755 version: link:../vitest ··· 856 853 '@vitest/pretty-format': 857 854 specifier: workspace:* 858 855 version: link:../pretty-format 859 - loupe: 860 - specifier: ^3.2.1 861 - version: 3.2.1 862 856 tinyrainbow: 863 857 specifier: 'catalog:' 864 - version: 2.0.0 858 + version: 3.0.3 865 859 devDependencies: 866 860 '@jridgewell/trace-mapping': 867 861 specifier: 'catalog:' ··· 872 866 diff-sequences: 873 867 specifier: ^29.6.3 874 868 version: 29.6.3 869 + loupe: 870 + specifier: ^3.2.1 871 + version: 3.2.1 875 872 tinyhighlight: 876 873 specifier: ^0.3.2 877 874 version: 0.3.2(picocolors@1.1.1) ··· 902 899 version: 4.1.12 903 900 tinyrainbow: 904 901 specifier: 'catalog:' 905 - version: 2.0.0 902 + version: 3.0.3 906 903 907 904 packages/vitest: 908 905 dependencies: ··· 968 965 version: 2.0.0 969 966 tinyrainbow: 970 967 specifier: 'catalog:' 971 - version: 2.0.0 968 + version: 3.0.3 972 969 vite: 973 970 specifier: ^6.3.5 974 971 version: 6.3.5(@types/node@22.18.1)(jiti@2.5.1)(lightningcss@1.30.1)(sass-embedded@1.92.1)(sass@1.92.1)(terser@5.36.0)(tsx@4.20.5)(yaml@2.8.1) ··· 982 979 '@edge-runtime/vm': 983 980 specifier: ^5.0.0 984 981 version: 5.0.0 982 + '@jridgewell/trace-mapping': 983 + specifier: 'catalog:' 984 + version: 0.3.30 985 985 '@sinonjs/fake-timers': 986 986 specifier: 14.0.0 987 987 version: 14.0.0(patch_hash=6f7091fcf11165157b4bfb8dde6b5b6b7697e3efd6e9b53bb4bdef442f60a278) ··· 1259 1259 version: 0.3.0 1260 1260 tinyrainbow: 1261 1261 specifier: 'catalog:' 1262 - version: 2.0.0 1262 + version: 3.0.3 1263 1263 tinyspy: 1264 1264 specifier: ^4.0.3 1265 1265 version: 4.0.3 ··· 1431 1431 version: 0.3.2 1432 1432 tinyrainbow: 1433 1433 specifier: 'catalog:' 1434 - version: 2.0.0 1434 + version: 3.0.3 1435 1435 vite: 1436 1436 specifier: ^6.3.5 1437 1437 version: 6.3.5(@types/node@22.18.1)(jiti@2.5.1)(lightningcss@1.30.1)(sass-embedded@1.92.1)(sass@1.92.1)(terser@5.36.0)(tsx@4.20.5)(yaml@2.8.1) ··· 2967 2967 '@jridgewell/source-map@0.3.6': 2968 2968 resolution: {integrity: sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==} 2969 2969 2970 - '@jridgewell/sourcemap-codec@1.5.0': 2971 - resolution: {integrity: sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==} 2972 - 2973 2970 '@jridgewell/sourcemap-codec@1.5.5': 2974 2971 resolution: {integrity: sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==} 2975 - 2976 - '@jridgewell/trace-mapping@0.3.29': 2977 - resolution: {integrity: sha512-uw6guiW/gcAGPDhLmd77/6lW8QLeiV5RUTsAX46Db6oLhGaVj4lhnPwb184s1bkc8kdVg/+h988dro8GRDpmYQ==} 2978 2972 2979 2973 '@jridgewell/trace-mapping@0.3.30': 2980 2974 resolution: {integrity: sha512-GQ7Nw5G2lTu/BtHTKfXhKHok2WGetd4XYcVKGx00SjAk8GMwgJM3zr6zORiPGuOE+/vkc90KtTosSSvaCjKb2Q==} ··· 8332 8326 superagent@8.1.2: 8333 8327 resolution: {integrity: sha512-6WTxW1EB6yCxV5VFOIPQruWGHqc3yI7hEmZK6h+pyk69Lk/Ut7rLUY6W/ONF2MjBuGjvmMiIpsrVJ2vjrHlslA==} 8334 8328 engines: {node: '>=6.4.0 <13 || >=14'} 8335 - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net 8329 + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net 8336 8330 8337 8331 superjson@2.2.2: 8338 8332 resolution: {integrity: sha512-5JRxVqC8I8NuOUjzBbvVJAKNM8qoVuH0O77h4WInc/qC2q5IreqKxYwgkga3PfA22OayK2ikceb/B26dztPl+Q==} ··· 8444 8438 resolution: {integrity: sha512-/RX9RzeH2xU5ADE7n2Ykvmi9ED3FBGPAjw9u3zucrNNaEBIO0HPSYgL0NT7+3p147ojeSdaVu08F6hjpv31HJg==} 8445 8439 engines: {node: ^20.0.0 || >=22.0.0} 8446 8440 8447 - tinyrainbow@2.0.0: 8448 - resolution: {integrity: sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==} 8441 + tinyrainbow@3.0.3: 8442 + resolution: {integrity: sha512-PSkbLUoxOFRzJYjjxHJt9xro7D+iilgMX/C9lawzVuYiIdcihh9DXmVibBe8lmcFrRi/VzlPjBxbN7rH24q8/Q==} 8449 8443 engines: {node: '>=14.0.0'} 8450 8444 8451 8445 tinyspy@4.0.3: ··· 10767 10761 '@jridgewell/remapping@2.3.5': 10768 10762 dependencies: 10769 10763 '@jridgewell/gen-mapping': 0.3.12 10770 - '@jridgewell/trace-mapping': 0.3.29 10764 + '@jridgewell/trace-mapping': 0.3.30 10771 10765 10772 10766 '@jridgewell/resolve-uri@3.1.1': {} 10773 10767 ··· 10776 10770 '@jridgewell/gen-mapping': 0.3.12 10777 10771 '@jridgewell/trace-mapping': 0.3.30 10778 10772 10779 - '@jridgewell/sourcemap-codec@1.5.0': {} 10780 - 10781 10773 '@jridgewell/sourcemap-codec@1.5.5': {} 10782 - 10783 - '@jridgewell/trace-mapping@0.3.29': 10784 - dependencies: 10785 - '@jridgewell/resolve-uri': 3.1.1 10786 - '@jridgewell/sourcemap-codec': 1.5.5 10787 10774 10788 10775 '@jridgewell/trace-mapping@0.3.30': 10789 10776 dependencies: 10790 10777 '@jridgewell/resolve-uri': 3.1.1 10791 - '@jridgewell/sourcemap-codec': 1.5.0 10778 + '@jridgewell/sourcemap-codec': 1.5.5 10792 10779 10793 10780 '@jsonjoy.com/base64@1.1.2(tslib@2.8.1)': 10794 10781 dependencies: ··· 14645 14632 14646 14633 istanbul-lib-source-maps@5.0.6: 14647 14634 dependencies: 14648 - '@jridgewell/trace-mapping': 0.3.29 14635 + '@jridgewell/trace-mapping': 0.3.30 14649 14636 debug: 4.4.1 14650 14637 istanbul-lib-coverage: 3.2.2 14651 14638 transitivePeerDependencies: ··· 14971 14958 14972 14959 magic-string@0.30.17: 14973 14960 dependencies: 14974 - '@jridgewell/sourcemap-codec': 1.5.0 14961 + '@jridgewell/sourcemap-codec': 1.5.5 14975 14962 14976 14963 magic-string@0.30.19: 14977 14964 dependencies: ··· 16919 16906 16920 16907 tinypool@2.0.0: {} 16921 16908 16922 - tinyrainbow@2.0.0: {} 16909 + tinyrainbow@3.0.3: {} 16923 16910 16924 16911 tinyspy@4.0.3: {} 16925 16912
+3 -2
pnpm-workspace.yaml
··· 4 4 - examples/* 5 5 - test/* 6 6 - test/config/fixtures/conditions-pkg 7 + 7 8 catalog: 8 9 '@iconify-json/carbon': ^1.2.13 9 10 '@iconify-json/logos': ^1.2.9 10 11 '@jridgewell/remapping': ^2.3.5 11 - '@jridgewell/trace-mapping': ^0.3.30 12 + '@jridgewell/trace-mapping': 0.3.30 12 13 '@types/chai': ^5.2.2 13 14 '@types/debug': ^4.1.12 14 15 '@types/estree': ^1.0.8 ··· 40 41 strip-literal: ^3.0.0 41 42 test-exclude: ^7.0.1 42 43 tinyglobby: ^0.2.15 43 - tinyrainbow: ^2.0.0 44 + tinyrainbow: ^3.0.3 44 45 unocss: ^66.5.1 45 46 unplugin-vue-components: ^0.28.0 46 47 vue: ^3.5.21
+14 -3
packages/pretty-format/rollup.config.js
··· 27 27 preferBuiltins: true, 28 28 }), 29 29 json(), 30 - oxc({ 31 - transform: { target: 'node14' }, 32 - }), 30 + { 31 + name: 'process-env', 32 + transform(code) { 33 + // inline is-react 34 + if (code.includes('process.env.NODE_ENV')) { 35 + return code.replace(/process\.env\.NODE_ENV/g, '"production"') 36 + } 37 + }, 38 + }, 33 39 commonjs(), 40 + oxc({ 41 + transform: { 42 + target: 'node18', 43 + }, 44 + }), 34 45 ] 35 46 36 47 export default defineConfig([
+1 -2
packages/runner/package.json
··· 43 43 }, 44 44 "dependencies": { 45 45 "@vitest/utils": "workspace:*", 46 - "pathe": "catalog:", 47 - "strip-literal": "catalog:" 46 + "pathe": "catalog:" 48 47 } 49 48 }
+25 -1
packages/utils/package.json
··· 36 36 "types": "./dist/helpers.d.ts", 37 37 "default": "./dist/helpers.js" 38 38 }, 39 + "./offset": { 40 + "types": "./dist/offset.d.ts", 41 + "default": "./dist/offset.js" 42 + }, 43 + "./constants": { 44 + "types": "./dist/constants.d.ts", 45 + "default": "./dist/constants.js" 46 + }, 47 + "./timers": { 48 + "types": "./dist/timers.d.ts", 49 + "default": "./dist/timers.js" 50 + }, 51 + "./display": { 52 + "types": "./dist/display.d.ts", 53 + "default": "./dist/display.js" 54 + }, 55 + "./highlight": { 56 + "types": "./dist/highlight.d.ts", 57 + "default": "./dist/highlight.js" 58 + }, 39 59 "./source-map": { 40 60 "types": "./dist/source-map.d.ts", 41 61 "default": "./dist/source-map.js" 62 + }, 63 + "./serialize": { 64 + "types": "./dist/serialize.d.ts", 65 + "default": "./dist/serialize.js" 42 66 }, 43 67 "./*": "./*" 44 68 }, ··· 62 86 }, 63 87 "dependencies": { 64 88 "@vitest/pretty-format": "workspace:*", 65 - "loupe": "^3.2.1", 66 89 "tinyrainbow": "catalog:" 67 90 }, 68 91 "devDependencies": { 69 92 "@jridgewell/trace-mapping": "catalog:", 70 93 "@types/estree": "catalog:", 71 94 "diff-sequences": "^29.6.3", 95 + "loupe": "^3.2.1", 72 96 "tinyhighlight": "^0.3.2" 73 97 } 74 98 }
+14
packages/utils/rollup.config.js
··· 16 16 'error': 'src/error.ts', 17 17 'source-map': 'src/source-map.ts', 18 18 'types': 'src/types.ts', 19 + 'constants': 'src/constants.ts', 20 + 'offset': 'src/offset.ts', 21 + 'timers': 'src/timers.ts', 22 + 'highlight': 'src/highlight.ts', 23 + 'display': 'src/display.ts', 19 24 'resolver': 'src/resolver.ts', 25 + 'serialize': 'src/serialize.ts', 20 26 } 21 27 22 28 const external = [ ··· 42 48 export default defineConfig([ 43 49 { 44 50 input: entries, 51 + treeshake: { 52 + moduleSideEffects: [ 53 + { 54 + external: true, 55 + sideEffects: false, 56 + }, 57 + ], 58 + }, 45 59 output: { 46 60 dir: 'dist', 47 61 format: 'esm',
+81
packages/vitest/LICENSE.md
··· 57 57 58 58 --------------------------------------- 59 59 60 + ## @jridgewell/resolve-uri 61 + License: MIT 62 + By: Justin Ridgewell 63 + Repository: https://github.com/jridgewell/resolve-uri 64 + 65 + > Copyright 2019 Justin Ridgewell <jridgewell@google.com> 66 + > 67 + > Permission is hereby granted, free of charge, to any person obtaining a copy 68 + > of this software and associated documentation files (the "Software"), to deal 69 + > in the Software without restriction, including without limitation the rights 70 + > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 71 + > copies of the Software, and to permit persons to whom the Software is 72 + > furnished to do so, subject to the following conditions: 73 + > 74 + > The above copyright notice and this permission notice shall be included in 75 + > all copies or substantial portions of the Software. 76 + > 77 + > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 78 + > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 79 + > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 80 + > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 81 + > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 82 + > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 83 + > SOFTWARE. 84 + 85 + --------------------------------------- 86 + 87 + ## @jridgewell/sourcemap-codec 88 + License: MIT 89 + By: Justin Ridgewell 90 + Repository: git+https://github.com/jridgewell/sourcemaps.git 91 + 92 + > Copyright 2024 Justin Ridgewell <justin@ridgewell.name> 93 + > 94 + > Permission is hereby granted, free of charge, to any person obtaining a copy 95 + > of this software and associated documentation files (the "Software"), to deal 96 + > in the Software without restriction, including without limitation the rights 97 + > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 98 + > copies of the Software, and to permit persons to whom the Software is 99 + > furnished to do so, subject to the following conditions: 100 + > 101 + > The above copyright notice and this permission notice shall be included in 102 + > all copies or substantial portions of the Software. 103 + > 104 + > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 105 + > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 106 + > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 107 + > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 108 + > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 109 + > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 110 + > SOFTWARE. 111 + 112 + --------------------------------------- 113 + 114 + ## @jridgewell/trace-mapping 115 + License: MIT 116 + By: Justin Ridgewell 117 + Repository: git+https://github.com/jridgewell/sourcemaps.git 118 + 119 + > Copyright 2024 Justin Ridgewell <justin@ridgewell.name> 120 + > 121 + > Permission is hereby granted, free of charge, to any person obtaining a copy 122 + > of this software and associated documentation files (the "Software"), to deal 123 + > in the Software without restriction, including without limitation the rights 124 + > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 125 + > copies of the Software, and to permit persons to whom the Software is 126 + > furnished to do so, subject to the following conditions: 127 + > 128 + > The above copyright notice and this permission notice shall be included in 129 + > all copies or substantial portions of the Software. 130 + > 131 + > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 132 + > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 133 + > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 134 + > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 135 + > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 136 + > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 137 + > SOFTWARE. 138 + 139 + --------------------------------------- 140 + 60 141 ## @sinonjs/commons 61 142 License: BSD-3-Clause 62 143 Repository: git+https://github.com/sinonjs/commons.git
+1 -4
packages/vitest/package.json
··· 56 56 "types": "./dist/node.d.ts", 57 57 "default": "./dist/node.js" 58 58 }, 59 - "./workers": { 60 - "types": "./dist/workers.d.ts", 61 - "import": "./dist/workers.js" 62 - }, 63 59 "./internal/browser": { 64 60 "types": "./dist/browser.d.ts", 65 61 "default": "./dist/browser.js" ··· 181 177 "devDependencies": { 182 178 "@antfu/install-pkg": "^1.1.0", 183 179 "@edge-runtime/vm": "^5.0.0", 180 + "@jridgewell/trace-mapping": "catalog:", 184 181 "@sinonjs/fake-timers": "14.0.0", 185 182 "@types/debug": "catalog:", 186 183 "@types/estree": "catalog:",
+3 -8
packages/vitest/rollup.config.js
··· 29 29 'spy': 'src/integrations/spy.ts', 30 30 'coverage': 'src/public/coverage.ts', 31 31 'reporters': 'src/public/reporters.ts', 32 - // TODO: advanced docs 33 - 'workers': 'src/public/workers.ts', 34 32 'module-runner': 'src/public/module-runner.ts', 35 33 'module-evaluator': 'src/runtime/moduleRunner/moduleEvaluator.ts', 36 34 37 35 // for performance reasons we bundle them separately so we don't import everything at once 38 - 'worker': 'src/runtime/worker.ts', 39 - 'workers/forks': 'src/runtime/workers/forks.ts', 40 - 'workers/threads': 'src/runtime/workers/threads.ts', 41 - 'workers/vmThreads': 'src/runtime/workers/vmThreads.ts', 42 - 'workers/vmForks': 'src/runtime/workers/vmForks.ts', 36 + 'worker-vm': 'src/runtime/worker-vm.ts', 37 + 'worker-base': 'src/runtime/worker-base.ts', 43 38 44 39 'workers/runVmTests': 'src/runtime/runVmTests.ts', 45 40 ··· 57 52 'coverage': 'src/public/coverage.ts', 58 53 'reporters': 'src/public/reporters.ts', 59 54 'mocker': 'src/public/mocker.ts', 60 - 'workers': 'src/public/workers.ts', 61 55 'snapshot': 'src/public/snapshot.ts', 62 56 'module-evaluator': 'src/runtime/moduleRunner/moduleEvaluator.ts', 63 57 } ··· 86 80 '@vitest/runner/types', 87 81 '@vitest/snapshot/environment', 88 82 '@vitest/snapshot/manager', 83 + /@vitest\/utils\/\w+/, 89 84 90 85 '#module-evaluator', 91 86 ]
-1
packages/vitest/workers.d.ts
··· 1 - export * from './dist/workers.js'
+1
test/browser/package.json
··· 11 11 "test-fixtures": "vitest", 12 12 "test-expect-dom": "vitest --root ./fixtures/expect-dom", 13 13 "test-mocking": "vitest --root ./fixtures/mocking", 14 + "test-logs": "vitest --root ./fixtures/print-logs", 14 15 "test-failing": "vitest --root ./fixtures/failing", 15 16 "test-timeout": "vitest --root ./fixtures/timeout", 16 17 "test-timeout-hooks": "vitest --root ./fixtures/timeout-hooks",
+1 -1
packages/expect/src/jest-expect.ts
··· 4 4 import type { AsymmetricMatcher } from './jest-asymmetric-matchers' 5 5 import type { Assertion, ChaiPlugin } from './types' 6 6 import { isMockFunction } from '@vitest/spy' 7 - import { assertTypes } from '@vitest/utils' 7 + import { assertTypes } from '@vitest/utils/helpers' 8 8 import c from 'tinyrainbow' 9 9 import { JEST_MATCHERS_OBJECT } from './constants' 10 10 import {
+2 -1
packages/expect/src/jest-matcher-utils.ts
··· 1 1 import type { Formatter } from 'tinyrainbow' 2 2 import type { MatcherHintOptions, Tester } from './types' 3 - import { getType, stringify } from '@vitest/utils' 4 3 import { diff, printDiffOrStringify } from '@vitest/utils/diff' 4 + import { stringify } from '@vitest/utils/display' 5 + import { getType } from '@vitest/utils/helpers' 5 6 import c from 'tinyrainbow' 6 7 import { JEST_MATCHERS_OBJECT } from './constants' 7 8
+1 -1
packages/expect/src/jest-utils.ts
··· 23 23 */ 24 24 25 25 import type { Tester, TesterContext } from './types' 26 - import { isObject } from '@vitest/utils' 26 + import { isObject } from '@vitest/utils/helpers' 27 27 28 28 // Extracted out of jasmine 2.5.2 29 29 export function equals(
+1 -1
packages/expect/src/utils.ts
··· 1 1 import type { Test } from '@vitest/runner/types' 2 2 import type { Assertion } from './types' 3 - import { noop } from '@vitest/utils' 4 3 import { processError } from '@vitest/utils/error' 4 + import { noop } from '@vitest/utils/helpers' 5 5 6 6 export function createAssertionMessage( 7 7 util: Chai.ChaiUtils,
+2 -2
packages/runner/src/collect.ts
··· 1 1 import type { FileSpecification, VitestRunner } from './types/runner' 2 2 import type { File, SuiteHooks } from './types/tasks' 3 - import { toArray } from '@vitest/utils' 4 - import { processError } from '@vitest/utils/error' 3 + import { processError } from '@vitest/utils/error' // TODO: load dynamically 4 + import { toArray } from '@vitest/utils/helpers' 5 5 import { collectorContext, setFileContext } from './context' 6 6 import { getHooks, setHooks } from './map' 7 7 import { runSetupFiles } from './setup'
+1 -1
packages/runner/src/context.ts
··· 11 11 TestContext, 12 12 WriteableTestContext, 13 13 } from './types/tasks' 14 - import { getSafeTimers } from '@vitest/utils' 14 + import { getSafeTimers } from '@vitest/utils/timers' 15 15 import { PendingError } from './errors' 16 16 import { finishSendTasksUpdate } from './run' 17 17 import { getRunner } from './suite'
+32 -3
packages/runner/src/fixture.ts
··· 1 1 import type { VitestRunner } from './types' 2 2 import type { FixtureOptions, TestContext } from './types/tasks' 3 - import { createDefer, isObject } from '@vitest/utils' 4 - import { stripLiteral } from 'strip-literal' 3 + import { createDefer, isObject } from '@vitest/utils/helpers' 5 4 import { getFileContext } from './context' 6 5 import { getTestFixture } from './map' 7 6 ··· 339 338 } 340 339 341 340 function getUsedProps(fn: Function) { 342 - let fnString = stripLiteral(fn.toString()) 341 + let fnString = filterOutComments(fn.toString()) 343 342 // match lowered async function and strip it off 344 343 // example code on esbuild-try https://esbuild.github.io/try/#YgAwLjI0LjAALS1zdXBwb3J0ZWQ6YXN5bmMtYXdhaXQ9ZmFsc2UAZQBlbnRyeS50cwBjb25zdCBvID0gewogIGYxOiBhc3luYyAoKSA9PiB7fSwKICBmMjogYXN5bmMgKGEpID0+IHt9LAogIGYzOiBhc3luYyAoYSwgYikgPT4ge30sCiAgZjQ6IGFzeW5jIGZ1bmN0aW9uKGEpIHt9LAogIGY1OiBhc3luYyBmdW5jdGlvbiBmZihhKSB7fSwKICBhc3luYyBmNihhKSB7fSwKCiAgZzE6IGFzeW5jICgpID0+IHt9LAogIGcyOiBhc3luYyAoeyBhIH0pID0+IHt9LAogIGczOiBhc3luYyAoeyBhIH0sIGIpID0+IHt9LAogIGc0OiBhc3luYyBmdW5jdGlvbiAoeyBhIH0pIHt9LAogIGc1OiBhc3luYyBmdW5jdGlvbiBnZyh7IGEgfSkge30sCiAgYXN5bmMgZzYoeyBhIH0pIHt9LAoKICBoMTogYXN5bmMgKCkgPT4ge30sCiAgLy8gY29tbWVudCBiZXR3ZWVuCiAgaDI6IGFzeW5jIChhKSA9PiB7fSwKfQ 345 344 // __async(this, null, function* ··· 385 384 } 386 385 387 386 return props 387 + } 388 + 389 + function filterOutComments(s: string): string { 390 + const result: string[] = [] 391 + let commentState: 'none' | 'singleline' | 'multiline' = 'none' 392 + for (let i = 0; i < s.length; ++i) { 393 + if (commentState === 'singleline') { 394 + if (s[i] === '\n') { 395 + commentState = 'none' 396 + } 397 + } 398 + else if (commentState === 'multiline') { 399 + if (s[i - 1] === '*' && s[i] === '/') { 400 + commentState = 'none' 401 + } 402 + } 403 + else if (commentState === 'none') { 404 + if (s[i] === '/' && s[i + 1] === '/') { 405 + commentState = 'singleline' 406 + } 407 + else if (s[i] === '/' && s[i + 1] === '*') { 408 + commentState = 'multiline' 409 + i += 2 410 + } 411 + else { 412 + result.push(s[i]) 413 + } 414 + } 415 + } 416 + return result.join('') 388 417 } 389 418 390 419 function splitByComma(s: string) {
+1 -1
packages/runner/src/hooks.ts
··· 9 9 TaskPopulated, 10 10 TestContext, 11 11 } from './types/tasks' 12 - import { assertTypes } from '@vitest/utils' 12 + import { assertTypes } from '@vitest/utils/helpers' 13 13 import { abortContextSignal, abortIfTimeout, withTimeout } from './context' 14 14 import { withFixtures } from './fixture' 15 15 import { getCurrentSuite, getRunner } from './suite'
-2
packages/runner/src/index.ts
··· 18 18 } from './suite' 19 19 export { getCurrentTest } from './test-state' 20 20 export type * from './types' 21 - 22 - export { processError } from '@vitest/utils/error'
+3 -2
packages/runner/src/run.ts
··· 17 17 TestContext, 18 18 WriteableTestContext, 19 19 } from './types/tasks' 20 - import { getSafeTimers, shuffle } from '@vitest/utils' 21 - import { processError } from '@vitest/utils/error' 20 + import { processError } from '@vitest/utils/error' // TODO: load dynamically 21 + import { shuffle } from '@vitest/utils/helpers' 22 + import { getSafeTimers } from '@vitest/utils/timers' 22 23 import { collectTests } from './collect' 23 24 import { abortContextSignal, getFileContext } from './context' 24 25 import { PendingError, TestRunAbortError } from './errors'
+2 -3
packages/runner/src/suite.ts
··· 17 17 TestFunction, 18 18 TestOptions, 19 19 } from './types/tasks' 20 + import { format, objDisplay } from '@vitest/utils/display' 20 21 import { 21 - format, 22 22 isNegativeNaN, 23 23 isObject, 24 - objDisplay, 25 24 objectAttr, 26 25 toArray, 27 - } from '@vitest/utils' 26 + } from '@vitest/utils/helpers' 28 27 import { 29 28 abortIfTimeout, 30 29 collectorContext,
+1 -1
packages/runner/src/test-state.ts
··· 1 - import type { Test } from './types/tasks.ts' 1 + import type { Test } from './types/tasks' 2 2 3 3 let _test: Test | undefined 4 4
+1 -1
packages/ui/node/index.ts
··· 2 2 import type { Vitest } from 'vitest/node' 3 3 import fs from 'node:fs' 4 4 import { fileURLToPath } from 'node:url' 5 - import { toArray } from '@vitest/utils' 5 + import { toArray } from '@vitest/utils/helpers' 6 6 import { basename, resolve } from 'pathe' 7 7 import sirv from 'sirv' 8 8 import c from 'tinyrainbow'
-1
packages/utils/src/display.ts
··· 3 3 format as prettyFormat, 4 4 plugins as prettyFormatPlugins, 5 5 } from '@vitest/pretty-format' 6 - // since this is already part of Vitest via Chai, we can just reuse it without increasing the size of bundle 7 6 import * as loupe from 'loupe' 8 7 9 8 type Inspect = (value: unknown, options: Options) => string
+2 -150
packages/utils/src/error.ts
··· 1 1 import type { DiffOptions } from './diff' 2 2 import type { TestError } from './types' 3 3 import { printDiffOrStringify } from './diff' 4 - import { format, stringify } from './display' 5 - 6 - // utils is bundled for any environment and might not support `Element` 7 - declare class Element { 8 - tagName: string 9 - } 10 - 11 - const IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@' 12 - const IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@' 13 - 14 - function isImmutable(v: any) { 15 - return v && (v[IS_COLLECTION_SYMBOL] || v[IS_RECORD_SYMBOL]) 16 - } 17 - 18 - const OBJECT_PROTO = Object.getPrototypeOf({}) 19 - 20 - function getUnserializableMessage(err: unknown) { 21 - if (err instanceof Error) { 22 - return `<unserializable>: ${err.message}` 23 - } 24 - if (typeof err === 'string') { 25 - return `<unserializable>: ${err}` 26 - } 27 - return '<unserializable>' 28 - } 29 - 30 - // https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm 31 - export function serializeValue(val: any, seen: WeakMap<WeakKey, any> = new WeakMap()): any { 32 - if (!val || typeof val === 'string') { 33 - return val 34 - } 35 - if (val instanceof Error && 'toJSON' in val && typeof val.toJSON === 'function') { 36 - const jsonValue = val.toJSON() 37 - 38 - if (jsonValue && jsonValue !== val && typeof jsonValue === 'object') { 39 - if (typeof val.message === 'string') { 40 - safe(() => jsonValue.message ??= val.message) 41 - } 42 - if (typeof val.stack === 'string') { 43 - safe(() => jsonValue.stack ??= val.stack) 44 - } 45 - if (typeof val.name === 'string') { 46 - safe(() => jsonValue.name ??= val.name) 47 - } 48 - if (val.cause != null) { 49 - safe(() => jsonValue.cause ??= serializeValue(val.cause, seen)) 50 - } 51 - } 52 - return serializeValue(jsonValue, seen) 53 - } 54 - if (typeof val === 'function') { 55 - return `Function<${val.name || 'anonymous'}>` 56 - } 57 - if (typeof val === 'symbol') { 58 - return val.toString() 59 - } 60 - if (typeof val !== 'object') { 61 - return val 62 - } 63 - if (typeof Buffer !== 'undefined' && val instanceof Buffer) { 64 - return `<Buffer(${val.length}) ...>` 65 - } 66 - if (typeof Uint8Array !== 'undefined' && val instanceof Uint8Array) { 67 - return `<Uint8Array(${val.length}) ...>` 68 - } 69 - // cannot serialize immutables as immutables 70 - if (isImmutable(val)) { 71 - return serializeValue(val.toJSON(), seen) 72 - } 73 - if ( 74 - val instanceof Promise 75 - || (val.constructor && val.constructor.prototype === 'AsyncFunction') 76 - ) { 77 - return 'Promise' 78 - } 79 - if (typeof Element !== 'undefined' && val instanceof Element) { 80 - return val.tagName 81 - } 82 - if (typeof val.asymmetricMatch === 'function') { 83 - return `${val.toString()} ${format(val.sample)}` 84 - } 85 - if (typeof val.toJSON === 'function') { 86 - return serializeValue(val.toJSON(), seen) 87 - } 88 - 89 - if (seen.has(val)) { 90 - return seen.get(val) 91 - } 92 - 93 - if (Array.isArray(val)) { 94 - // eslint-disable-next-line unicorn/no-new-array -- we need to keep sparse arrays ([1,,3]) 95 - const clone: any[] = new Array(val.length) 96 - seen.set(val, clone) 97 - val.forEach((e, i) => { 98 - try { 99 - clone[i] = serializeValue(e, seen) 100 - } 101 - catch (err) { 102 - clone[i] = getUnserializableMessage(err) 103 - } 104 - }) 105 - return clone 106 - } 107 - else { 108 - // Objects with `Error` constructors appear to cause problems during worker communication 109 - // using `MessagePort`, so the serialized error object is being recreated as plain object. 110 - const clone = Object.create(null) 111 - seen.set(val, clone) 112 - 113 - let obj = val 114 - while (obj && obj !== OBJECT_PROTO) { 115 - Object.getOwnPropertyNames(obj).forEach((key) => { 116 - if (key in clone) { 117 - return 118 - } 119 - try { 120 - clone[key] = serializeValue(val[key], seen) 121 - } 122 - catch (err) { 123 - // delete in case it has a setter from prototype that might throw 124 - delete clone[key] 125 - clone[key] = getUnserializableMessage(err) 126 - } 127 - }) 128 - obj = Object.getPrototypeOf(obj) 129 - } 130 - return clone 131 - } 132 - } 133 - 134 - function safe(fn: () => void) { 135 - try { 136 - return fn() 137 - } 138 - catch { 139 - // ignore 140 - } 141 - } 4 + import { stringify } from './display' 5 + import { serializeValue } from './serialize' 142 6 143 7 export { serializeValue as serializeError } 144 - 145 - function normalizeErrorMessage(message: string) { 146 - return message.replace(/__(vite_ssr_import|vi_import)_\d+__\./g, '') 147 - } 148 8 149 9 export function processError( 150 10 _err: any, ··· 174 34 if ('actual' in err && typeof err.actual !== 'string') { 175 35 err.actual = stringify(err.actual, 10) 176 36 } 177 - 178 - // some Error implementations don't allow rewriting message 179 - try { 180 - if (typeof err.message === 'string') { 181 - err.message = normalizeErrorMessage(err.message) 182 - } 183 - } 184 - catch {} 185 37 186 38 // some Error implementations may not allow rewriting cause 187 39 // in most cases, the assignment will lead to "err.cause = err.cause"
+3 -21
packages/utils/src/helpers.ts
··· 10 10 stackTraceLimit?: number 11 11 } 12 12 13 + export { nanoid } from './nanoid' 14 + export { shuffle } from './random' 15 + 13 16 /** 14 17 * Get original stacktrace without source map support the most performant way. 15 18 * - Create only 1 stack frame. ··· 96 99 97 100 export function isBareImport(id: string): boolean { 98 101 return bareImportRE.test(id) 99 - } 100 - 101 - // convert RegExp.toString to RegExp 102 - export function parseRegexp(input: string): RegExp { 103 - // Parse input 104 - // eslint-disable-next-line regexp/no-misleading-capturing-group 105 - const m = input.match(/(\/?)(.+)\1([a-z]*)/i) 106 - 107 - // match nothing 108 - if (!m) { 109 - return /$^/ 110 - } 111 - 112 - // Invalid flags 113 - // eslint-disable-next-line regexp/optimal-quantifier-concatenation 114 - if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])) { 115 - return new RegExp(input) 116 - } 117 - 118 - // Create the regular expression 119 - return new RegExp(m[2], m[3]) 120 102 } 121 103 122 104 export function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T> {
-52
packages/utils/src/index.ts
··· 1 - export { 2 - CSS_LANGS_RE, 3 - KNOWN_ASSET_RE, 4 - KNOWN_ASSET_TYPES, 5 - NULL_BYTE_PLACEHOLDER, 6 - VALID_ID_PREFIX, 7 - } from './constants' 8 - export { 9 - format, 10 - inspect, 11 - objDisplay, 12 - stringify, 13 - } from './display' 14 1 export type { LoupeOptions, StringifyOptions } from './display' 15 - 16 - export { 17 - assertTypes, 18 - cleanUrl, 19 - clone, 20 - createDefer, 21 - createSimpleStackTrace, 22 - deepClone, 23 - deepMerge, 24 - getCallLastIndex, 25 - getOwnProperties, 26 - getType, 27 - isBareImport, 28 - isExternalUrl, 29 - isNegativeNaN, 30 - isObject, 31 - isPrimitive, 32 - noop, 33 - notNullish, 34 - objectAttr, 35 - parseRegexp, 36 - slash, 37 - toArray, 38 - unwrapId, 39 - withTrailingSlash, 40 - wrapId, 41 - } from './helpers' 42 2 export type { DeferPromise } from './helpers' 43 - 44 - export { highlight } from './highlight' 45 - export { nanoid } from './nanoid' 46 - export { 47 - lineSplitRE, 48 - offsetToLineNumber, 49 - positionToOffset, 50 - } from './offset' 51 - export { shuffle } from './random' 52 - export { getSafeTimers, setSafeTimers } from './timers' 53 - 54 3 export type { SafeTimers } from './timers' 55 - 56 4 export type { 57 5 ArgumentsType, 58 6 Arrayable,
+140
packages/utils/src/serialize.ts
··· 1 + // utils is bundled for any environment and might not support `Element` 2 + declare class Element { 3 + tagName: string 4 + } 5 + 6 + const IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@' 7 + const IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@' 8 + 9 + function isImmutable(v: any) { 10 + return v && (v[IS_COLLECTION_SYMBOL] || v[IS_RECORD_SYMBOL]) 11 + } 12 + 13 + const OBJECT_PROTO = Object.getPrototypeOf({}) 14 + 15 + function getUnserializableMessage(err: unknown) { 16 + if (err instanceof Error) { 17 + return `<unserializable>: ${err.message}` 18 + } 19 + if (typeof err === 'string') { 20 + return `<unserializable>: ${err}` 21 + } 22 + return '<unserializable>' 23 + } 24 + 25 + // https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm 26 + export function serializeValue(val: any, seen: WeakMap<WeakKey, any> = new WeakMap()): any { 27 + if (!val || typeof val === 'string') { 28 + return val 29 + } 30 + if (val instanceof Error && 'toJSON' in val && typeof val.toJSON === 'function') { 31 + const jsonValue = val.toJSON() 32 + 33 + if (jsonValue && jsonValue !== val && typeof jsonValue === 'object') { 34 + if (typeof val.message === 'string') { 35 + safe(() => jsonValue.message ??= normalizeErrorMessage(val.message)) 36 + } 37 + if (typeof val.stack === 'string') { 38 + safe(() => jsonValue.stack ??= val.stack) 39 + } 40 + if (typeof val.name === 'string') { 41 + safe(() => jsonValue.name ??= val.name) 42 + } 43 + if (val.cause != null) { 44 + safe(() => jsonValue.cause ??= serializeValue(val.cause, seen)) 45 + } 46 + } 47 + return serializeValue(jsonValue, seen) 48 + } 49 + if (typeof val === 'function') { 50 + return `Function<${val.name || 'anonymous'}>` 51 + } 52 + if (typeof val === 'symbol') { 53 + return val.toString() 54 + } 55 + if (typeof val !== 'object') { 56 + return val 57 + } 58 + if (typeof Buffer !== 'undefined' && val instanceof Buffer) { 59 + return `<Buffer(${val.length}) ...>` 60 + } 61 + if (typeof Uint8Array !== 'undefined' && val instanceof Uint8Array) { 62 + return `<Uint8Array(${val.length}) ...>` 63 + } 64 + // cannot serialize immutables as immutables 65 + if (isImmutable(val)) { 66 + return serializeValue(val.toJSON(), seen) 67 + } 68 + if ( 69 + val instanceof Promise 70 + || (val.constructor && val.constructor.prototype === 'AsyncFunction') 71 + ) { 72 + return 'Promise' 73 + } 74 + if (typeof Element !== 'undefined' && val instanceof Element) { 75 + return val.tagName 76 + } 77 + if (typeof val.toJSON === 'function') { 78 + return serializeValue(val.toJSON(), seen) 79 + } 80 + 81 + if (seen.has(val)) { 82 + return seen.get(val) 83 + } 84 + 85 + if (Array.isArray(val)) { 86 + // eslint-disable-next-line unicorn/no-new-array -- we need to keep sparse arrays ([1,,3]) 87 + const clone: any[] = new Array(val.length) 88 + seen.set(val, clone) 89 + val.forEach((e, i) => { 90 + try { 91 + clone[i] = serializeValue(e, seen) 92 + } 93 + catch (err) { 94 + clone[i] = getUnserializableMessage(err) 95 + } 96 + }) 97 + return clone 98 + } 99 + else { 100 + // Objects with `Error` constructors appear to cause problems during worker communication 101 + // using `MessagePort`, so the serialized error object is being recreated as plain object. 102 + const clone = Object.create(null) 103 + seen.set(val, clone) 104 + 105 + let obj = val 106 + while (obj && obj !== OBJECT_PROTO) { 107 + Object.getOwnPropertyNames(obj).forEach((key) => { 108 + if (key in clone) { 109 + return 110 + } 111 + try { 112 + clone[key] = serializeValue(val[key], seen) 113 + } 114 + catch (err) { 115 + // delete in case it has a setter from prototype that might throw 116 + delete clone[key] 117 + clone[key] = getUnserializableMessage(err) 118 + } 119 + }) 120 + obj = Object.getPrototypeOf(obj) 121 + } 122 + if (val instanceof Error) { 123 + safe(() => val.message = normalizeErrorMessage(val.message)) 124 + } 125 + return clone 126 + } 127 + } 128 + 129 + function safe(fn: () => void) { 130 + try { 131 + return fn() 132 + } 133 + catch { 134 + // ignore 135 + } 136 + } 137 + 138 + function normalizeErrorMessage(message: string) { 139 + return message.replace(/__(vite_ssr_import|vi_import)_\d+__\./g, '') 140 + }
+76 -27
packages/utils/src/source-map.ts
··· 1 - import type { SourceMapInput } from '@jridgewell/trace-mapping' 1 + import type { OriginalMapping } from '@jridgewell/trace-mapping' 2 2 import type { ParsedStack, TestError } from './types' 3 - import { originalPositionFor, TraceMap } from '@jridgewell/trace-mapping' 3 + import { originalPositionFor } from '@jridgewell/trace-mapping' 4 4 import { resolve } from 'pathe' 5 5 import { isPrimitive, notNullish } from './helpers' 6 - 7 - export { 8 - eachMapping, 9 - type EachMapping, 10 - generatedPositionFor, 11 - originalPositionFor, 12 - TraceMap, 13 - } from '@jridgewell/trace-mapping' 14 - export type { SourceMapInput } from '@jridgewell/trace-mapping' 15 6 16 7 export interface StackTraceParserOptions { 17 8 ignoreStackEntries?: (RegExp | string)[] ··· 237 228 } 238 229 239 230 const map = options.getSourceMap?.(stack.file) as 240 - | SourceMapInput 231 + | SourceMapLike 241 232 | null 242 233 | undefined 243 234 if (!map || typeof map !== 'object' || !map.version) { 244 235 return shouldFilter(ignoreStackEntries, stack.file) ? null : stack 245 236 } 246 237 247 - const traceMap = new TraceMap(map) 248 - const { line, column, source, name } = originalPositionFor(traceMap, stack) 238 + const traceMap = new DecodedMap(map, stack.file) 239 + const position = getOriginalPosition(traceMap, stack) 240 + if (!position) { 241 + return stack 242 + } 249 243 250 - let file: string = stack.file 251 - if (source) { 252 - const fileUrl = stack.file.startsWith('file://') 253 - ? stack.file 254 - : `file://${stack.file}` 255 - const sourceRootUrl = map.sourceRoot 256 - ? new URL(map.sourceRoot, fileUrl) 257 - : fileUrl 258 - file = new URL(source, sourceRootUrl).pathname 259 - // if the file path is on windows, we need to remove the leading slash 260 - if (file.match(/\/\w:\//)) { 261 - file = file.slice(1) 262 - } 244 + const { line, column, source, name } = position 245 + let file = source || stack.file 246 + if (file.match(/\/\w:\//)) { 247 + file = file.slice(1) 263 248 } 264 249 265 250 if (shouldFilter(ignoreStackEntries, file)) { ··· 333 318 334 319 ;(e as TestError).stacks = stackFrames 335 320 return stackFrames 321 + } 322 + 323 + interface SourceMapLike { 324 + version: number 325 + mappings?: string 326 + names?: string[] 327 + sources?: string[] 328 + sourcesContent?: string[] 329 + sourceRoot?: string 330 + } 331 + 332 + interface Needle { 333 + line: number 334 + column: number 335 + } 336 + 337 + export class DecodedMap { 338 + _encoded: string 339 + _decoded: undefined | number[][][] 340 + _decodedMemo: Stats 341 + url: string 342 + version: number 343 + names: string[] = [] 344 + resolvedSources: string[] 345 + 346 + constructor( 347 + public map: SourceMapLike, 348 + from: string, 349 + ) { 350 + const { mappings, names, sources } = map 351 + this.version = map.version 352 + this.names = names || [] 353 + this._encoded = mappings || '' 354 + this._decodedMemo = memoizedState() 355 + this.url = from 356 + this.resolvedSources = (sources || []).map(s => 357 + resolve(s || '', from), 358 + ) 359 + } 360 + } 361 + 362 + interface Stats { 363 + lastKey: number 364 + lastNeedle: number 365 + lastIndex: number 366 + } 367 + 368 + function memoizedState(): Stats { 369 + return { 370 + lastKey: -1, 371 + lastNeedle: -1, 372 + lastIndex: -1, 373 + } 374 + } 375 + 376 + export function getOriginalPosition( 377 + map: DecodedMap, 378 + needle: Needle, 379 + ): OriginalMapping | null { 380 + const result = originalPositionFor(map as any, needle) 381 + if (result.column == null) { 382 + return null 383 + } 384 + return result 336 385 }
+3 -1
test/config/test/console-color.test.ts
··· 41 41 GITHUB_ACTIONS: undefined, 42 42 43 43 // Overrides current process's value, since we are running Vitest in Vitest here 44 - FORCE_TTY: undefined, 44 + // By default, tinyrainbow doesn't check isatty since version 3, but 45 + // FORCE_TTY=false will make the check `false` 46 + FORCE_TTY: 'false', 45 47 }, 46 48 }, undefined, undefined, undefined, { preserveAnsi: true }) 47 49
+1 -1
test/core/test/concurrent-suite.test.ts
··· 1 - import { createDefer } from '@vitest/utils' 1 + import { createDefer } from '@vitest/utils/helpers' 2 2 import { afterAll, describe, expect, test } from 'vitest' 3 3 4 4 describe('basic', () => {
+1 -1
test/core/test/diff.test.ts
··· 1 1 import type { DiffOptions } from '@vitest/utils/diff' 2 2 import { stripVTControlCharacters } from 'node:util' 3 - import { processError } from '@vitest/runner' 4 3 import { diff, diffStringsUnified, printDiffOrStringify } from '@vitest/utils/diff' 4 + import { processError } from '@vitest/utils/error' 5 5 import { expect, test } from 'vitest' 6 6 7 7 function wrapDiff(diff?: string) {
+6 -24
test/core/test/exports.test.ts
··· 57 57 "populateGlobal": "function", 58 58 }, 59 59 "./internal/browser": { 60 + "DecodedMap": "function", 60 61 "SpyModule": "object", 61 - "TraceMap": "function", 62 62 "collectTests": "function", 63 63 "format": "function", 64 + "getOriginalPosition": "function", 64 65 "getSafeTimers": "function", 65 66 "getType": "function", 66 67 "inspect": "function", 67 68 "loadDiffConfig": "function", 68 69 "loadSnapshotSerializers": "function", 69 - "originalPositionFor": "function", 70 70 "processError": "function", 71 + "setSafeTimers": "function", 71 72 "setupCommonEnv": "function", 72 73 "startCoverageInsideWorker": "function", 73 74 "startTests": "function", ··· 158 159 "setFn": "function", 159 160 "setHooks": "function", 160 161 }, 161 - "./workers": { 162 - "collectVitestWorkerTests": "function", 163 - "createForksRpcOptions": "function", 164 - "createThreadsRpcOptions": "function", 165 - "provideWorkerState": "function", 166 - "runBaseTests": "function", 167 - "runVitestWorker": "function", 168 - "runVmTests": "function", 169 - "unwrapSerializableConfig": "function", 170 - }, 171 162 } 172 163 `) 173 164 } ··· 217 208 "populateGlobal": "function", 218 209 }, 219 210 "./internal/browser": { 211 + "DecodedMap": "function", 220 212 "SpyModule": "object", 221 - "TraceMap": "function", 222 213 "collectTests": "function", 223 214 "format": "function", 215 + "getOriginalPosition": "function", 224 216 "getSafeTimers": "function", 225 217 "getType": "function", 226 218 "inspect": "function", 227 219 "loadDiffConfig": "function", 228 220 "loadSnapshotSerializers": "function", 229 - "originalPositionFor": "function", 230 221 "processError": "function", 222 + "setSafeTimers": "function", 231 223 "setupCommonEnv": "function", 232 224 "startCoverageInsideWorker": "function", 233 225 "startTests": "function", ··· 317 309 "getHooks": "function", 318 310 "setFn": "function", 319 311 "setHooks": "function", 320 - }, 321 - "./workers": { 322 - "collectVitestWorkerTests": "function", 323 - "createForksRpcOptions": "function", 324 - "createThreadsRpcOptions": "function", 325 - "provideWorkerState": "function", 326 - "runBaseTests": "function", 327 - "runVitestWorker": "function", 328 - "runVmTests": "function", 329 - "unwrapSerializableConfig": "function", 330 312 }, 331 313 } 332 314 `)
+1 -1
test/core/test/serialize.test.ts
··· 1 1 // @vitest-environment jsdom 2 2 3 - import { serializeValue } from '@vitest/utils/error' 3 + import { serializeValue } from '@vitest/utils/serialize' 4 4 import { describe, expect, it } from 'vitest' 5 5 6 6 describe('error serialize', () => {
+1 -1
test/core/test/utils-display.spec.ts
··· 1 1 import util from 'node:util' 2 - import { format } from '@vitest/utils' 2 + import { format } from '@vitest/utils/display' 3 3 import { describe, expect, test } from 'vitest' 4 4 5 5 describe('format', () => {
+2 -1
test/core/test/utils.spec.ts
··· 1 - import { assertTypes, deepClone, deepMerge, isNegativeNaN, objDisplay, objectAttr, toArray } from '@vitest/utils' 1 + import { objDisplay } from '@vitest/utils/display' 2 + import { assertTypes, deepClone, deepMerge, isNegativeNaN, objectAttr, toArray } from '@vitest/utils/helpers' 2 3 import { parseSingleFFOrSafariStack } from '@vitest/utils/source-map' 3 4 import { EvaluatedModules } from 'vite/module-runner' 4 5 import { beforeAll, describe, expect, test } from 'vitest'
+1 -2
packages/browser/src/node/plugin.ts
··· 6 6 import { createReadStream, lstatSync, readFileSync } from 'node:fs' 7 7 import { createRequire } from 'node:module' 8 8 import { dynamicImportPlugin } from '@vitest/mocker/node' 9 - import { toArray } from '@vitest/utils' 9 + import { toArray } from '@vitest/utils/helpers' 10 10 import MagicString from 'magic-string' 11 11 import { basename, dirname, extname, resolve } from 'pathe' 12 12 import sirv from 'sirv' ··· 281 281 const include = [ 282 282 'vitest > expect-type', 283 283 'vitest > @vitest/snapshot > magic-string', 284 - 'vitest > @vitest/runner > strip-literal', 285 284 'vitest > @vitest/expect > chai', 286 285 'vitest > @vitest/expect > chai > loupe', 287 286 'vitest > @vitest/utils > loupe',
+2 -2
packages/browser/src/node/pool.ts
··· 1 - import type { DeferPromise } from '@vitest/utils' 1 + import type { DeferPromise } from '@vitest/utils/helpers' 2 2 import type { 3 3 BrowserProvider, 4 4 ProcessPool, ··· 9 9 import crypto from 'node:crypto' 10 10 import * as nodeos from 'node:os' 11 11 import { performance } from 'node:perf_hooks' 12 - import { createDefer } from '@vitest/utils' 12 + import { createDefer } from '@vitest/utils/helpers' 13 13 import { stringify } from 'flatted' 14 14 import { createDebugger } from 'vitest/node' 15 15
+4 -3
packages/browser/src/node/projectParent.ts
··· 75 75 return result?.map 76 76 }, 77 77 getUrlId: (id) => { 78 - const mod = this.vite.moduleGraph.getModuleById(id) 78 + const moduleGraph = this.vite.environments.client.moduleGraph 79 + const mod = moduleGraph.getModuleById(id) 79 80 if (mod) { 80 81 return id 81 82 } 82 83 const resolvedPath = resolve(this.vite.config.root, id.slice(1)) 83 - const modUrl = this.vite.moduleGraph.getModuleById(resolvedPath) 84 + const modUrl = moduleGraph.getModuleById(resolvedPath) 84 85 if (modUrl) { 85 86 return resolvedPath 86 87 } 87 88 // some browsers (looking at you, safari) don't report queries in stack traces 88 89 // the next best thing is to try the first id that this file resolves to 89 - const files = this.vite.moduleGraph.getModulesByFile(resolvedPath) 90 + const files = moduleGraph.getModulesByFile(resolvedPath) 90 91 if (files && files.size) { 91 92 return files.values().next().value!.id! 92 93 }
+1 -1
packages/mocker/src/browser/hints.ts
··· 1 1 import type { MaybeMockedDeep } from '@vitest/spy' 2 2 import type { ModuleMockFactoryWithHelper, ModuleMockOptions } from '../types' 3 3 import type { ModuleMocker } from './mocker' 4 - import { createSimpleStackTrace } from '@vitest/utils' 4 + import { createSimpleStackTrace } from '@vitest/utils/helpers' 5 5 import { parseSingleStack } from '@vitest/utils/source-map' 6 6 7 7 export interface CompilerHintsOptions {
+1 -1
packages/runner/src/utils/tasks.ts
··· 1 1 import type { Arrayable } from '@vitest/utils' 2 2 import type { Suite, Task, Test } from '../types/tasks' 3 - import { toArray } from '@vitest/utils' 3 + import { toArray } from '@vitest/utils/helpers' 4 4 5 5 export function isTestCase(s: Task): s is Test { 6 6 return s.type === 'test'
+2 -2
packages/snapshot/src/port/inlineSnapshot.ts
··· 1 1 import type MagicString from 'magic-string' 2 2 import type { SnapshotEnvironment } from '../types' 3 + import { getCallLastIndex } from '../../../utils/src/helpers' 3 4 import { 4 - getCallLastIndex, 5 5 lineSplitRE, 6 6 offsetToLineNumber, 7 7 positionToOffset, 8 - } from '../../../utils/src/index' 8 + } from '../../../utils/src/offset' 9 9 10 10 export interface InlineSnapshot { 11 11 snapshot: string
+1 -1
packages/snapshot/src/port/utils.ts
··· 10 10 import type { SnapshotEnvironment } from '../types/environment' 11 11 import { format as prettyFormat } from '@vitest/pretty-format' 12 12 import naturalCompare from 'natural-compare' 13 - import { isObject } from '../../../utils/src/index' 13 + import { isObject } from '../../../utils/src/helpers' 14 14 import { getSerializers } from './plugins' 15 15 16 16 // TODO: rewrite and clean up
+1 -1
packages/vitest/src/api/setup.ts
··· 15 15 WebSocketRPC, 16 16 } from './types' 17 17 import { existsSync, promises as fs } from 'node:fs' 18 - import { noop } from '@vitest/utils' 18 + import { noop } from '@vitest/utils/helpers' 19 19 import { createBirpc } from 'birpc' 20 20 import { parse, stringify } from 'flatted' 21 21 import { WebSocketServer } from 'ws'
+1 -1
packages/vitest/src/integrations/vi.ts
··· 10 10 import type { VitestMocker } from '../runtime/moduleRunner/moduleMocker' 11 11 import type { MockFactoryWithHelper, MockOptions } from '../types/mocker' 12 12 import { clearAllMocks, fn, isMockFunction, resetAllMocks, restoreAllMocks, spyOn } from '@vitest/spy' 13 - import { assertTypes, createSimpleStackTrace } from '@vitest/utils' 13 + import { assertTypes, createSimpleStackTrace } from '@vitest/utils/helpers' 14 14 import { getWorkerState, isChildProcess, resetModules, waitForImportsToResolve } from '../runtime/utils' 15 15 import { parseSingleStack } from '../utils/source-map' 16 16 import { FakeTimers } from './mock/timers'
+1 -1
packages/vitest/src/integrations/wait.ts
··· 1 - import { getSafeTimers } from '@vitest/utils' 1 + import { getSafeTimers } from '@vitest/utils/timers' 2 2 import { vi } from './vi' 3 3 4 4 // The waitFor function was inspired by https://github.com/testing-library/web-testing-library/pull/2
+1 -1
packages/vitest/src/node/ast-collect.ts
··· 1 1 import type { File, Suite, Task, Test } from '@vitest/runner' 2 2 import type { TestError } from '../types/general' 3 3 import type { TestProject } from './project' 4 + import { originalPositionFor, TraceMap } from '@jridgewell/trace-mapping' 4 5 import { 5 6 calculateSuiteHash, 6 7 generateHash, 7 8 interpretTaskModes, 8 9 someTasksAreOnly, 9 10 } from '@vitest/runner/utils' 10 - import { originalPositionFor, TraceMap } from '@vitest/utils/source-map' 11 11 import { ancestor as walkAst } from 'acorn-walk' 12 12 import { relative } from 'pathe' 13 13 import { parseAst } from 'vite'
+1 -1
packages/vitest/src/node/core.ts
··· 16 16 import os from 'node:os' 17 17 import { getTasks, hasFailed, limitConcurrency } from '@vitest/runner/utils' 18 18 import { SnapshotManager } from '@vitest/snapshot/manager' 19 - import { deepClone, deepMerge, noop, toArray } from '@vitest/utils' 19 + import { deepClone, deepMerge, noop, toArray } from '@vitest/utils/helpers' 20 20 import { normalize, relative } from 'pathe' 21 21 import { version } from '../../package.json' with { type: 'json' } 22 22 import { WebSocketReporter } from '../api/setup'
+1 -1
packages/vitest/src/node/coverage.ts
··· 6 6 import type { AfterSuiteRunMeta } from '../types/general' 7 7 import { existsSync, promises as fs, readdirSync, writeFileSync } from 'node:fs' 8 8 import path from 'node:path' 9 - import { cleanUrl, slash } from '@vitest/utils' 9 + import { cleanUrl, slash } from '@vitest/utils/helpers' 10 10 import { relative, resolve } from 'pathe' 11 11 import pm from 'picomatch' 12 12 import { glob } from 'tinyglobby'
+1 -1
packages/vitest/src/node/create.ts
··· 6 6 import type { VitestOptions } from './core' 7 7 import type { VitestRunMode } from './types/config' 8 8 import { resolve } from 'node:path' 9 - import { deepClone, slash } from '@vitest/utils' 9 + import { deepClone, slash } from '@vitest/utils/helpers' 10 10 import { findUp } from 'find-up' 11 11 import { mergeConfig } from 'vite' 12 12 import { configFiles } from '../constants'
+1 -1
packages/vitest/src/node/globalSetup.ts
··· 1 1 import type { ModuleRunner } from 'vite/module-runner' 2 2 import type { TestProject } from './project' 3 - import { toArray } from '@vitest/utils' 3 + import { toArray } from '@vitest/utils/helpers' 4 4 5 5 export interface GlobalSetupFile { 6 6 file: string
+1 -1
packages/vitest/src/node/logger.ts
··· 4 4 import type { Vitest } from './core' 5 5 import type { TestProject } from './project' 6 6 import { Console } from 'node:console' 7 - import { toArray } from '@vitest/utils' 7 + import { toArray } from '@vitest/utils/helpers' 8 8 import c from 'tinyrainbow' 9 9 import { highlightCode } from '../utils/colors' 10 10 import { printError } from './printError'
+2 -1
packages/vitest/src/node/printError.ts
··· 7 7 import { existsSync, readFileSync } from 'node:fs' 8 8 import { Writable } from 'node:stream' 9 9 import { stripVTControlCharacters } from 'node:util' 10 - import { inspect, isPrimitive } from '@vitest/utils' 10 + import { inspect } from '@vitest/utils/display' 11 + import { isPrimitive } from '@vitest/utils/helpers' 11 12 import { normalize, relative } from 'pathe' 12 13 import c from 'tinyrainbow' 13 14 import { TypeCheckError } from '../typecheck/typechecker'
+1 -1
packages/vitest/src/node/project.ts
··· 17 17 import { rm } from 'node:fs/promises' 18 18 import { tmpdir } from 'node:os' 19 19 import path from 'node:path' 20 - import { deepMerge, nanoid, slash } from '@vitest/utils' 20 + import { deepMerge, nanoid, slash } from '@vitest/utils/helpers' 21 21 import { isAbsolute, join, relative } from 'pathe' 22 22 import pm from 'picomatch' 23 23 import { glob } from 'tinyglobby'
+1 -1
packages/vitest/src/node/resolver.ts
··· 2 2 import { existsSync, promises as fsp } from 'node:fs' 3 3 import { isBuiltin } from 'node:module' 4 4 import { pathToFileURL } from 'node:url' 5 - import { KNOWN_ASSET_RE } from '@vitest/utils' 5 + import { KNOWN_ASSET_RE } from '@vitest/utils/constants' 6 6 import { findNearestPackageData } from '@vitest/utils/resolver' 7 7 import * as esModuleLexer from 'es-module-lexer' 8 8 import { dirname, extname, join, resolve } from 'pathe'
+3 -3
packages/vitest/src/node/test-run.ts
··· 17 17 import assert from 'node:assert' 18 18 import { createHash } from 'node:crypto' 19 19 import { copyFile, mkdir } from 'node:fs/promises' 20 - import { isPrimitive } from '@vitest/utils' 21 - import { serializeError } from '@vitest/utils/error' 20 + import { isPrimitive } from '@vitest/utils/helpers' 21 + import { serializeValue } from '@vitest/utils/serialize' 22 22 import { parseErrorStacktrace } from '@vitest/utils/source-map' 23 23 import mime from 'mime/lite' 24 24 import { basename, dirname, extname, resolve } from 'pathe' ··· 75 75 76 76 for (const [id, event, data] of events) { 77 77 await this.reportEvent(id, event, data).catch((error) => { 78 - this.vitest.state.catchError(serializeError(error), 'Unhandled Reporter Error') 78 + this.vitest.state.catchError(serializeValue(error), 'Unhandled Reporter Error') 79 79 }) 80 80 } 81 81
+1 -1
packages/vitest/src/node/watch-filter.ts
··· 1 1 import type { Writable } from 'node:stream' 2 2 import readline from 'node:readline' 3 3 import { stripVTControlCharacters } from 'node:util' 4 - import { createDefer } from '@vitest/utils' 4 + import { createDefer } from '@vitest/utils/helpers' 5 5 import c from 'tinyrainbow' 6 6 import { stdout as getStdout } from '../utils/base' 7 7
+1 -1
packages/vitest/src/node/watcher.ts
··· 1 1 import type { Vitest } from './core' 2 2 import type { TestProject } from './project' 3 3 import { readFileSync } from 'node:fs' 4 - import { noop, slash } from '@vitest/utils' 4 + import { noop, slash } from '@vitest/utils/helpers' 5 5 import { resolve } from 'pathe' 6 6 import pm from 'picomatch' 7 7
+11 -10
packages/vitest/src/public/browser.ts
··· 9 9 loadSnapshotSerializers, 10 10 setupCommonEnv, 11 11 } from '../runtime/setup-common' 12 - export { collectTests, processError, startTests } from '@vitest/runner' 12 + export { collectTests, startTests } from '@vitest/runner' 13 13 export * as SpyModule from '@vitest/spy' 14 - export { 15 - format, 16 - getSafeTimers, 17 - getType, 18 - inspect, 19 - stringify, 20 - } from '@vitest/utils' 21 14 export type { LoupeOptions, ParsedStack, StringifyOptions } from '@vitest/utils' 22 15 export { 23 - originalPositionFor, 24 - TraceMap, 16 + format, 17 + inspect, 18 + stringify, 19 + } from '@vitest/utils/display' 20 + export { processError } from '@vitest/utils/error' 21 + export { getType } from '@vitest/utils/helpers' 22 + export { 23 + DecodedMap, 24 + getOriginalPosition, 25 25 } from '@vitest/utils/source-map' 26 + export { getSafeTimers, setSafeTimers } from '@vitest/utils/timers'
-10
packages/vitest/src/public/workers.ts
··· 1 - export { provideWorkerState } from '../runtime/utils' 2 - export { collect as collectVitestWorkerTests, run as runVitestWorker } from '../runtime/worker' 3 - export { runBaseTests } from '../runtime/workers/base' 4 - export type { VitestWorker, WorkerRpcOptions } from '../runtime/workers/types' 5 - export { 6 - createForksRpcOptions, 7 - createThreadsRpcOptions, 8 - unwrapSerializableConfig, 9 - } from '../runtime/workers/utils' 10 - export { runVmTests } from '../runtime/workers/vm'
+1 -1
packages/vitest/src/runtime/benchmark.ts
··· 2 2 import type { BenchFunction, BenchmarkAPI, BenchOptions } from './types/benchmark' 3 3 import { getCurrentSuite } from '@vitest/runner' 4 4 import { createChainable } from '@vitest/runner/utils' 5 - import { noop } from '@vitest/utils' 5 + import { noop } from '@vitest/utils/helpers' 6 6 import { getWorkerState } from './utils' 7 7 8 8 const benchFns = new WeakMap<Test, BenchFunction>()
+1 -1
packages/vitest/src/runtime/console.ts
··· 2 2 import { Console } from 'node:console' 3 3 import { relative } from 'node:path' 4 4 import { Writable } from 'node:stream' 5 - import { getSafeTimers } from '@vitest/utils' 5 + import { getSafeTimers } from '@vitest/utils/timers' 6 6 import c from 'tinyrainbow' 7 7 import { RealDate } from '../integrations/mock/date' 8 8 import { getWorkerState } from './utils'
+1 -1
packages/vitest/src/runtime/external-executor.ts
··· 5 5 import fs from 'node:fs' 6 6 import { isBuiltin } from 'node:module' 7 7 import { fileURLToPath, pathToFileURL } from 'node:url' 8 - import { isBareImport } from '@vitest/utils' 8 + import { isBareImport } from '@vitest/utils/helpers' 9 9 import { findNearestPackageData } from '@vitest/utils/resolver' 10 10 import { extname, normalize } from 'pathe' 11 11 import { CommonjsExecutor } from './vm/commonjs-executor'
+1 -1
packages/vitest/src/runtime/rpc.ts
··· 2 2 import type { BirpcOptions, BirpcReturn } from 'birpc' 3 3 import type { RunnerRPC, RuntimeRPC } from '../types/rpc' 4 4 import type { WorkerRPC } from '../types/worker' 5 - import { getSafeTimers } from '@vitest/utils' 5 + import { getSafeTimers } from '@vitest/utils/timers' 6 6 import { createBirpc } from 'birpc' 7 7 import { getWorkerState } from './utils' 8 8
+1 -1
packages/vitest/src/runtime/runVmTests.ts
··· 7 7 import timersPromises from 'node:timers/promises' 8 8 import util from 'node:util' 9 9 import { collectTests, startTests } from '@vitest/runner' 10 - import { KNOWN_ASSET_TYPES } from '@vitest/utils' 10 + import { KNOWN_ASSET_TYPES } from '@vitest/utils/constants' 11 11 import { setupChaiConfig } from '../integrations/chai/config' 12 12 import { 13 13 startCoverageInsideWorker,
+1 -1
packages/vitest/src/runtime/setup-common.ts
··· 4 4 import type { SerializedConfig } from './config' 5 5 import type { VitestModuleRunner } from './moduleRunner/moduleRunner' 6 6 import { addSerializer } from '@vitest/snapshot' 7 - import { setSafeTimers } from '@vitest/utils' 7 + import { setSafeTimers } from '@vitest/utils/timers' 8 8 import { getWorkerState } from './utils' 9 9 10 10 let globalSetup = false
+2 -1
packages/vitest/src/runtime/setup-node.ts
··· 5 5 import timers from 'node:timers' 6 6 import timersPromises from 'node:timers/promises' 7 7 import util from 'node:util' 8 - import { getSafeTimers, KNOWN_ASSET_TYPES } from '@vitest/utils' 8 + import { KNOWN_ASSET_TYPES } from '@vitest/utils/constants' 9 + import { getSafeTimers } from '@vitest/utils/timers' 9 10 import { expect } from '../integrations/chai' 10 11 import { resolveSnapshotEnvironment } from '../integrations/snapshot/environments/resolveSnapshotEnvironment' 11 12 import * as VitestIndex from '../public/index'
+1 -1
packages/vitest/src/runtime/utils.ts
··· 1 1 import type { EvaluatedModules } from 'vite/module-runner' 2 2 import type { WorkerGlobalState } from '../types/worker' 3 - import { getSafeTimers } from '@vitest/utils' 3 + import { getSafeTimers } from '@vitest/utils/timers' 4 4 5 5 const NAME_WORKER_STATE = '__vitest_worker__' 6 6
+16
packages/vitest/src/runtime/worker-base.ts
··· 1 + import type { ContextRPC } from '../types/worker' 2 + import * as worker from './worker' 3 + import forks from './workers/forks' 4 + import threads from './workers/threads' 5 + 6 + export async function run(ctx: ContextRPC): Promise<void> { 7 + await worker.execute('run', ctx, ctx.pool === 'forks' ? forks : threads) 8 + } 9 + 10 + export async function collect(ctx: ContextRPC): Promise<void> { 11 + await worker.execute('collect', ctx, ctx.pool === 'forks' ? forks : threads) 12 + } 13 + 14 + export async function teardown(): Promise<void> { 15 + await worker.teardown() 16 + }
+16
packages/vitest/src/runtime/worker-vm.ts
··· 1 + import type { ContextRPC } from '../types/worker' 2 + import * as worker from './worker' 3 + import vmForks from './workers/vmForks' 4 + import vmThreads from './workers/vmThreads' 5 + 6 + export async function run(ctx: ContextRPC): Promise<void> { 7 + await worker.execute('run', ctx, ctx.pool === 'vmForks' ? vmForks : vmThreads) 8 + } 9 + 10 + export async function collect(ctx: ContextRPC): Promise<void> { 11 + await worker.execute('collect', ctx, ctx.pool === 'vmForks' ? vmForks : vmThreads) 12 + } 13 + 14 + export async function teardown(): Promise<void> { 15 + await worker.teardown() 16 + }
+5 -35
packages/vitest/src/runtime/worker.ts
··· 1 1 import type { ModuleRunner } from 'vite/module-runner' 2 2 import type { ContextRPC, WorkerGlobalState } from '../types/worker' 3 3 import type { VitestWorker } from './workers/types' 4 - import { pathToFileURL } from 'node:url' 5 4 import { createStackString, parseStacktrace } from '@vitest/utils/source-map' 6 5 import { EvaluatedModules } from 'vite/module-runner' 7 6 import { loadEnvironment } from '../integrations/env/loader' 8 - import { addCleanupListener, cleanup as cleanupWorker } from './cleanup' 9 7 import { setupInspect } from './inspector' 10 8 import { createRuntimeRpc, rpcDone } from './rpc' 11 9 import { isChildProcess } from './utils' ··· 29 27 } 30 28 31 29 const resolvingModules = new Set<string>() 30 + const globalListeners = new Set<() => unknown>() 32 31 33 32 // this is what every pool executes when running tests 34 - async function execute(method: 'run' | 'collect', ctx: ContextRPC) { 33 + export async function execute(method: 'run' | 'collect', ctx: ContextRPC, worker: VitestWorker): Promise<void> { 35 34 disposeInternalListeners() 36 35 37 36 const prepareStart = performance.now() ··· 45 44 let environmentLoader: ModuleRunner | undefined 46 45 47 46 try { 48 - // worker is a filepath or URL to a file that exposes a default export with "getRpcOptions" and "runTests" methods 49 - if (ctx.worker[0] === '.') { 50 - throw new Error( 51 - `Path to the test runner cannot be relative, received "${ctx.worker}"`, 52 - ) 53 - } 54 - 55 - const file = ctx.worker.startsWith('file:') 56 - ? ctx.worker 57 - : pathToFileURL(ctx.worker).toString() 58 - const testRunnerModule = await import(file) 59 - 60 - if ( 61 - !testRunnerModule.default 62 - || typeof testRunnerModule.default !== 'object' 63 - ) { 64 - throw new TypeError( 65 - `Test worker object should be exposed as a default export. Received "${typeof testRunnerModule.default}"`, 66 - ) 67 - } 68 - 69 - const worker = testRunnerModule.default as VitestWorker 70 47 if (!worker.getRpcOptions || typeof worker.getRpcOptions !== 'function') { 71 48 throw new TypeError( 72 49 `Test worker should expose "getRpcOptions" method. Received "${typeof worker.getRpcOptions}".`, ··· 101 78 prepare: prepareStart, 102 79 }, 103 80 rpc, 104 - onCleanup: listener => addCleanupListener(listener), 81 + onCleanup: listener => globalListeners.add(listener), 105 82 providedContext: ctx.providedContext, 106 83 onFilterStackTrace(stack) { 107 84 return createStackString(parseStacktrace(stack)) ··· 127 104 } 128 105 } 129 106 130 - export function run(ctx: ContextRPC): Promise<void> { 131 - return execute('run', ctx) 132 - } 133 - 134 - export function collect(ctx: ContextRPC): Promise<void> { 135 - return execute('collect', ctx) 136 - } 137 - 138 107 export async function teardown(): Promise<void> { 139 - return cleanupWorker() 108 + const promises = [...globalListeners].map(l => l()) 109 + await Promise.all(promises) 140 110 } 141 111 142 112 function createImportMetaEnvProxy(): WorkerGlobalState['metaEnv'] {
+2 -2
packages/vitest/src/typecheck/typechecker.ts
··· 1 + import type { EachMapping } from '@jridgewell/trace-mapping' 1 2 import type { File, Task, TaskEventPack, TaskResultPack, TaskState } from '@vitest/runner' 2 3 import type { ParsedStack, TestError } from '@vitest/utils' 3 - import type { EachMapping } from '@vitest/utils/source-map' 4 4 import type { ChildProcess } from 'node:child_process' 5 5 import type { Result } from 'tinyexec' 6 6 import type { Vitest } from '../node/core' ··· 10 10 import type { TscErrorInfo } from './types' 11 11 import os from 'node:os' 12 12 import { performance } from 'node:perf_hooks' 13 - import { eachMapping, generatedPositionFor, TraceMap } from '@vitest/utils/source-map' 13 + import { eachMapping, generatedPositionFor, TraceMap } from '@jridgewell/trace-mapping' 14 14 import { basename, join, resolve } from 'pathe' 15 15 import { x } from 'tinyexec' 16 16 import { distDir } from '../paths'
-1
packages/vitest/src/types/worker.ts
··· 16 16 17 17 export interface ContextRPC { 18 18 pool: string 19 - worker: string 20 19 workerId: number 21 20 config: SerializedConfig 22 21 projectName: string
+1 -1
packages/vitest/src/utils/base.ts
··· 1 - export { getCallLastIndex, nanoid, notNullish } from '@vitest/utils' 1 + export { getCallLastIndex, nanoid, notNullish } from '@vitest/utils/helpers' 2 2 3 3 export function groupBy<T, K extends string | number | symbol>( 4 4 collection: T[],
+1 -1
packages/vitest/src/utils/colors.ts
··· 1 1 import type { Colors } from 'tinyrainbow' 2 - import { highlight } from '@vitest/utils' 2 + import { highlight } from '@vitest/utils/highlight' 3 3 import { extname } from 'pathe' 4 4 import c from 'tinyrainbow' 5 5
+1 -1
packages/vitest/src/utils/source-map.ts
··· 2 2 lineSplitRE, 3 3 offsetToLineNumber, 4 4 positionToOffset, 5 - } from '@vitest/utils' 5 + } from '@vitest/utils/offset' 6 6 export { 7 7 defaultStackIgnorePatterns, 8 8 parseErrorStacktrace,
+1 -1
packages/vitest/src/utils/tasks.ts
··· 1 1 import type { File, Suite, Task, TaskEventPack, TaskResultPack } from '@vitest/runner' 2 2 import type { Arrayable } from '../types/general' 3 3 import { getTests } from '@vitest/runner/utils' 4 - import { toArray } from '@vitest/utils' 4 + import { toArray } from '@vitest/utils/helpers' 5 5 6 6 export function hasBenchmark(suite: Arrayable<Suite>): boolean { 7 7 return toArray(suite).some(s =>
+1 -1
packages/vitest/src/utils/timers.ts
··· 1 - export { getSafeTimers } from '@vitest/utils' 1 + export { getSafeTimers } from '@vitest/utils/timers'
+1 -1
test/cli/fixtures/fails/concurrent-suite-deadlock.test.ts
··· 1 - import { createDefer } from '@vitest/utils' 1 + import { createDefer } from '@vitest/utils/helpers' 2 2 import { describe, test, vi, expect } from 'vitest' 3 3 4 4 // 3 tests depend on each other,
+1 -1
test/cli/fixtures/fails/concurrent-test-deadlock.test.ts
··· 1 1 import { describe, expect, test, vi } from 'vitest' 2 - import { createDefer } from '@vitest/utils' 2 + import { createDefer } from '@vitest/utils/helpers' 3 3 4 4 // 3 tests depend on each other, 5 5 // so they will deadlock when maxConcurrency < 3
+11 -19
packages/browser/src/client/tester/runner.ts
··· 4 4 import { globalChannel, onCancel } from '@vitest/browser/client' 5 5 import { page, userEvent } from '@vitest/browser/context' 6 6 import { 7 + DecodedMap, 8 + getOriginalPosition, 7 9 loadDiffConfig, 8 10 loadSnapshotSerializers, 9 - originalPositionFor, 10 11 takeCoverageInsideWorker, 11 - TraceMap, 12 12 } from 'vitest/internal/browser' 13 13 import { NodeBenchmarkRunner, VitestTestRunner } from 'vitest/runners' 14 14 import { createStackString, parseStacktrace } from '../../../../utils/src/source-map' ··· 154 154 return rpc().onTaskAnnotate(test.id, annotation) 155 155 } 156 156 157 - const traceMap = new TraceMap(map as any) 158 - const { line, column, source } = originalPositionFor(traceMap, annotation.location) 159 - if (line != null && column != null && source != null) { 160 - let file: string = annotation.location.file 161 - if (source) { 162 - const fileUrl = annotation.location.file.startsWith('file://') 163 - ? annotation.location.file 164 - : `file://${annotation.location.file}` 165 - const sourceRootUrl = map.sourceRoot 166 - ? new URL(map.sourceRoot, fileUrl) 167 - : fileUrl 168 - file = new URL(source, sourceRootUrl).pathname 169 - } 170 - 157 + const traceMap = new DecodedMap(map as any, annotation.location.file) 158 + const position = getOriginalPosition(traceMap, annotation.location) 159 + if (position) { 160 + const { source, column, line } = position 161 + const file = source || annotation.location.file 171 162 annotation.location = { 172 163 line, 173 164 column: column + 1, ··· 261 252 if (!result) { 262 253 return null 263 254 } 264 - return new TraceMap(result as any) 255 + return new DecodedMap(result as any, file) 265 256 } 266 257 267 258 async function updateTestFilesLocations(files: File[], sourceMaps: Map<string, any>) { ··· 272 263 } 273 264 const updateLocation = (task: Task) => { 274 265 if (task.location) { 275 - const { line, column } = originalPositionFor(traceMap, task.location) 276 - if (line != null && column != null) { 266 + const position = getOriginalPosition(traceMap, task.location) 267 + if (position) { 268 + const { line, column } = position 277 269 task.location = { line, column: task.each ? column : column + 1 } 278 270 } 279 271 }
+6 -6
packages/browser/src/client/tester/snapshot.ts
··· 1 1 import type { VitestBrowserClient } from '@vitest/browser/client' 2 2 import type { ParsedStack } from 'vitest/internal/browser' 3 3 import type { SnapshotEnvironment } from 'vitest/snapshot' 4 - import { originalPositionFor, TraceMap } from 'vitest/internal/browser' 4 + import { DecodedMap, getOriginalPosition } from 'vitest/internal/browser' 5 5 6 6 export class VitestBrowserSnapshotEnvironment implements SnapshotEnvironment { 7 7 private sourceMaps = new Map<string, any>() 8 - private traceMaps = new Map<string, TraceMap>() 8 + private traceMaps = new Map<string, DecodedMap>() 9 9 10 10 public addSourceMap(filepath: string, map: any): void { 11 11 this.sourceMaps.set(filepath, map) ··· 46 46 } 47 47 let traceMap = this.traceMaps.get(stack.file) 48 48 if (!traceMap) { 49 - traceMap = new TraceMap(map) 49 + traceMap = new DecodedMap(map, stack.file) 50 50 this.traceMaps.set(stack.file, traceMap) 51 51 } 52 - const { line, column } = originalPositionFor(traceMap, stack) 53 - if (line != null && column != null) { 54 - return { ...stack, line, column } 52 + const position = getOriginalPosition(traceMap, stack) 53 + if (position) { 54 + return { ...stack, line: position.line, column: position.column } 55 55 } 56 56 return stack 57 57 }
-1
packages/browser/src/client/tester/state.ts
··· 8 8 const state: WorkerGlobalState = { 9 9 ctx: { 10 10 pool: 'browser', 11 - worker: './browser.js', 12 11 workerId: 1, 13 12 config, 14 13 projectName: config.name || '',
+1 -1
packages/browser/src/node/plugins/pluginContext.ts
··· 2 2 import type { Plugin } from 'vitest/config' 3 3 import type { ParentBrowserProject } from '../projectParent' 4 4 import { fileURLToPath } from 'node:url' 5 - import { slash } from '@vitest/utils' 5 + import { slash } from '@vitest/utils/helpers' 6 6 import { dirname, resolve } from 'pathe' 7 7 8 8 const VIRTUAL_ID_CONTEXT = '\0@vitest/browser/context'
+1 -1
packages/ui/client/composables/explorer/collector.ts
··· 2 2 import type { Arrayable } from '@vitest/utils' 3 3 import type { CollectFilteredTests, CollectorInfo, Filter, FilteredTests } from '~/composables/explorer/types' 4 4 import { isTestCase } from '@vitest/runner/utils' 5 - import { toArray } from '@vitest/utils' 5 + import { toArray } from '@vitest/utils/helpers' 6 6 import { client, findById } from '~/composables/client' 7 7 import { testRunState } from '~/composables/client/state' 8 8 import { expandNodesOnEndRun } from '~/composables/explorer/expand'
+1 -1
packages/vitest/src/integrations/chai/poll.ts
··· 1 1 import type { Assertion, ExpectStatic } from '@vitest/expect' 2 2 import type { Test } from '@vitest/runner' 3 3 import { chai } from '@vitest/expect' 4 - import { getSafeTimers } from '@vitest/utils' 4 + import { getSafeTimers } from '@vitest/utils/timers' 5 5 import { getWorkerState } from '../../runtime/utils' 6 6 7 7 // these matchers are not supported because they don't make sense with poll
+1 -1
packages/vitest/src/integrations/env/node.ts
··· 11 11 'Uint8Array', 12 12 ]) 13 13 14 - const nodeGlobals = new Map() 14 + const nodeGlobals = new Map<string, PropertyDescriptor>() 15 15 16 16 function populateNodeGlobals() { 17 17 if (nodeGlobals.size !== 0) {
+1 -1
packages/vitest/src/node/browser/sessions.ts
··· 1 1 import type { TestProject } from '../project' 2 2 import type { BrowserServerStateSession } from '../types/browser' 3 - import { createDefer } from '@vitest/utils' 3 + import { createDefer } from '@vitest/utils/helpers' 4 4 5 5 export class BrowserSessions { 6 6 private sessions = new Map<string, BrowserServerStateSession>()
+1 -1
packages/vitest/src/node/cache/index.ts
··· 1 1 import type { SuiteResultCache } from './results' 2 - import { slash } from '@vitest/utils' 2 + import { slash } from '@vitest/utils/helpers' 3 3 import { resolve } from 'pathe' 4 4 import { hash } from '../hash' 5 5 import { FilesStatsCache } from './files'
+1 -1
packages/vitest/src/node/cli/cac.ts
··· 2 2 import type { VitestRunMode } from '../types/config' 3 3 import type { CliOptions } from './cli-api' 4 4 import type { CLIOption, CLIOptions as CLIOptionsConfig } from './cli-config' 5 - import { toArray } from '@vitest/utils' 5 + import { toArray } from '@vitest/utils/helpers' 6 6 import cac from 'cac' 7 7 import { normalize } from 'pathe' 8 8 import c from 'tinyrainbow'
+1 -1
packages/vitest/src/node/config/resolveConfig.ts
··· 10 10 import type { BaseCoverageOptions, CoverageReporterWithOptions } from '../types/coverage' 11 11 import type { BuiltinPool, ForksOptions, PoolOptions, ThreadsOptions } from '../types/pool-options' 12 12 import crypto from 'node:crypto' 13 - import { slash, toArray } from '@vitest/utils' 13 + import { slash, toArray } from '@vitest/utils/helpers' 14 14 import { resolveModule } from 'local-pkg' 15 15 import { normalize, relative, resolve } from 'pathe' 16 16 import c from 'tinyrainbow'
+1 -1
packages/vitest/src/node/environments/fetchModule.ts
··· 5 5 import { mkdirSync } from 'node:fs' 6 6 import { rename, stat, unlink, writeFile } from 'node:fs/promises' 7 7 import { tmpdir } from 'node:os' 8 - import { isExternalUrl, nanoid, unwrapId } from '@vitest/utils' 8 + import { isExternalUrl, nanoid, unwrapId } from '@vitest/utils/helpers' 9 9 import { dirname, join } from 'pathe' 10 10 import { fetchModule } from 'vite' 11 11 import { hash } from '../hash'
+1 -1
packages/vitest/src/node/environments/normalizeUrl.ts
··· 1 1 import type { DevEnvironment } from 'vite' 2 2 import { existsSync } from 'node:fs' 3 3 import path from 'node:path' 4 - import { cleanUrl, withTrailingSlash, wrapId } from '@vitest/utils' 4 + import { cleanUrl, withTrailingSlash, wrapId } from '@vitest/utils/helpers' 5 5 6 6 // this is copy pasted from vite 7 7 export function normalizeResolvedIdToUrl(
+1 -1
packages/vitest/src/node/plugins/cssEnabler.ts
··· 1 1 import type { Plugin as VitePlugin } from 'vite' 2 2 import type { CSSModuleScopeStrategy, ResolvedConfig } from '../types/config' 3 - import { toArray } from '@vitest/utils' 3 + import { toArray } from '@vitest/utils/helpers' 4 4 import { relative } from 'pathe' 5 5 import { generateCssFilenameHash } from '../../integrations/css/css-modules' 6 6
+1 -5
packages/vitest/src/node/plugins/index.ts
··· 1 1 import type { UserConfig as ViteConfig, Plugin as VitePlugin } from 'vite' 2 2 import type { ResolvedConfig, UserConfig } from '../types/config' 3 - import { 4 - deepClone, 5 - deepMerge, 6 - notNullish, 7 - } from '@vitest/utils' 3 + import { deepClone, deepMerge, notNullish } from '@vitest/utils/helpers' 8 4 import { relative } from 'pathe' 9 5 import * as vite from 'vite' 10 6 import { defaultPort } from '../../constants'
+1 -1
packages/vitest/src/node/plugins/metaEnvReplacer.ts
··· 1 1 import type { Plugin } from 'vite' 2 - import { cleanUrl } from '@vitest/utils' 2 + import { cleanUrl } from '@vitest/utils/helpers' 3 3 import MagicString from 'magic-string' 4 4 import { stripLiteral } from 'strip-literal' 5 5
+1 -1
packages/vitest/src/node/plugins/publicConfig.ts
··· 3 3 UserConfig as ViteUserConfig, 4 4 } from 'vite' 5 5 import type { ResolvedConfig, UserConfig } from '../types/config' 6 - import { deepClone, slash } from '@vitest/utils' 6 + import { deepClone, slash } from '@vitest/utils/helpers' 7 7 import { findUp } from 'find-up' 8 8 import { resolve } from 'pathe' 9 9 import { mergeConfig, resolveConfig as resolveViteConfig } from 'vite'
+1 -1
packages/vitest/src/node/plugins/workspace.ts
··· 2 2 import type { TestProject } from '../project' 3 3 import type { BrowserConfigOptions, ResolvedConfig, TestProjectInlineConfiguration } from '../types/config' 4 4 import { existsSync, readFileSync } from 'node:fs' 5 - import { deepMerge } from '@vitest/utils' 5 + import { deepMerge } from '@vitest/utils/helpers' 6 6 import { basename, dirname, relative, resolve } from 'pathe' 7 7 import * as vite from 'vite' 8 8 import { configDefaults } from '../../defaults'
+1 -4
packages/vitest/src/node/pools/forks.ts
··· 90 90 // avoid recreating threads when tests are finished 91 91 : 0 92 92 93 - const worker = resolve(vitest.distPath, 'workers/forks.js') 94 - 95 93 const options: TinypoolOptions = { 96 94 runtime: 'child_process', 97 - filename: resolve(vitest.distPath, 'worker.js'), 95 + filename: resolve(vitest.distPath, 'worker-base.js'), 98 96 teardown: 'teardown', 99 97 100 98 maxThreads, ··· 137 135 const workerId = ++id 138 136 const data: ContextRPC = { 139 137 pool: 'forks', 140 - worker, 141 138 config, 142 139 files, 143 140 invalidates,
+1 -1
packages/vitest/src/node/pools/rpc.ts
··· 2 2 import type { TestProject } from '../project' 3 3 import type { ResolveSnapshotPathHandlerContext } from '../types/config' 4 4 import { fileURLToPath } from 'node:url' 5 - import { cleanUrl } from '@vitest/utils' 5 + import { cleanUrl } from '@vitest/utils/helpers' 6 6 import { createFetchModuleFunction, handleRollupError } from '../environments/fetchModule' 7 7 import { normalizeResolvedIdToUrl } from '../environments/normalizeUrl' 8 8
+1 -4
packages/vitest/src/node/pools/threads.ts
··· 71 71 // avoid recreating forks when tests are finished 72 72 : 0 73 73 74 - const worker = resolve(vitest.distPath, 'workers/threads.js') 75 - 76 74 const options: TinypoolOptions = { 77 - filename: resolve(vitest.distPath, 'worker.js'), 75 + filename: resolve(vitest.distPath, 'worker-base.js'), 78 76 teardown: 'teardown', 79 77 // TODO: investigate further 80 78 // It seems atomics introduced V8 Fatal Error https://github.com/vitest-dev/vitest/issues/1191 ··· 121 119 const workerId = ++id 122 120 const data: WorkerContext = { 123 121 pool: 'threads', 124 - worker, 125 122 port: workerPort, 126 123 config, 127 124 files,
+1 -1
packages/vitest/src/node/pools/typecheck.ts
··· 6 6 import type { TestSpecification } from '../spec' 7 7 import type { TestRunEndReason } from '../types/reporter' 8 8 import { hasFailed } from '@vitest/runner/utils' 9 - import { createDefer } from '@vitest/utils' 9 + import { createDefer } from '@vitest/utils/helpers' 10 10 import { Typechecker } from '../../typecheck/typechecker' 11 11 import { groupBy } from '../../utils/base' 12 12
+2 -5
packages/vitest/src/node/pools/vmForks.ts
··· 97 97 // avoid recreating forks when tests are finished 98 98 : 0 99 99 100 - const worker = resolve(vitest.distPath, 'workers/vmForks.js') 101 - 102 100 const options: TinypoolOptions = { 103 101 runtime: 'child_process', 104 - filename: resolve(vitest.distPath, 'worker.js'), 102 + filename: resolve(vitest.distPath, 'worker-vm.js'), 105 103 106 104 maxThreads, 107 105 minThreads, ··· 144 142 const { channel } = createChildProcessChannel(project, name === 'collect') 145 143 const workerId = ++id 146 144 const data: ContextRPC = { 147 - pool: 'forks', 148 - worker, 145 + pool: 'vmForks', 149 146 config, 150 147 files, 151 148 invalidates,
+1 -4
packages/vitest/src/node/pools/vmThreads.ts
··· 74 74 // avoid recreating threads when tests are finished 75 75 : 0 76 76 77 - const worker = resolve(vitest.distPath, 'workers/vmThreads.js') 78 - 79 77 const options: TinypoolOptions = { 80 - filename: resolve(vitest.distPath, 'worker.js'), 78 + filename: resolve(vitest.distPath, 'worker-vm.js'), 81 79 // TODO: investigate further 82 80 // It seems atomics introduced V8 Fatal Error https://github.com/vitest-dev/vitest/issues/1191 83 81 useAtomics: poolOptions.useAtomics ?? false, ··· 124 122 const workerId = ++id 125 123 const data: WorkerContext = { 126 124 pool: 'vmThreads', 127 - worker, 128 125 port: workerPort, 129 126 config, 130 127 files: paths,
+1 -1
packages/vitest/src/node/projects/resolveProjects.ts
··· 10 10 import { existsSync, readdirSync, statSync } from 'node:fs' 11 11 import os from 'node:os' 12 12 import { limitConcurrency } from '@vitest/runner/utils' 13 - import { deepClone } from '@vitest/utils' 13 + import { deepClone } from '@vitest/utils/helpers' 14 14 import { basename, dirname, relative, resolve } from 'pathe' 15 15 import { glob, isDynamicPattern } from 'tinyglobby' 16 16 import { mergeConfig } from 'vite'
+1 -1
packages/vitest/src/node/reporters/base.ts
··· 6 6 import type { TestCase, TestCollection, TestModule, TestModuleState, TestResult, TestSuite, TestSuiteState } from './reported-tasks' 7 7 import { performance } from 'node:perf_hooks' 8 8 import { getFullName, getSuites, getTestName, getTests, hasFailed } from '@vitest/runner/utils' 9 - import { toArray } from '@vitest/utils' 9 + import { toArray } from '@vitest/utils/helpers' 10 10 import { parseStacktrace } from '@vitest/utils/source-map' 11 11 import { relative } from 'pathe' 12 12 import c from 'tinyrainbow'
+1 -1
packages/vitest/src/node/sequencers/BaseSequencer.ts
··· 1 1 import type { Vitest } from '../core' 2 2 import type { TestSpecification } from '../spec' 3 3 import type { TestSequencer } from './types' 4 - import { slash } from '@vitest/utils' 4 + import { slash } from '@vitest/utils/helpers' 5 5 import { relative, resolve } from 'pathe' 6 6 import { hash } from '../hash' 7 7
+1 -1
packages/vitest/src/node/sequencers/RandomSequencer.ts
··· 1 1 import type { TestSpecification } from '../spec' 2 - import { shuffle } from '@vitest/utils' 2 + import { shuffle } from '@vitest/utils/helpers' 3 3 import { BaseSequencer } from './BaseSequencer' 4 4 5 5 export class RandomSequencer extends BaseSequencer {
+4 -3
packages/vitest/src/runtime/moduleRunner/errorCatcher.ts
··· 1 1 import type { WorkerGlobalState } from '../../types/worker' 2 - import { processError } from '@vitest/utils/error' 2 + import { serializeValue } from '@vitest/utils/serialize' 3 3 4 4 const dispose: (() => void)[] = [] 5 5 ··· 7 7 dispose.forEach(fn => fn()) 8 8 dispose.length = 0 9 9 10 - function catchError(err: unknown, type: string, event: 'uncaughtException' | 'unhandledRejection') { 10 + function catchError(err: any, type: string, event: 'uncaughtException' | 'unhandledRejection') { 11 11 const worker = state() 12 12 13 13 const listeners = process.listeners(event as 'uncaughtException') ··· 17 17 return 18 18 } 19 19 20 - const error = processError(err) 20 + const error = serializeValue(err) 21 + 21 22 if (typeof error === 'object' && error != null) { 22 23 error.VITEST_TEST_NAME = worker.current?.type === 'test' ? worker.current.name : undefined 23 24 if (worker.filepath) {
+2 -3
packages/vitest/src/runtime/moduleRunner/moduleMocker.ts
··· 6 6 import vm from 'node:vm' 7 7 import { AutomockedModule, MockerRegistry, mockObject, RedirectedModule } from '@vitest/mocker' 8 8 import { findMockRedirect } from '@vitest/mocker/redirect' 9 - import { highlight } from '@vitest/utils' 10 9 import { distDir } from '../../paths' 11 10 12 11 const spyModulePath = resolve(distDir, 'spy.js') ··· 239 238 `[vitest] No "${String(prop)}" export is defined on the "${mock.raw}" mock. ` 240 239 + 'Did you forget to return it from "vi.mock"?' 241 240 + '\nIf you need to partially mock a module, you can use "importOriginal" helper inside:\n', 242 - highlight(`vi.mock(import("${mock.raw}"), async (importOriginal) => { 241 + `vi.mock(import("${mock.raw}"), async (importOriginal) => { 243 242 const actual = await importOriginal() 244 243 return { 245 244 ...actual, 246 245 // your mocked methods 247 246 } 248 - })`), 247 + })`, 249 248 ) 250 249 } 251 250
+1 -1
packages/vitest/src/runtime/moduleRunner/startModuleRunner.ts
··· 5 5 import type { CreateImportMeta } from './moduleRunner' 6 6 import fs from 'node:fs' 7 7 import { isBuiltin } from 'node:module' 8 - import { isBareImport } from '@vitest/utils' 8 + import { isBareImport } from '@vitest/utils/helpers' 9 9 import { getCachedVitestImport } from './cachedResolver' 10 10 import { listenForErrors } from './errorCatcher' 11 11 import { unwrapId, VitestModuleEvaluator } from './moduleEvaluator'
+2 -1
packages/vitest/src/runtime/runners/benchmark.ts
··· 14 14 BenchTask, 15 15 } from '../types/benchmark' 16 16 import { updateTask as updateRunnerTask } from '@vitest/runner' 17 - import { createDefer, getSafeTimers } from '@vitest/utils' 17 + import { createDefer } from '@vitest/utils/helpers' 18 + import { getSafeTimers } from '@vitest/utils/timers' 18 19 import { getBenchFn, getBenchOptions } from '../benchmark' 19 20 import { getWorkerState } from '../utils' 20 21
-1
packages/vitest/src/runtime/runners/test.ts
··· 12 12 } from '@vitest/runner' 13 13 import type { ModuleRunner } from 'vite/module-runner' 14 14 import type { SerializedConfig } from '../config' 15 - // import type { VitestExecutor } from '../execute' 16 15 import { getState, GLOBAL_EXPECT, setState } from '@vitest/expect' 17 16 import { getNames, getTestName, getTests } from '@vitest/runner/utils' 18 17 import { processError } from '@vitest/utils/error'
+2 -1
packages/vitest/src/runtime/vm/vite-executor.ts
··· 4 4 import type { EsmExecutor } from './esm-executor' 5 5 import type { VMModule } from './types' 6 6 import { pathToFileURL } from 'node:url' 7 - import { CSS_LANGS_RE, KNOWN_ASSET_RE, toArray } from '@vitest/utils' 7 + import { CSS_LANGS_RE, KNOWN_ASSET_RE } from '@vitest/utils/constants' 8 + import { toArray } from '@vitest/utils/helpers' 8 9 import { SyntheticModule } from './utils' 9 10 10 11 interface ViteExecutorOptions {
+1 -2
packages/vitest/src/runtime/workers/base.ts
··· 37 37 modules.forEach((module) => { 38 38 state.evaluatedModules.invalidateModule(module) 39 39 }) 40 - // evaluatedModules.delete(fsPath) 41 - // evaluatedModules.delete(`mock:${fsPath}`) 42 40 }) 43 41 } 44 42 ctx.files.forEach((i) => { ··· 60 58 ? { filepath: f, testLocations: undefined } 61 59 : f, 62 60 ) 61 + // we could load @vite/env, but it would take ~8ms, while this takes ~0,02ms 63 62 if (ctx.config.serializedDefines) { 64 63 try { 65 64 runInThisContext(`(() =>{\n${ctx.config.serializedDefines}})()`, {
+20 -1
packages/vitest/src/runtime/workers/utils.ts
··· 2 2 import type { ResolvedConfig, SerializedConfig } from '../../node/types/config' 3 3 import type { WorkerContext } from '../../node/types/worker' 4 4 import type { WorkerRpcOptions } from './types' 5 - import { parseRegexp } from '@vitest/utils' 6 5 7 6 const REGEXP_WRAP_PREFIX = '$$vitest:' 8 7 ··· 90 89 } 91 90 92 91 return config 92 + } 93 + 94 + function parseRegexp(input: string): RegExp { 95 + // Parse input 96 + // eslint-disable-next-line regexp/no-misleading-capturing-group 97 + const m = input.match(/(\/?)(.+)\1([a-z]*)/i) 98 + 99 + // match nothing 100 + if (!m) { 101 + return /$^/ 102 + } 103 + 104 + // Invalid flags 105 + // eslint-disable-next-line regexp/optimal-quantifier-concatenation 106 + if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])) { 107 + return new RegExp(input) 108 + } 109 + 110 + // Create the regular expression 111 + return new RegExp(m[2], m[3]) 93 112 }
+1 -1
packages/browser/src/node/commands/screenshotMatcher/utils.ts
··· 3 3 import type { ScreenshotMatcherArguments } from '../../../shared/screenshotMatcher/types' 4 4 import type { AnyCodec } from './codecs' 5 5 import { platform } from 'node:os' 6 - import { deepMerge } from '@vitest/utils' 6 + import { deepMerge } from '@vitest/utils/helpers' 7 7 import { basename, dirname, extname, join, relative, resolve } from 'pathe' 8 8 import { takeScreenshot } from '../screenshot' 9 9 import { getCodec } from './codecs'
+1 -1
packages/vitest/src/node/reporters/benchmark/tableRender.ts
··· 3 3 import type { FormattedBenchmarkResult } from './json-formatter' 4 4 import { stripVTControlCharacters } from 'node:util' 5 5 import { getTests } from '@vitest/runner/utils' 6 - import { notNullish } from '@vitest/utils' 6 + import { notNullish } from '@vitest/utils/helpers' 7 7 import c from 'tinyrainbow' 8 8 import { F_RIGHT } from '../renderers/figures' 9 9 import { getStateSymbol, truncateString } from '../renderers/utils'
+1 -1
packages/vitest/src/node/reporters/renderers/utils.ts
··· 3 3 import type { Formatter } from 'tinyrainbow' 4 4 import type { TestProject } from '../../project' 5 5 import { stripVTControlCharacters } from 'node:util' 6 - import { slash } from '@vitest/utils' 6 + import { slash } from '@vitest/utils/helpers' 7 7 import { basename, dirname, isAbsolute, relative } from 'pathe' 8 8 import c from 'tinyrainbow' 9 9 import {