MCPcopy
hub / github.com/vitest-dev/vitest / resetModules

Function resetModules

packages/vitest/src/runtime/utils.ts:52–73  ·  view source on GitHub ↗
(modules: EvaluatedModules, resetMocks = false)

Source from the content-addressed store, hash-verified

50}
51
52export function resetModules(modules: EvaluatedModules, resetMocks = false): void {
53 const skipPaths = [
54 // Vitest
55 /\/vitest\/dist\//,
56 // yarn's .store folder
57 /vitest-virtual-\w+\/dist/,
58 // cnpm
59 /@vitest\/dist/,
60 // don't clear mocks
61 ...(!resetMocks ? [/^mock:/] : []),
62 ]
63 modules.idToModuleMap.forEach((node, path) => {
64 if (skipPaths.some(re => re.test(path))) {
65 return
66 }
67
68 node.promise = undefined
69 node.exports = undefined
70 node.evaluated = false
71 node.importers.clear()
72 })
73}
74
75function waitNextTick() {
76 const { setTimeout } = getSafeTimers()

Callers 3

resetModulesFunction · 0.90
runFunction · 0.90
utils.spec.tsFile · 0.90

Calls 2

clearMethod · 0.65
testMethod · 0.45

Tested by

no test coverage detected