alpha
Login
or
Join now
danielroe.dev
/
nuxt-vitest
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
[READ-ONLY] Mirror of https://github.com/danielroe/nuxt-vitest. An vitest environment with support for testing code that needs a Nuxt runtime environment
nuxt
nuxt-module
testing
unit-testing
vitest
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
chore: refactor package structure
author
Daniel Roe
date
3 years ago
(Dec 19, 2022, 1:49 PM UTC)
commit
96037499
960374993601296656b27fa4af74c4b68205cd70
parent
b1e61faf
b1e61fafbfded8e03c3b4e3cabe41860da1844cb
+592
-127
12 changed files
Expand all
Collapse all
Unified
Split
config.d.ts
package.json
playground
package.json
tests
index.spec.ts
vitest.config.mjs
pnpm-lock.yaml
src
config.ts
index.ts
utils.ts
vitest-environment-nuxt
index.ts
package.json
utils.d.ts
+1
config.d.ts
View file
Reviewed
···
1
1
+
export * from './dist/config'
+39
-4
package.json
View file
Reviewed
···
1
1
{
2
2
-
"name": "nuxt-unit-test",
3
3
-
"scripts": {},
2
2
+
"name": "vitest-environment-nuxt",
3
3
+
"scripts": {
4
4
+
"build": "unbuild",
5
5
+
"dev:prepare": "unbuild --stub",
6
6
+
"test": "cd playground && pnpm vitest"
7
7
+
},
8
8
+
"main": "./dist/index.cjs",
9
9
+
"module": "./dist/index.mjs",
10
10
+
"exports": {
11
11
+
"./config": {
12
12
+
"require": "./dist/config.cjs",
13
13
+
"import": "./dist/config.mjs",
14
14
+
"types": "./dist/config.d.ts"
15
15
+
},
16
16
+
"./utils": {
17
17
+
"require": "./dist/utils.cjs",
18
18
+
"import": "./dist/utils.mjs",
19
19
+
"types": "./dist/utils.d.ts"
20
20
+
},
21
21
+
".": {
22
22
+
"require": "./dist/index.cjs",
23
23
+
"import": "./dist/index.mjs",
24
24
+
"types": "./dist/index.d.ts"
25
25
+
}
26
26
+
},
27
27
+
"files": [
28
28
+
"dist",
29
29
+
"config.d.ts",
30
30
+
"utils.d.ts"
31
31
+
],
4
32
"devDependencies": {
5
33
"nuxt": "3.0.0",
6
6
-
"vitest": "0.24.5",
7
7
-
"vitest-environment-nuxt": "link:./src/vitest-environment-nuxt"
34
34
+
"unbuild": "^1.0.2",
35
35
+
"vitest": "0.24.5"
36
36
+
},
37
37
+
"resolutions": {
38
38
+
"vitest-environment-nuxt": "workspace:*"
39
39
+
},
40
40
+
"peerDependencies": {
41
41
+
"nuxt": "3.0.0",
42
42
+
"vitest": "^0.24.5"
8
43
}
9
44
}
+1
playground/package.json
View file
Reviewed
···
12
12
"happy-dom": "^7.6.6",
13
13
"nuxt": "^3.0.0",
14
14
"vitest": "^0.24.5",
15
15
+
"vitest-environment-nuxt": "latest",
15
16
"vue": "^3.2.45"
16
17
}
17
18
}
+1
-2
playground/tests/index.spec.ts
View file
Reviewed
···
1
1
import { describe, it, expect } from 'vitest'
2
2
3
3
-
import { mountSuspended } from '../../src/runtime/mount'
4
4
-
import { registerEndpoint } from '../../src/runtime/mock'
3
3
+
import { mountSuspended, registerEndpoint } from 'vitest-environment-nuxt/utils'
5
4
6
5
import App from '~/app.vue'
7
6
import FetchComponent from '~/components/FetchComponent.vue'
+13
-2
playground/vitest.config.mjs
View file
Reviewed
···
1
1
import { defineConfig } from 'vite'
2
2
-
import { getVitestConfig } from '../src'
2
2
+
import { getVitestConfig } from 'vitest-environment-nuxt/config'
3
3
4
4
const viteConfig = await getVitestConfig()
5
5
6
6
-
export default defineConfig(viteConfig)
6
6
+
export default defineConfig({
7
7
+
...viteConfig,
8
8
+
resolve: {
9
9
+
...viteConfig.resolve,
10
10
+
alias: {
11
11
+
...viteConfig.resolve?.alias,
12
12
+
// TODO: fix bug with stubbing root package
13
13
+
'vitest-environment-nuxt/utils': '../src/utils',
14
14
+
'vitest-environment-nuxt': '../src/index',
15
15
+
},
16
16
+
},
17
17
+
})
+419
-2
pnpm-lock.yaml
View file
Reviewed
···
1
1
lockfileVersion: 5.4
2
2
3
3
+
overrides:
4
4
+
vitest-environment-nuxt: workspace:*
5
5
+
3
6
importers:
4
7
5
8
.:
6
9
specifiers:
7
10
nuxt: 3.0.0
11
11
+
unbuild: ^1.0.2
8
12
vitest: 0.24.5
9
9
-
vitest-environment-nuxt: link:./src/vitest-environment-nuxt
10
13
devDependencies:
11
14
nuxt: 3.0.0
15
15
+
unbuild: 1.0.2
12
16
vitest: 0.24.5
13
13
-
vitest-environment-nuxt: link:src/vitest-environment-nuxt
14
17
15
18
playground:
16
19
specifiers:
···
18
21
happy-dom: ^7.6.6
19
22
nuxt: ^3.0.0
20
23
vitest: ^0.24.5
24
24
+
vitest-environment-nuxt: workspace:*
21
25
vue: ^3.2.45
22
26
devDependencies:
23
27
'@vue/test-utils': 2.2.1_vue@3.2.45
24
28
happy-dom: 7.6.6
25
29
nuxt: 3.0.0
26
30
vitest: 0.24.5_happy-dom@7.6.6
31
31
+
vitest-environment-nuxt: link:..
27
32
vue: 3.2.45
28
33
29
34
packages:
···
349
354
dev: true
350
355
optional: true
351
356
357
357
+
/@esbuild/android-arm/0.15.18:
358
358
+
resolution: {integrity: sha512-5GT+kcs2WVGjVs7+boataCkO5Fg0y4kCjzkB5bAip7H4jfnOS3dA6KPiww9W1OEKTKeAcUVhdZGvgI65OXmUnw==}
359
359
+
engines: {node: '>=12'}
360
360
+
cpu: [arm]
361
361
+
os: [android]
362
362
+
requiresBuild: true
363
363
+
dev: true
364
364
+
optional: true
365
365
+
352
366
/@esbuild/linux-loong64/0.15.13:
353
367
resolution: {integrity: sha512-+BoyIm4I8uJmH/QDIH0fu7MG0AEx9OXEDXnqptXCwKOlOqZiS4iraH1Nr7/ObLMokW3sOCeBNyD68ATcV9b9Ag==}
354
368
engines: {node: '>=12'}
···
360
374
361
375
/@esbuild/linux-loong64/0.15.16:
362
376
resolution: {integrity: sha512-SDLfP1uoB0HZ14CdVYgagllgrG7Mdxhkt4jDJOKl/MldKrkQ6vDJMZKl2+5XsEY/Lzz37fjgLQoJBGuAw/x8kQ==}
377
377
+
engines: {node: '>=12'}
378
378
+
cpu: [loong64]
379
379
+
os: [linux]
380
380
+
requiresBuild: true
381
381
+
dev: true
382
382
+
optional: true
383
383
+
384
384
+
/@esbuild/linux-loong64/0.15.18:
385
385
+
resolution: {integrity: sha512-L4jVKS82XVhw2nvzLg/19ClLWg0y27ulRwuP7lcyL6AbUWB5aPglXY3M21mauDQMDfRLs8cQmeT03r/+X3cZYQ==}
363
386
engines: {node: '>=12'}
364
387
cpu: [loong64]
365
388
os: [linux]
···
662
685
slash: 4.0.0
663
686
dev: true
664
687
688
688
+
/@rollup/plugin-alias/4.0.2_rollup@3.7.5:
689
689
+
resolution: {integrity: sha512-1hv7dBOZZwo3SEupxn4UA2N0EDThqSSS+wI1St1TNTBtOZvUchyIClyHcnDcjjrReTPZ47Faedrhblv4n+T5UQ==}
690
690
+
engines: {node: '>=14.0.0'}
691
691
+
peerDependencies:
692
692
+
rollup: ^1.20.0||^2.0.0||^3.0.0
693
693
+
peerDependenciesMeta:
694
694
+
rollup:
695
695
+
optional: true
696
696
+
dependencies:
697
697
+
rollup: 3.7.5
698
698
+
slash: 4.0.0
699
699
+
dev: true
700
700
+
665
701
/@rollup/plugin-commonjs/23.0.2_rollup@2.79.1:
666
702
resolution: {integrity: sha512-e9ThuiRf93YlVxc4qNIurvv+Hp9dnD+4PjOqQs5vAYfcZ3+AXSrcdzXnVjWxcGQOa6KGJFcRZyUI3ktWLavFjg==}
667
703
engines: {node: '>=14.0.0'}
···
680
716
rollup: 2.79.1
681
717
dev: true
682
718
719
719
+
/@rollup/plugin-commonjs/23.0.7_rollup@3.7.5:
720
720
+
resolution: {integrity: sha512-hsSD5Qzyuat/swzrExGG5l7EuIlPhwTsT7KwKbSCQzIcJWjRxiimi/0tyMYY2bByitNb3i1p+6JWEDGa0NvT0Q==}
721
721
+
engines: {node: '>=14.0.0'}
722
722
+
peerDependencies:
723
723
+
rollup: ^2.68.0||^3.0.0
724
724
+
peerDependenciesMeta:
725
725
+
rollup:
726
726
+
optional: true
727
727
+
dependencies:
728
728
+
'@rollup/pluginutils': 5.0.2_rollup@3.7.5
729
729
+
commondir: 1.0.1
730
730
+
estree-walker: 2.0.2
731
731
+
glob: 8.0.3
732
732
+
is-reference: 1.2.1
733
733
+
magic-string: 0.27.0
734
734
+
rollup: 3.7.5
735
735
+
dev: true
736
736
+
683
737
/@rollup/plugin-inject/5.0.2_rollup@2.79.1:
684
738
resolution: {integrity: sha512-zRthPC/sZ2OaQwPh2LvFn0A+3SyMAZR1Vqsp89mWkIuGXKswT8ty1JWj1pf7xdZvft4gHZaCuhdopuiCwjclWg==}
685
739
engines: {node: '>=14.0.0'}
···
708
762
rollup: 2.79.1
709
763
dev: true
710
764
765
765
+
/@rollup/plugin-json/5.0.2_rollup@3.7.5:
766
766
+
resolution: {integrity: sha512-D1CoOT2wPvadWLhVcmpkDnesTzjhNIQRWLsc3fA49IFOP2Y84cFOOJ+nKGYedvXHKUsPeq07HR4hXpBBr+CHlA==}
767
767
+
engines: {node: '>=14.0.0'}
768
768
+
peerDependencies:
769
769
+
rollup: ^1.20.0||^2.0.0||^3.0.0
770
770
+
peerDependenciesMeta:
771
771
+
rollup:
772
772
+
optional: true
773
773
+
dependencies:
774
774
+
'@rollup/pluginutils': 5.0.2_rollup@3.7.5
775
775
+
rollup: 3.7.5
776
776
+
dev: true
777
777
+
711
778
/@rollup/plugin-node-resolve/15.0.1_rollup@2.79.1:
712
779
resolution: {integrity: sha512-ReY88T7JhJjeRVbfCyNj+NXAG3IIsVMsX9b5/9jC98dRP8/yxlZdz7mHZbHk5zHr24wZZICS5AcXsFZAXYUQEg==}
713
780
engines: {node: '>=14.0.0'}
···
726
793
rollup: 2.79.1
727
794
dev: true
728
795
796
796
+
/@rollup/plugin-node-resolve/15.0.1_rollup@3.7.5:
797
797
+
resolution: {integrity: sha512-ReY88T7JhJjeRVbfCyNj+NXAG3IIsVMsX9b5/9jC98dRP8/yxlZdz7mHZbHk5zHr24wZZICS5AcXsFZAXYUQEg==}
798
798
+
engines: {node: '>=14.0.0'}
799
799
+
peerDependencies:
800
800
+
rollup: ^2.78.0||^3.0.0
801
801
+
peerDependenciesMeta:
802
802
+
rollup:
803
803
+
optional: true
804
804
+
dependencies:
805
805
+
'@rollup/pluginutils': 5.0.2_rollup@3.7.5
806
806
+
'@types/resolve': 1.20.2
807
807
+
deepmerge: 4.2.2
808
808
+
is-builtin-module: 3.2.0
809
809
+
is-module: 1.0.0
810
810
+
resolve: 1.22.1
811
811
+
rollup: 3.7.5
812
812
+
dev: true
813
813
+
729
814
/@rollup/plugin-replace/5.0.1_rollup@2.79.1:
730
815
resolution: {integrity: sha512-Z3MfsJ4CK17BfGrZgvrcp/l6WXoKb0kokULO+zt/7bmcyayokDaQ2K3eDJcRLCTAlp5FPI4/gz9MHAsosz4Rag==}
731
816
engines: {node: '>=14.0.0'}
···
738
823
'@rollup/pluginutils': 5.0.2_rollup@2.79.1
739
824
magic-string: 0.26.7
740
825
rollup: 2.79.1
826
826
+
dev: true
827
827
+
828
828
+
/@rollup/plugin-replace/5.0.1_rollup@3.7.5:
829
829
+
resolution: {integrity: sha512-Z3MfsJ4CK17BfGrZgvrcp/l6WXoKb0kokULO+zt/7bmcyayokDaQ2K3eDJcRLCTAlp5FPI4/gz9MHAsosz4Rag==}
830
830
+
engines: {node: '>=14.0.0'}
831
831
+
peerDependencies:
832
832
+
rollup: ^1.20.0||^2.0.0||^3.0.0
833
833
+
peerDependenciesMeta:
834
834
+
rollup:
835
835
+
optional: true
836
836
+
dependencies:
837
837
+
'@rollup/pluginutils': 5.0.2_rollup@3.7.5
838
838
+
magic-string: 0.26.7
839
839
+
rollup: 3.7.5
741
840
dev: true
742
841
743
842
/@rollup/plugin-wasm/6.0.1_rollup@2.79.1:
···
781
880
rollup: 2.79.1
782
881
dev: true
783
882
883
883
+
/@rollup/pluginutils/5.0.2_rollup@3.7.5:
884
884
+
resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==}
885
885
+
engines: {node: '>=14.0.0'}
886
886
+
peerDependencies:
887
887
+
rollup: ^1.20.0||^2.0.0||^3.0.0
888
888
+
peerDependenciesMeta:
889
889
+
rollup:
890
890
+
optional: true
891
891
+
dependencies:
892
892
+
'@types/estree': 1.0.0
893
893
+
estree-walker: 2.0.2
894
894
+
picomatch: 2.3.1
895
895
+
rollup: 3.7.5
896
896
+
dev: true
897
897
+
784
898
/@trysound/sax/0.2.0:
785
899
resolution: {integrity: sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA==}
786
900
engines: {node: '>=10.13.0'}
···
1915
2029
dev: true
1916
2030
optional: true
1917
2031
2032
2032
+
/esbuild-android-64/0.15.18:
2033
2033
+
resolution: {integrity: sha512-wnpt3OXRhcjfIDSZu9bnzT4/TNTDsOUvip0foZOUBG7QbSt//w3QV4FInVJxNhKc/ErhUxc5z4QjHtMi7/TbgA==}
2034
2034
+
engines: {node: '>=12'}
2035
2035
+
cpu: [x64]
2036
2036
+
os: [android]
2037
2037
+
requiresBuild: true
2038
2038
+
dev: true
2039
2039
+
optional: true
2040
2040
+
1918
2041
/esbuild-android-arm64/0.15.13:
1919
2042
resolution: {integrity: sha512-TKzyymLD6PiVeyYa4c5wdPw87BeAiTXNtK6amWUcXZxkV51gOk5u5qzmDaYSwiWeecSNHamFsaFjLoi32QR5/w==}
1920
2043
engines: {node: '>=12'}
···
1933
2056
dev: true
1934
2057
optional: true
1935
2058
2059
2059
+
/esbuild-android-arm64/0.15.18:
2060
2060
+
resolution: {integrity: sha512-G4xu89B8FCzav9XU8EjsXacCKSG2FT7wW9J6hOc18soEHJdtWu03L3TQDGf0geNxfLTtxENKBzMSq9LlbjS8OQ==}
2061
2061
+
engines: {node: '>=12'}
2062
2062
+
cpu: [arm64]
2063
2063
+
os: [android]
2064
2064
+
requiresBuild: true
2065
2065
+
dev: true
2066
2066
+
optional: true
2067
2067
+
1936
2068
/esbuild-darwin-64/0.15.13:
1937
2069
resolution: {integrity: sha512-WAx7c2DaOS6CrRcoYCgXgkXDliLnFv3pQLV6GeW1YcGEZq2Gnl8s9Pg7ahValZkpOa0iE/ojRVQ87sbUhF1Cbg==}
1938
2070
engines: {node: '>=12'}
···
1951
2083
dev: true
1952
2084
optional: true
1953
2085
2086
2086
+
/esbuild-darwin-64/0.15.18:
2087
2087
+
resolution: {integrity: sha512-2WAvs95uPnVJPuYKP0Eqx+Dl/jaYseZEUUT1sjg97TJa4oBtbAKnPnl3b5M9l51/nbx7+QAEtuummJZW0sBEmg==}
2088
2088
+
engines: {node: '>=12'}
2089
2089
+
cpu: [x64]
2090
2090
+
os: [darwin]
2091
2091
+
requiresBuild: true
2092
2092
+
dev: true
2093
2093
+
optional: true
2094
2094
+
1954
2095
/esbuild-darwin-arm64/0.15.13:
1955
2096
resolution: {integrity: sha512-U6jFsPfSSxC3V1CLiQqwvDuj3GGrtQNB3P3nNC3+q99EKf94UGpsG9l4CQ83zBs1NHrk1rtCSYT0+KfK5LsD8A==}
1956
2097
engines: {node: '>=12'}
···
1962
2103
1963
2104
/esbuild-darwin-arm64/0.15.16:
1964
2105
resolution: {integrity: sha512-fMXaUr5ou0M4WnewBKsspMtX++C1yIa3nJ5R2LSbLCfJT3uFdcRoU/NZjoM4kOMKyOD9Sa/2vlgN8G07K3SJnw==}
2106
2106
+
engines: {node: '>=12'}
2107
2107
+
cpu: [arm64]
2108
2108
+
os: [darwin]
2109
2109
+
requiresBuild: true
2110
2110
+
dev: true
2111
2111
+
optional: true
2112
2112
+
2113
2113
+
/esbuild-darwin-arm64/0.15.18:
2114
2114
+
resolution: {integrity: sha512-tKPSxcTJ5OmNb1btVikATJ8NftlyNlc8BVNtyT/UAr62JFOhwHlnoPrhYWz09akBLHI9nElFVfWSTSRsrZiDUA==}
1965
2115
engines: {node: '>=12'}
1966
2116
cpu: [arm64]
1967
2117
os: [darwin]
···
1987
2137
dev: true
1988
2138
optional: true
1989
2139
2140
2140
+
/esbuild-freebsd-64/0.15.18:
2141
2141
+
resolution: {integrity: sha512-TT3uBUxkteAjR1QbsmvSsjpKjOX6UkCstr8nMr+q7zi3NuZ1oIpa8U41Y8I8dJH2fJgdC3Dj3CXO5biLQpfdZA==}
2142
2142
+
engines: {node: '>=12'}
2143
2143
+
cpu: [x64]
2144
2144
+
os: [freebsd]
2145
2145
+
requiresBuild: true
2146
2146
+
dev: true
2147
2147
+
optional: true
2148
2148
+
1990
2149
/esbuild-freebsd-arm64/0.15.13:
1991
2150
resolution: {integrity: sha512-6pCSWt8mLUbPtygv7cufV0sZLeylaMwS5Fznj6Rsx9G2AJJsAjQ9ifA+0rQEIg7DwJmi9it+WjzNTEAzzdoM3Q==}
1992
2151
engines: {node: '>=12'}
···
2005
2164
dev: true
2006
2165
optional: true
2007
2166
2167
2167
+
/esbuild-freebsd-arm64/0.15.18:
2168
2168
+
resolution: {integrity: sha512-R/oVr+X3Tkh+S0+tL41wRMbdWtpWB8hEAMsOXDumSSa6qJR89U0S/PpLXrGF7Wk/JykfpWNokERUpCeHDl47wA==}
2169
2169
+
engines: {node: '>=12'}
2170
2170
+
cpu: [arm64]
2171
2171
+
os: [freebsd]
2172
2172
+
requiresBuild: true
2173
2173
+
dev: true
2174
2174
+
optional: true
2175
2175
+
2008
2176
/esbuild-linux-32/0.15.13:
2009
2177
resolution: {integrity: sha512-VbZdWOEdrJiYApm2kkxoTOgsoCO1krBZ3quHdYk3g3ivWaMwNIVPIfEE0f0XQQ0u5pJtBsnk2/7OPiCFIPOe/w==}
2010
2178
engines: {node: '>=12'}
···
2023
2191
dev: true
2024
2192
optional: true
2025
2193
2194
2194
+
/esbuild-linux-32/0.15.18:
2195
2195
+
resolution: {integrity: sha512-lphF3HiCSYtaa9p1DtXndiQEeQDKPl9eN/XNoBf2amEghugNuqXNZA/ZovthNE2aa4EN43WroO0B85xVSjYkbg==}
2196
2196
+
engines: {node: '>=12'}
2197
2197
+
cpu: [ia32]
2198
2198
+
os: [linux]
2199
2199
+
requiresBuild: true
2200
2200
+
dev: true
2201
2201
+
optional: true
2202
2202
+
2026
2203
/esbuild-linux-64/0.15.13:
2027
2204
resolution: {integrity: sha512-rXmnArVNio6yANSqDQlIO4WiP+Cv7+9EuAHNnag7rByAqFVuRusLbGi2697A5dFPNXoO//IiogVwi3AdcfPC6A==}
2028
2205
engines: {node: '>=12'}
···
2041
2218
dev: true
2042
2219
optional: true
2043
2220
2221
2221
+
/esbuild-linux-64/0.15.18:
2222
2222
+
resolution: {integrity: sha512-hNSeP97IviD7oxLKFuii5sDPJ+QHeiFTFLoLm7NZQligur8poNOWGIgpQ7Qf8Balb69hptMZzyOBIPtY09GZYw==}
2223
2223
+
engines: {node: '>=12'}
2224
2224
+
cpu: [x64]
2225
2225
+
os: [linux]
2226
2226
+
requiresBuild: true
2227
2227
+
dev: true
2228
2228
+
optional: true
2229
2229
+
2044
2230
/esbuild-linux-arm/0.15.13:
2045
2231
resolution: {integrity: sha512-Ac6LpfmJO8WhCMQmO253xX2IU2B3wPDbl4IvR0hnqcPrdfCaUa2j/lLMGTjmQ4W5JsJIdHEdW12dG8lFS0MbxQ==}
2046
2232
engines: {node: '>=12'}
···
2052
2238
2053
2239
/esbuild-linux-arm/0.15.16:
2054
2240
resolution: {integrity: sha512-XKcrxCEXDTOuoRj5l12tJnkvuxXBMKwEC5j0JISw3ziLf0j4zIwXbKbTmUrKFWbo6ZgvNpa7Y5dnbsjVvH39bQ==}
2241
2241
+
engines: {node: '>=12'}
2242
2242
+
cpu: [arm]
2243
2243
+
os: [linux]
2244
2244
+
requiresBuild: true
2245
2245
+
dev: true
2246
2246
+
optional: true
2247
2247
+
2248
2248
+
/esbuild-linux-arm/0.15.18:
2249
2249
+
resolution: {integrity: sha512-UH779gstRblS4aoS2qpMl3wjg7U0j+ygu3GjIeTonCcN79ZvpPee12Qun3vcdxX+37O5LFxz39XeW2I9bybMVA==}
2055
2250
engines: {node: '>=12'}
2056
2251
cpu: [arm]
2057
2252
os: [linux]
···
2077
2272
dev: true
2078
2273
optional: true
2079
2274
2275
2275
+
/esbuild-linux-arm64/0.15.18:
2276
2276
+
resolution: {integrity: sha512-54qr8kg/6ilcxd+0V3h9rjT4qmjc0CccMVWrjOEM/pEcUzt8X62HfBSeZfT2ECpM7104mk4yfQXkosY8Quptug==}
2277
2277
+
engines: {node: '>=12'}
2278
2278
+
cpu: [arm64]
2279
2279
+
os: [linux]
2280
2280
+
requiresBuild: true
2281
2281
+
dev: true
2282
2282
+
optional: true
2283
2283
+
2080
2284
/esbuild-linux-mips64le/0.15.13:
2081
2285
resolution: {integrity: sha512-47PgmyYEu+yN5rD/MbwS6DxP2FSGPo4Uxg5LwIdxTiyGC2XKwHhHyW7YYEDlSuXLQXEdTO7mYe8zQ74czP7W8A==}
2082
2286
engines: {node: '>=12'}
···
2095
2299
dev: true
2096
2300
optional: true
2097
2301
2302
2302
+
/esbuild-linux-mips64le/0.15.18:
2303
2303
+
resolution: {integrity: sha512-Mk6Ppwzzz3YbMl/ZZL2P0q1tnYqh/trYZ1VfNP47C31yT0K8t9s7Z077QrDA/guU60tGNp2GOwCQnp+DYv7bxQ==}
2304
2304
+
engines: {node: '>=12'}
2305
2305
+
cpu: [mips64el]
2306
2306
+
os: [linux]
2307
2307
+
requiresBuild: true
2308
2308
+
dev: true
2309
2309
+
optional: true
2310
2310
+
2098
2311
/esbuild-linux-ppc64le/0.15.13:
2099
2312
resolution: {integrity: sha512-z6n28h2+PC1Ayle9DjKoBRcx/4cxHoOa2e689e2aDJSaKug3jXcQw7mM+GLg+9ydYoNzj8QxNL8ihOv/OnezhA==}
2100
2313
engines: {node: '>=12'}
···
2113
2326
dev: true
2114
2327
optional: true
2115
2328
2329
2329
+
/esbuild-linux-ppc64le/0.15.18:
2330
2330
+
resolution: {integrity: sha512-b0XkN4pL9WUulPTa/VKHx2wLCgvIAbgwABGnKMY19WhKZPT+8BxhZdqz6EgkqCLld7X5qiCY2F/bfpUUlnFZ9w==}
2331
2331
+
engines: {node: '>=12'}
2332
2332
+
cpu: [ppc64]
2333
2333
+
os: [linux]
2334
2334
+
requiresBuild: true
2335
2335
+
dev: true
2336
2336
+
optional: true
2337
2337
+
2116
2338
/esbuild-linux-riscv64/0.15.13:
2117
2339
resolution: {integrity: sha512-+Lu4zuuXuQhgLUGyZloWCqTslcCAjMZH1k3Xc9MSEJEpEFdpsSU0sRDXAnk18FKOfEjhu4YMGaykx9xjtpA6ow==}
2118
2340
engines: {node: '>=12'}
···
2124
2346
2125
2347
/esbuild-linux-riscv64/0.15.16:
2126
2348
resolution: {integrity: sha512-ty2YUHZlwFOwp7pR+J87M4CVrXJIf5ZZtU/umpxgVJBXvWjhziSLEQxvl30SYfUPq0nzeWKBGw5i/DieiHeKfw==}
2349
2349
+
engines: {node: '>=12'}
2350
2350
+
cpu: [riscv64]
2351
2351
+
os: [linux]
2352
2352
+
requiresBuild: true
2353
2353
+
dev: true
2354
2354
+
optional: true
2355
2355
+
2356
2356
+
/esbuild-linux-riscv64/0.15.18:
2357
2357
+
resolution: {integrity: sha512-ba2COaoF5wL6VLZWn04k+ACZjZ6NYniMSQStodFKH/Pu6RxzQqzsmjR1t9QC89VYJxBeyVPTaHuBMCejl3O/xg==}
2127
2358
engines: {node: '>=12'}
2128
2359
cpu: [riscv64]
2129
2360
os: [linux]
···
2149
2380
dev: true
2150
2381
optional: true
2151
2382
2383
2383
+
/esbuild-linux-s390x/0.15.18:
2384
2384
+
resolution: {integrity: sha512-VbpGuXEl5FCs1wDVp93O8UIzl3ZrglgnSQ+Hu79g7hZu6te6/YHgVJxCM2SqfIila0J3k0csfnf8VD2W7u2kzQ==}
2385
2385
+
engines: {node: '>=12'}
2386
2386
+
cpu: [s390x]
2387
2387
+
os: [linux]
2388
2388
+
requiresBuild: true
2389
2389
+
dev: true
2390
2390
+
optional: true
2391
2391
+
2152
2392
/esbuild-netbsd-64/0.15.13:
2153
2393
resolution: {integrity: sha512-EHj9QZOTel581JPj7UO3xYbltFTYnHy+SIqJVq6yd3KkCrsHRbapiPb0Lx3EOOtybBEE9EyqbmfW1NlSDsSzvQ==}
2154
2394
engines: {node: '>=12'}
···
2167
2407
dev: true
2168
2408
optional: true
2169
2409
2410
2410
+
/esbuild-netbsd-64/0.15.18:
2411
2411
+
resolution: {integrity: sha512-98ukeCdvdX7wr1vUYQzKo4kQ0N2p27H7I11maINv73fVEXt2kyh4K4m9f35U1K43Xc2QGXlzAw0K9yoU7JUjOg==}
2412
2412
+
engines: {node: '>=12'}
2413
2413
+
cpu: [x64]
2414
2414
+
os: [netbsd]
2415
2415
+
requiresBuild: true
2416
2416
+
dev: true
2417
2417
+
optional: true
2418
2418
+
2170
2419
/esbuild-openbsd-64/0.15.13:
2171
2420
resolution: {integrity: sha512-nkuDlIjF/sfUhfx8SKq0+U+Fgx5K9JcPq1mUodnxI0x4kBdCv46rOGWbuJ6eof2n3wdoCLccOoJAbg9ba/bT2w==}
2172
2421
engines: {node: '>=12'}
···
2178
2427
2179
2428
/esbuild-openbsd-64/0.15.16:
2180
2429
resolution: {integrity: sha512-KgxMHyxMCT+NdLQE1zVJEsLSt2QQBAvJfmUGDmgEq8Fvjrf6vSKB00dVHUEDKcJwMID6CdgCpvYNt999tIYhqA==}
2430
2430
+
engines: {node: '>=12'}
2431
2431
+
cpu: [x64]
2432
2432
+
os: [openbsd]
2433
2433
+
requiresBuild: true
2434
2434
+
dev: true
2435
2435
+
optional: true
2436
2436
+
2437
2437
+
/esbuild-openbsd-64/0.15.18:
2438
2438
+
resolution: {integrity: sha512-yK5NCcH31Uae076AyQAXeJzt/vxIo9+omZRKj1pauhk3ITuADzuOx5N2fdHrAKPxN+zH3w96uFKlY7yIn490xQ==}
2181
2439
engines: {node: '>=12'}
2182
2440
cpu: [x64]
2183
2441
os: [openbsd]
···
2203
2461
dev: true
2204
2462
optional: true
2205
2463
2464
2464
+
/esbuild-sunos-64/0.15.18:
2465
2465
+
resolution: {integrity: sha512-On22LLFlBeLNj/YF3FT+cXcyKPEI263nflYlAhz5crxtp3yRG1Ugfr7ITyxmCmjm4vbN/dGrb/B7w7U8yJR9yw==}
2466
2466
+
engines: {node: '>=12'}
2467
2467
+
cpu: [x64]
2468
2468
+
os: [sunos]
2469
2469
+
requiresBuild: true
2470
2470
+
dev: true
2471
2471
+
optional: true
2472
2472
+
2206
2473
/esbuild-windows-32/0.15.13:
2207
2474
resolution: {integrity: sha512-XoF2iBf0wnqo16SDq+aDGi/+QbaLFpkiRarPVssMh9KYbFNCqPLlGAWwDvxEVz+ywX6Si37J2AKm+AXq1kC0JA==}
2208
2475
engines: {node: '>=12'}
···
2221
2488
dev: true
2222
2489
optional: true
2223
2490
2491
2491
+
/esbuild-windows-32/0.15.18:
2492
2492
+
resolution: {integrity: sha512-o+eyLu2MjVny/nt+E0uPnBxYuJHBvho8vWsC2lV61A7wwTWC3jkN2w36jtA+yv1UgYkHRihPuQsL23hsCYGcOQ==}
2493
2493
+
engines: {node: '>=12'}
2494
2494
+
cpu: [ia32]
2495
2495
+
os: [win32]
2496
2496
+
requiresBuild: true
2497
2497
+
dev: true
2498
2498
+
optional: true
2499
2499
+
2224
2500
/esbuild-windows-64/0.15.13:
2225
2501
resolution: {integrity: sha512-Et6htEfGycjDrtqb2ng6nT+baesZPYQIW+HUEHK4D1ncggNrDNk3yoboYQ5KtiVrw/JaDMNttz8rrPubV/fvPQ==}
2226
2502
engines: {node: '>=12'}
···
2232
2508
2233
2509
/esbuild-windows-64/0.15.16:
2234
2510
resolution: {integrity: sha512-HjW1hHRLSncnM3MBCP7iquatHVJq9l0S2xxsHHj4yzf4nm9TU4Z7k4NkeMlD/dHQ4jPlQQhwcMvwbJiOefSuZw==}
2511
2511
+
engines: {node: '>=12'}
2512
2512
+
cpu: [x64]
2513
2513
+
os: [win32]
2514
2514
+
requiresBuild: true
2515
2515
+
dev: true
2516
2516
+
optional: true
2517
2517
+
2518
2518
+
/esbuild-windows-64/0.15.18:
2519
2519
+
resolution: {integrity: sha512-qinug1iTTaIIrCorAUjR0fcBk24fjzEedFYhhispP8Oc7SFvs+XeW3YpAKiKp8dRpizl4YYAhxMjlftAMJiaUw==}
2235
2520
engines: {node: '>=12'}
2236
2521
cpu: [x64]
2237
2522
os: [win32]
···
2257
2542
dev: true
2258
2543
optional: true
2259
2544
2545
2545
+
/esbuild-windows-arm64/0.15.18:
2546
2546
+
resolution: {integrity: sha512-q9bsYzegpZcLziq0zgUi5KqGVtfhjxGbnksaBFYmWLxeV/S1fK4OLdq2DFYnXcLMjlZw2L0jLsk1eGoB522WXQ==}
2547
2547
+
engines: {node: '>=12'}
2548
2548
+
cpu: [arm64]
2549
2549
+
os: [win32]
2550
2550
+
requiresBuild: true
2551
2551
+
dev: true
2552
2552
+
optional: true
2553
2553
+
2260
2554
/esbuild/0.15.13:
2261
2555
resolution: {integrity: sha512-Cu3SC84oyzzhrK/YyN4iEVy2jZu5t2fz66HEOShHURcjSkOSAVL8C/gfUT+lDJxkVHpg8GZ10DD0rMHRPqMFaQ==}
2262
2556
engines: {node: '>=12'}
···
2317
2611
esbuild-windows-arm64: 0.15.16
2318
2612
dev: true
2319
2613
2614
2614
+
/esbuild/0.15.18:
2615
2615
+
resolution: {integrity: sha512-x/R72SmW3sSFRm5zrrIjAhCeQSAWoni3CmHEqfQrZIQTM3lVCdehdwuIqaOtfC2slvpdlLa62GYoN8SxT23m6Q==}
2616
2616
+
engines: {node: '>=12'}
2617
2617
+
hasBin: true
2618
2618
+
requiresBuild: true
2619
2619
+
optionalDependencies:
2620
2620
+
'@esbuild/android-arm': 0.15.18
2621
2621
+
'@esbuild/linux-loong64': 0.15.18
2622
2622
+
esbuild-android-64: 0.15.18
2623
2623
+
esbuild-android-arm64: 0.15.18
2624
2624
+
esbuild-darwin-64: 0.15.18
2625
2625
+
esbuild-darwin-arm64: 0.15.18
2626
2626
+
esbuild-freebsd-64: 0.15.18
2627
2627
+
esbuild-freebsd-arm64: 0.15.18
2628
2628
+
esbuild-linux-32: 0.15.18
2629
2629
+
esbuild-linux-64: 0.15.18
2630
2630
+
esbuild-linux-arm: 0.15.18
2631
2631
+
esbuild-linux-arm64: 0.15.18
2632
2632
+
esbuild-linux-mips64le: 0.15.18
2633
2633
+
esbuild-linux-ppc64le: 0.15.18
2634
2634
+
esbuild-linux-riscv64: 0.15.18
2635
2635
+
esbuild-linux-s390x: 0.15.18
2636
2636
+
esbuild-netbsd-64: 0.15.18
2637
2637
+
esbuild-openbsd-64: 0.15.18
2638
2638
+
esbuild-sunos-64: 0.15.18
2639
2639
+
esbuild-windows-32: 0.15.18
2640
2640
+
esbuild-windows-64: 0.15.18
2641
2641
+
esbuild-windows-arm64: 0.15.18
2642
2642
+
dev: true
2643
2643
+
2320
2644
/escalade/3.1.1:
2321
2645
resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==}
2322
2646
engines: {node: '>=6'}
···
3146
3470
sourcemap-codec: 1.4.8
3147
3471
dev: true
3148
3472
3473
3473
+
/magic-string/0.27.0:
3474
3474
+
resolution: {integrity: sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==}
3475
3475
+
engines: {node: '>=12'}
3476
3476
+
dependencies:
3477
3477
+
'@jridgewell/sourcemap-codec': 1.4.14
3478
3478
+
dev: true
3479
3479
+
3149
3480
/make-dir/3.1.0:
3150
3481
resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==}
3151
3482
engines: {node: '>=8'}
···
3286
3617
hasBin: true
3287
3618
dev: true
3288
3619
3620
3620
+
/mkdist/1.0.0_typescript@4.9.4:
3621
3621
+
resolution: {integrity: sha512-aJke+yvXwwcrOh+3KfAdDgDA+MPe7c+R8hQ7IPfp0gqL1/WPZZUS9rwS6CNjdwDJmHm6DTMA9KwX1FNjZG3I1Q==}
3622
3622
+
hasBin: true
3623
3623
+
peerDependencies:
3624
3624
+
sass: ^1.56.1
3625
3625
+
typescript: '>=4.8.4'
3626
3626
+
peerDependenciesMeta:
3627
3627
+
sass:
3628
3628
+
optional: true
3629
3629
+
typescript:
3630
3630
+
optional: true
3631
3631
+
dependencies:
3632
3632
+
defu: 6.1.1
3633
3633
+
esbuild: 0.15.18
3634
3634
+
fs-extra: 10.1.0
3635
3635
+
globby: 13.1.2
3636
3636
+
jiti: 1.16.0
3637
3637
+
mri: 1.2.0
3638
3638
+
pathe: 1.0.0
3639
3639
+
typescript: 4.9.4
3640
3640
+
dev: true
3641
3641
+
3289
3642
/mlly/1.0.0:
3290
3643
resolution: {integrity: sha512-QL108Hwt+u9bXdWgOI0dhzZfACovn5Aen4Xvc8Jasd9ouRH4NjnrXEiyP3nVvJo91zPlYjVRckta0Nt2zfoR6g==}
3291
3644
dependencies:
···
4219
4572
glob: 7.2.3
4220
4573
dev: true
4221
4574
4575
4575
+
/rollup-plugin-dts/5.0.0_oj4jlwi3mkekxo3vucumcwebnq:
4576
4576
+
resolution: {integrity: sha512-OO8ayCvuJCKaQSShyVTARxGurVVk4ulzbuvz+0zFd1f93vlnWFU5pBMT7HFeS6uj7MvvZLx4kUAarGATSU1+Ng==}
4577
4577
+
engines: {node: '>=v14'}
4578
4578
+
peerDependencies:
4579
4579
+
rollup: ^3.0.0
4580
4580
+
typescript: ^4.1
4581
4581
+
dependencies:
4582
4582
+
magic-string: 0.26.7
4583
4583
+
rollup: 3.7.5
4584
4584
+
typescript: 4.9.4
4585
4585
+
optionalDependencies:
4586
4586
+
'@babel/code-frame': 7.18.6
4587
4587
+
dev: true
4588
4588
+
4222
4589
/rollup-plugin-terser/7.0.2_rollup@2.79.1:
4223
4590
resolution: {integrity: sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==}
4224
4591
deprecated: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
···
4257
4624
/rollup/2.79.1:
4258
4625
resolution: {integrity: sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==}
4259
4626
engines: {node: '>=10.0.0'}
4627
4627
+
hasBin: true
4628
4628
+
optionalDependencies:
4629
4629
+
fsevents: 2.3.2
4630
4630
+
dev: true
4631
4631
+
4632
4632
+
/rollup/3.7.5:
4633
4633
+
resolution: {integrity: sha512-z0ZbqHBtS/et2EEUKMrAl2CoSdwN7ZPzL17UMiKN9RjjqHShTlv7F9J6ZJZJNREYjBh3TvBrdfjkFDIXFNeuiQ==}
4634
4634
+
engines: {node: '>=14.18.0', npm: '>=8.0.0'}
4260
4635
hasBin: true
4261
4636
optionalDependencies:
4262
4637
fsevents: 2.3.2
···
4715
5090
resolution: {integrity: sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==}
4716
5091
dev: true
4717
5092
5093
5093
+
/typescript/4.9.4:
5094
5094
+
resolution: {integrity: sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==}
5095
5095
+
engines: {node: '>=4.2.0'}
5096
5096
+
hasBin: true
5097
5097
+
dev: true
5098
5098
+
4718
5099
/ufo/0.8.6:
4719
5100
resolution: {integrity: sha512-fk6CmUgwKCfX79EzcDQQpSCMxrHstvbLswFChHS0Vump+kFkw7nJBfTZoC1j0bOGoY9I7R3n2DGek5ajbcYnOw==}
4720
5101
dev: true
···
4725
5106
4726
5107
/ultrahtml/1.0.4:
4727
5108
resolution: {integrity: sha512-sso5lk1F1/Q1crKx0+9/9/rHCykRJFSifYLaShnhgzfJhbEDZdpntClBs7ojhx0lRmQlUtDIxrC/8hBJj5bVPw==}
5109
5109
+
dev: true
5110
5110
+
5111
5111
+
/unbuild/1.0.2:
5112
5112
+
resolution: {integrity: sha512-nQ2rxQ9aqIPzVhOEs6T/YcDGb6PWf6BAtQ0as+YWoaWCfezAdeL3KlNWSh279D6euOeCt94t0b/vAGr3GKu9Gw==}
5113
5113
+
hasBin: true
5114
5114
+
dependencies:
5115
5115
+
'@rollup/plugin-alias': 4.0.2_rollup@3.7.5
5116
5116
+
'@rollup/plugin-commonjs': 23.0.7_rollup@3.7.5
5117
5117
+
'@rollup/plugin-json': 5.0.2_rollup@3.7.5
5118
5118
+
'@rollup/plugin-node-resolve': 15.0.1_rollup@3.7.5
5119
5119
+
'@rollup/plugin-replace': 5.0.1_rollup@3.7.5
5120
5120
+
'@rollup/pluginutils': 5.0.2_rollup@3.7.5
5121
5121
+
chalk: 5.1.2
5122
5122
+
consola: 2.15.3
5123
5123
+
defu: 6.1.1
5124
5124
+
esbuild: 0.15.18
5125
5125
+
globby: 13.1.2
5126
5126
+
hookable: 5.4.2
5127
5127
+
jiti: 1.16.0
5128
5128
+
magic-string: 0.27.0
5129
5129
+
mkdirp: 1.0.4
5130
5130
+
mkdist: 1.0.0_typescript@4.9.4
5131
5131
+
mlly: 1.0.0
5132
5132
+
mri: 1.2.0
5133
5133
+
pathe: 1.0.0
5134
5134
+
pkg-types: 1.0.1
5135
5135
+
pretty-bytes: 6.0.0
5136
5136
+
rimraf: 3.0.2
5137
5137
+
rollup: 3.7.5
5138
5138
+
rollup-plugin-dts: 5.0.0_oj4jlwi3mkekxo3vucumcwebnq
5139
5139
+
scule: 1.0.0
5140
5140
+
typescript: 4.9.4
5141
5141
+
untyped: 1.0.0
5142
5142
+
transitivePeerDependencies:
5143
5143
+
- sass
5144
5144
+
- supports-color
4728
5145
dev: true
4729
5146
4730
5147
/unctx/2.1.1:
+42
src/config.ts
View file
Reviewed
···
1
1
+
import { loadNuxt, buildNuxt } from '@nuxt/kit'
2
2
+
import { InlineConfig as VitestConfig } from 'vitest'
3
3
+
import { InlineConfig } from 'vite'
4
4
+
5
5
+
// https://github.com/nuxt/framework/issues/6496
6
6
+
async function getViteConfig (rootDir = process.cwd()) {
7
7
+
const nuxt = await loadNuxt({
8
8
+
cwd: rootDir,
9
9
+
dev: false,
10
10
+
overrides: {
11
11
+
ssr: false,
12
12
+
app: {
13
13
+
rootId: 'nuxt-test'
14
14
+
},
15
15
+
},
16
16
+
})
17
17
+
return new Promise<InlineConfig>((resolve, reject) => {
18
18
+
nuxt.hook('vite:extendConfig', config => {
19
19
+
resolve(config)
20
20
+
throw new Error('_stop_')
21
21
+
})
22
22
+
buildNuxt(nuxt).catch(err => {
23
23
+
if (!err.toString().includes('_stop_')) {
24
24
+
reject(err)
25
25
+
}
26
26
+
})
27
27
+
}).finally(() => nuxt.close())
28
28
+
}
29
29
+
30
30
+
export async function getVitestConfig (): Promise<InlineConfig & { test: VitestConfig }> {
31
31
+
const viteConfig = await getViteConfig()
32
32
+
33
33
+
return {
34
34
+
...viteConfig,
35
35
+
test: {
36
36
+
environment: 'nuxt',
37
37
+
deps: {
38
38
+
inline: [/\/(nuxt|nuxt3)\//, /^#/, 'vue'],
39
39
+
},
40
40
+
},
41
41
+
}
42
42
+
}
+73
-38
src/index.ts
View file
Reviewed
···
1
1
-
import { loadNuxt, buildNuxt } from '@nuxt/kit'
2
2
-
import { InlineConfig as VitestConfig } from 'vitest'
3
3
-
import { join } from 'path'
4
4
-
import { fileURLToPath } from 'url'
5
5
-
import { InlineConfig } from 'vite'
1
1
+
import type { Environment } from 'vitest'
2
2
+
import { Window, GlobalWindow } from 'happy-dom'
3
3
+
import { createFetch } from 'ohmyfetch'
4
4
+
import { App, createApp, toNodeListener } from 'h3'
5
5
+
import {
6
6
+
createCall,
7
7
+
createFetch as createLocalFetch,
8
8
+
} from 'unenv/runtime/fetch/index'
6
9
7
7
-
// https://github.com/nuxt/framework/issues/6496
8
8
-
async function getViteConfig (rootDir = process.cwd()) {
9
9
-
const nuxt = await loadNuxt({
10
10
-
cwd: rootDir,
11
11
-
dev: false,
12
12
-
overrides: {
13
13
-
ssr: false,
14
14
-
app: {
15
15
-
rootId: 'nuxt-test'
10
10
+
// @ts-expect-error TODO: https://github.com/vitest-dev/vitest/pull/2530
11
11
+
import * as viteEnvironments from 'vitest/environments'
12
12
+
const { populateGlobal } = viteEnvironments as typeof import('vitest/dist/environments')
13
13
+
14
14
+
export default <Environment> {
15
15
+
name: 'nuxt',
16
16
+
async setup () {
17
17
+
const win = new (GlobalWindow || Window)() as any as (Window & {
18
18
+
__app: App
19
19
+
__registry: Set<string>
20
20
+
__NUXT__: any
21
21
+
$fetch: any
22
22
+
fetch: any
23
23
+
})
24
24
+
25
25
+
win.__NUXT__ = {
26
26
+
serverRendered: false,
27
27
+
config: {
28
28
+
public: {},
29
29
+
app: { baseURL: '/' },
16
30
},
17
17
-
},
18
18
-
})
19
19
-
return new Promise<InlineConfig>((resolve, reject) => {
20
20
-
nuxt.hook('vite:extendConfig', config => {
21
21
-
resolve(config)
22
22
-
throw new Error('_stop_')
23
23
-
})
24
24
-
buildNuxt(nuxt).catch(err => {
25
25
-
if (!err.toString().includes('_stop_')) {
26
26
-
reject(err)
31
31
+
data: {},
32
32
+
state: {},
33
33
+
}
34
34
+
35
35
+
const app = win.document.createElement('div')
36
36
+
// this is a workaround for a happy-dom bug with ids beginning with _
37
37
+
app.id = 'nuxt-test'
38
38
+
win.document.body.appendChild(app)
39
39
+
40
40
+
// @ts-expect-error
41
41
+
win.IntersectionObserver = win.IntersectionObserver || class IntersectionObserver {
42
42
+
observe () {}
43
43
+
}
44
44
+
45
45
+
const h3App = createApp()
46
46
+
47
47
+
// @ts-expect-error TODO: fix in h3
48
48
+
const localCall = createCall(toNodeListener(h3App))
49
49
+
const localFetch = createLocalFetch(localCall, globalThis.fetch)
50
50
+
51
51
+
const registry = new Set<string>()
52
52
+
53
53
+
win.fetch = (init, options) => {
54
54
+
if (typeof init === 'string' && registry.has(init)) {
55
55
+
init = '/_' + init
27
56
}
28
28
-
})
29
29
-
}).finally(() => nuxt.close())
30
30
-
}
57
57
+
return localFetch(init, options)
58
58
+
}
59
59
+
60
60
+
// @ts-expect-error
61
61
+
win.$fetch = createFetch({ fetch: win.fetch, Headers: win.Headers })
62
62
+
63
63
+
win.__registry = registry
64
64
+
win.__app = h3App
31
65
32
32
-
export async function getVitestConfig (): Promise<InlineConfig & { test: VitestConfig }> {
33
33
-
const viteConfig = await getViteConfig()
34
34
-
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
66
66
+
const { keys, originals } = populateGlobal(global, win, { bindFunctions: true })
35
67
36
36
-
return {
37
37
-
...viteConfig,
38
38
-
test: {
39
39
-
environment: 'nuxt',
40
40
-
deps: {
41
41
-
inline: [/\/(nuxt|nuxt3)\//, /^#/, 'vue'],
42
42
-
},
43
43
-
},
68
68
+
// @ts-expect-error nuxt alias
69
69
+
await import('#app/entry')
70
70
+
71
71
+
return {
72
72
+
// called after all tests with this env have been run
73
73
+
teardown () {
74
74
+
win.happyDOM.cancelAsync()
75
75
+
keys.forEach(key => delete global[key])
76
76
+
originals.forEach((v, k) => global[k] = v)
77
77
+
}
78
78
+
}
44
79
}
45
80
}
+2
src/utils.ts
View file
Reviewed
···
1
1
+
export { registerEndpoint } from './runtime/mock'
2
2
+
export { mountSuspended } from './runtime/mount'
-75
src/vitest-environment-nuxt/index.ts
Reviewed
···
1
1
-
import type { Environment } from 'vitest'
2
2
-
import { Window, GlobalWindow } from 'happy-dom'
3
3
-
import { createFetch } from 'ohmyfetch'
4
4
-
import { App, createApp, toNodeListener } from 'h3'
5
5
-
import {
6
6
-
createCall,
7
7
-
createFetch as createLocalFetch,
8
8
-
} from 'unenv/runtime/fetch/index'
9
9
-
// @ts-expect-error TODO: add subpath types
10
10
-
import * as viteEnvironments from 'vitest/environments'
11
11
-
const { populateGlobal } = viteEnvironments as typeof import('vitest/dist/environments')
12
12
-
13
13
-
export default <Environment> {
14
14
-
name: 'nuxt',
15
15
-
async setup () {
16
16
-
const win = new (GlobalWindow || Window)() as any as (Window & {
17
17
-
__app: App
18
18
-
__registry: Set<string>
19
19
-
__NUXT__: any
20
20
-
$fetch: any
21
21
-
fetch: any
22
22
-
})
23
23
-
24
24
-
win.__NUXT__ = {
25
25
-
serverRendered: false,
26
26
-
config: {
27
27
-
public: {},
28
28
-
app: { baseURL: '/' },
29
29
-
},
30
30
-
data: {},
31
31
-
state: {},
32
32
-
}
33
33
-
34
34
-
const app = win.document.createElement('div')
35
35
-
app.id = 'nuxt-test'
36
36
-
win.document.body.appendChild(app)
37
37
-
38
38
-
// @ts-expect-error
39
39
-
win.IntersectionObserver = win.IntersectionObserver || class IntersectionObserver {
40
40
-
observe () {}
41
41
-
}
42
42
-
43
43
-
const h3App = createApp()
44
44
-
45
45
-
const localCall = createCall(toNodeListener(h3App))
46
46
-
const localFetch = createLocalFetch(localCall, globalThis.fetch)
47
47
-
48
48
-
const registry = new Set<string>()
49
49
-
50
50
-
win.fetch = (init, options) => {
51
51
-
if (typeof init === 'string' && registry.has(init)) {
52
52
-
init = '/_' + init
53
53
-
}
54
54
-
return localFetch(init, options)
55
55
-
}
56
56
-
win.$fetch = createFetch({ fetch: win.fetch, Headers: win.Headers })
57
57
-
58
58
-
win.__registry = registry
59
59
-
win.__app = h3App
60
60
-
61
61
-
const { keys, originals } = populateGlobal(global, win, { bindFunctions: true })
62
62
-
63
63
-
// @ts-expect-error nuxt alias
64
64
-
await import('#app/entry')
65
65
-
66
66
-
return {
67
67
-
// called after all tests with this env have been run
68
68
-
teardown () {
69
69
-
win.happyDOM.cancelAsync()
70
70
-
keys.forEach(key => delete global[key])
71
71
-
originals.forEach((v, k) => global[k] = v)
72
72
-
}
73
73
-
}
74
74
-
}
75
75
-
}
-4
src/vitest-environment-nuxt/package.json
Reviewed
···
1
1
-
{
2
2
-
"name": "vitest-environment-nuxt",
3
3
-
"main": "index.ts"
4
4
-
}
+1
utils.d.ts
View file
Reviewed
···
1
1
+
export * from './dist/utils'