Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

执行jest用例后,报了 ReferenceError: You are trying to import a file after the Jest environment has been torn down. From test/modules/config-center/index.spec.js #88

Open
sauron0914 opened this issue May 11, 2022 · 0 comments

Comments

@sauron0914
Copy link

const { request } = require('../../@helpers/agent')
const { strict: t } = require('assert')
const { closeNacosClient, connectNacos } = require('../../../src/utils/nacos')

beforeAll(async () => {
  await connectNacos()
})

afterAll(async () => {
  await closeNacosClient()
})

test('/test-jest', async () => {
  const response = await request.get('/1.0/test-jest')
  t.equal(response.status, 200)
  t.equal(response.body.code, 0)
})
const connectNacos = () => {
  nacosClient = new NacosConfigClient({
    ...config.nacos,
  })
}

const closeNacosClient = async () => {
  await nacosClient.unSubscribe({
    dataId: 'xxx1.yaml',
    group: 'DEFAULT_GROUP',
  })
  await nacosClient.unSubscribe({
    dataId: 'xxx2.yaml',
    group: 'DEFAULT_GROUP',
  })
  await nacosClient.close()
}

当有两个 test 的时候,就会出现这种情况,看了下,好像是 nacosClient.close() 关闭无效

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant