Skip to content

Commit 20b1ed1

Browse files
committed
vi.mock(import())
1 parent f2e0312 commit 20b1ed1

3 files changed

Lines changed: 33 additions & 51 deletions

File tree

.oxlintrc.json

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,7 @@
2121
"oxc/no-async-await": "off",
2222
"oxc/no-rest-spread-properties": "off", // Enable if older browser support is needed
2323
"eslint/max-statements": ["warn", 20],
24-
"eslint/id-length": [
25-
"error",
26-
{
27-
"exceptions": [
28-
"x",
29-
"y",
30-
"z",
31-
"i",
32-
"j",
33-
"k",
34-
"r",
35-
"g",
36-
"b",
37-
"id",
38-
"ID",
39-
"fs",
40-
"os"
41-
],
42-
"min": 3
43-
}
44-
],
24+
"eslint/id-length": ["error", { "exceptions": ["x", "y", "z", "i", "j", "k", "r", "g", "b", "id", "ID", "fs", "os"], "min": 3 }],
4525
"eslint/no-console": "warn", // Disable for debugging. Disable later to not have browser logs
4626
"sort-imports": ["error", { "allowSeparatedGroups": true }],
4727
"eslint/no-undefined": "off", // Conflict with unicorn/no-typeof-undefined which prefers direct undefined comparison
@@ -52,6 +32,7 @@
5232
"oxc/no-optional-chaining": "off",
5333
"node/no-process-env": "off",
5434
"no-continue": "off",
35+
"import/no-nodejs-modules": "off",
5536
"import/unambiguous": "off",
5637
"max-params": ["warn", { "max": 4 }],
5738
"eslint/no-magic-numbers": [
@@ -60,7 +41,7 @@
6041
"ignore": [-1, 0, 1, 2, 3, 4],
6142
"ignoreArrayIndexes": true
6243
}
63-
]
44+
],
6445
},
6546
"overrides": [
6647
{
@@ -71,16 +52,15 @@
7152
{
7253
"case": "pascalCase"
7354
}
74-
]
55+
],
7556
}
7657
},
7758
{
7859
"files": [
7960
"app/plugins/**",
8061
"node_scripts/**",
8162
"server/**",
82-
"*.config.js"
83-
],
63+
"*.config.js", ],
8464
"rules": {
8565
"import/no-default-export": "off"
8666
}
@@ -89,7 +69,9 @@
8969
"files": ["tests/**"],
9070
"rules": {
9171
"vitest/require-hook": "off",
92-
"vitest/no-hooks": "off"
72+
"vitest/no-hooks": "off",
73+
"vitest/no-importing-vitest-globals": "off",
74+
"import/no-relative-parent-imports": "warn",
9375
}
9476
},
9577
{

tests/unit/composables/project_manager.nuxt.test.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ const hybridViewerStoreMock = {
135135

136136
// MOCKS
137137
vi.stubGlobal("$fetch", vi.fn().mockResolvedValue({ snapshot: snapshotMock }))
138-
vi.mock("../../../internal/utils/viewer_call", () => ({
138+
vi.mock(import("../../../internal/utils/viewer_call", () => ({
139139
viewer_call: viewer_call_mock_fn,
140-
}))
140+
})))
141141

142-
vi.mock("@ogw_front/composables/api_fetch", () => ({
142+
vi.mock(import("@ogw_front/composables/api_fetch", () => ({
143143
api_fetch: vi.fn(async (_req, options = {}) => {
144144
const response = {
145145
_data: new Blob(["zipcontent"], { type: "application/zip" }),
@@ -152,34 +152,34 @@ vi.mock("@ogw_front/composables/api_fetch", () => ({
152152
}
153153
return response
154154
}),
155-
}))
156-
vi.mock("js-file-download", () => ({ default: vi.fn() }))
157-
vi.mock("@ogw_front/stores/infra", () => ({
155+
})))
156+
vi.mock(import("js-file-download", () => ({ default: vi.fn() })))
157+
vi.mock(import("@ogw_front/stores/infra", () => ({
158158
useInfraStore: () => infraStoreMock,
159-
}))
160-
vi.mock("@ogw_front/stores/viewer", () => ({
159+
})))
160+
vi.mock(import("@ogw_front/stores/viewer", () => ({
161161
useViewerStore: () => viewerStoreMock,
162-
}))
163-
vi.mock("@ogw_front/stores/treeview", () => ({
162+
})))
163+
vi.mock(import("@ogw_front/stores/treeview", () => ({
164164
useTreeviewStore: () => treeviewStoreMock,
165-
}))
166-
vi.mock("@ogw_front/stores/data", () => ({
165+
})))
166+
vi.mock(import("@ogw_front/stores/data", () => ({
167167
useDataStore: () => dataStoreMock,
168-
}))
169-
vi.mock("@ogw_front/stores/data_style", () => ({
168+
})))
169+
vi.mock(import("@ogw_front/stores/data_style", () => ({
170170
useDataStyleStore: () => dataStyleStoreMock,
171-
}))
172-
vi.mock("@ogw_front/stores/hybrid_viewer", () => ({
171+
})))
172+
vi.mock(import("@ogw_front/stores/hybrid_viewer", () => ({
173173
useHybridViewerStore: () => hybridViewerStoreMock,
174-
}))
175-
vi.mock("@ogw_front/stores/geode", () => ({
174+
})))
175+
vi.mock(import("@ogw_front/stores/geode", () => ({
176176
useGeodeStore: () => geodeStoreMock,
177-
}))
178-
vi.mock("@ogw_front/stores/app", () => ({
177+
})))
178+
vi.mock(import("@ogw_front/stores/app", () => ({
179179
useAppStore: () => ({
180180
exportStores: vi.fn(() => ({ projectName: "mockedProject" })),
181181
}),
182-
}))
182+
})))
183183

184184
vi.stubGlobal("useAppStore", () => ({
185185
exportStores: vi.fn(() => ({ projectName: "mockedProject" })),

tests/unit/plugins/project_load.nuxt.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ const PANEL_WIDTH = 320
1313
const Z_SCALE = 1.5
1414
const STORES_SLICE_START = 1
1515

16-
vi.mock("../../../internal/utils/viewer_call", () => ({
16+
vi.mock(import("../../../internal/utils/viewer_call", () => ({
1717
viewer_call: vi.fn(async () => {
1818
await Promise.resolve()
1919
}),
20-
}))
21-
vi.mock("../../../app/stores/hybrid_viewer", () => ({
20+
})))
21+
vi.mock(import("../../../app/stores/hybrid_viewer", () => ({
2222
useHybridViewerStore: () => ({
2323
$id: "hybridViewer",
2424
initHybridViewer: vi.fn(),
@@ -28,7 +28,7 @@ vi.mock("../../../app/stores/hybrid_viewer", () => ({
2828
save: vi.fn(),
2929
load: vi.fn(),
3030
}),
31-
}))
31+
})))
3232

3333
beforeEach(() => {
3434
setupActivePinia()

0 commit comments

Comments
 (0)