Skip to content

Commit

Permalink
fix: 测试用例修复
Browse files Browse the repository at this point in the history
  • Loading branch information
bigmeow committed Jun 29, 2023
1 parent d09c885 commit e1766fa
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/taro-cli/src/__tests__/build-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ describe('构建配置测试', () => {

describe('小程序', () => {
it(`项目 output.clean = clean: { keep: ['project.config.json'] } ==> 清空dist文件夹但保留指定文件`, async () => {
const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any>
const logSpy = jest.spyOn(console, 'log')
const errorSpy = jest.spyOn(console, 'error')
logSpy.mockImplementation(() => {})
errorSpy.mockImplementation(() => {})
exitSpy.mockImplementation(() => {
throw new Error()
})

try {
await runBuild(APP_PATH, {
options: {
Expand All @@ -51,6 +60,10 @@ describe('构建配置测试', () => {
// no handler
}
expect(emptyDirectoryMocked).toBeCalledWith(OUTPUT_PATH, { excludes: ['project.config.json'] })

exitSpy.mockRestore()
logSpy.mockRestore()
errorSpy.mockRestore()
})
})

Expand All @@ -61,10 +74,10 @@ describe('构建配置测试', () => {
const errorSpy = jest.spyOn(console, 'error')
logSpy.mockImplementation(() => {})
errorSpy.mockImplementation(() => {})

exitSpy.mockImplementation(() => {
throw new Error()
})

try {
await runBuild(APP_PATH, {
options: {
Expand All @@ -76,6 +89,10 @@ describe('构建配置测试', () => {
// no handler
}
expect(emptyDirectoryMocked).toBeCalledTimes(0)

exitSpy.mockRestore()
logSpy.mockRestore()
errorSpy.mockRestore()
})
})
})

0 comments on commit e1766fa

Please sign in to comment.