Skip to content

Commit

Permalink
Merge pull request #371 from caoyang818/release-3.6.8-app
Browse files Browse the repository at this point in the history
fix: 还原代码rootPath以及优化单元测试代码
  • Loading branch information
qican777 authored Nov 1, 2023
2 parents 24b7257 + 5605540 commit 7b9ed9a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 13 deletions.
5 changes: 0 additions & 5 deletions packages/taro-cli-convertor/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ import * as taroize from '@tarojs/taroize'
import Convertor from '../src/index'
import { generateMinimalEscapeCode } from './util'

jest.mock('../src/util/index.ts', () => ({
...jest.requireActual('../src/util/index.ts'), // 保留原始的其他函数
printToLogFile: jest.fn(),
}))

jest.mock('fs', () => ({
...jest.requireActual('fs'), // 保留原始的其他函数
appendFile: jest.fn(),
Expand Down
5 changes: 0 additions & 5 deletions packages/taro-cli-convertor/__tests__/script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import { generateMinimalEscapeCode } from './util'
const fs = require('fs')
const path = require('path')

jest.mock('../src/util/index.ts', () => ({
...jest.requireActual('../src/util/index.ts'), // 保留原始的其他函数
printToLogFile: jest.fn(),
}))

jest.mock('fs', () => ({
...jest.requireActual('fs'), // 保留原始的其他函数
appendFile: jest.fn(),
Expand Down
5 changes: 5 additions & 0 deletions packages/taroize/__tests__/event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ interface Option {
path: string
}

jest.mock('fs', () => ({
...jest.requireActual('fs'), // 保留原始的其他函数
appendFile: jest.fn(),
}))

describe('event convertor', () => {
const option: Option = {
path: '',
Expand Down
4 changes: 4 additions & 0 deletions packages/taroize/__tests__/script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { parseScript } from '../src/script'
import { parseWXML, WXS } from '../src/wxml'
import { generateMinimalEscapeCode } from './util'

jest.mock('fs', () => ({
...jest.requireActual('fs'), // 保留原始的其他函数
appendFile: jest.fn(),
}))

interface Option {
script: string
Expand Down
6 changes: 5 additions & 1 deletion packages/taroize/__tests__/template.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { parseWXML } from '../src/wxml'
import { generateMinimalEscapeCode } from './util'

jest.mock('fs')
const fs = require('fs')
const path = require('path')

jest.mock('fs', () => ({
...jest.requireActual('fs'), // 保留原始的其他函数
appendFile: jest.fn(),
}))

describe('template.ts', () => {
describe('import 正常情况', () => {
// 还原模拟函数
Expand Down
5 changes: 5 additions & 0 deletions packages/taroize/__tests__/wxml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import * as t from '@babel/types'
import { convertStyleUnit, parseContent, parseStyle, parseWXML } from '../src/wxml'
import { generateMinimalEscapeCode } from './util'

jest.mock('fs', () => ({
...jest.requireActual('fs'), // 保留原始的其他函数
appendFile: jest.fn(),
}))

interface Option {
path: string
rootPath: string
Expand Down
4 changes: 3 additions & 1 deletion packages/taroize/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ export const usedComponents = new Set<string>()
export const errors: string[] = []

export const globals = {
rootPath: '',
hasCatchTrue: false,
logFilePath: '',
}

export const THIRD_PARTY_COMPONENTS = new Set<string>()

export const resetGlobals = (logFilePath) => {
export const resetGlobals = (rootPath, logFilePath) => {
globals.rootPath = rootPath
globals.hasCatchTrue = false
globals.logFilePath = logFilePath
THIRD_PARTY_COMPONENTS.clear()
Expand Down
2 changes: 1 addition & 1 deletion packages/taroize/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface Option {
}

export function parse (option: Option) {
resetGlobals(option.logFilePath)
resetGlobals(option.rootPath, option.logFilePath)
setting.rootPath = option.rootPath
if (option.json) {
const config = JSON.parse(option.json)
Expand Down

0 comments on commit 7b9ed9a

Please sign in to comment.