Vitest无法加载包([vite-node]无法加载meteor/meteor)

cnjp1d6j  于 2023-06-29  发布在  Node.js
关注(0)|答案(1)|浏览(183)

我用TypeScript建立了一个新的meteor项目,并安装了vitest。
当我运行vitest时,我得到以下错误:

FAIL  tests/main.test.ts [ tests/main.test.ts ]
Error: [vite-node] Failed to load meteor/meteor

测试很简单:

import { Meteor } from 'meteor/meteor'
import { describe, test, expect } from 'vitest'

// ---

describe('replay', function () {
    test('package.json has correct name', async function () {
        const { name } = await import('../package.json')
        expect(name).toBe('replay')
    })

    if (Meteor.isClient) {
        test('client is not server', function () {
            expect(Meteor.isServer).toBe(false)
        })
    }

    if (Meteor.isServer) {
        test('server is not client', function () {
            expect(Meteor.isClient).toBe(false)
        })
    }
})

该存储库可在此处公开获取:https://github.com/repetitioestmaterstudiorum/replay
我不明白为什么维特斯不能进口流星。由于node_modules/@types/meteor,它的声明是全局的。

np8igboo

np8igboo1#

您遇到的问题可能是因为您单独调用vitest。
要测试meteor应用程序,您应该使用meteor test --driver-package meteortesting:mocha作为传递,驱动程序将用于测试应用程序。
Vitest也是一个Assert库,所以它可能能够在您的应用程序中运行,但我无法使其在我的机器上工作以获取更多细节,还可以检查测试中的meteor文档,如果您可能需要其他东西,您可以在Meteor GitHub repo的issue部分与我们联系

相关问题