test: update unit test

This commit is contained in:
pengzhanbo 2024-10-15 01:35:01 +08:00
parent b8f43267ad
commit e01ba19fce
6 changed files with 12 additions and 12 deletions

View File

@ -1,3 +0,0 @@
const { fs } = require('memfs')
module.exports = fs

View File

@ -1,3 +0,0 @@
const { fs } = require('memfs')
module.exports = fs.promises

View File

@ -8,9 +8,7 @@ import { createPackageJson } from './packageJson.js'
import { createRender } from './render.js' import { createRender } from './render.js'
import { getTemplate, readFiles, readJsonFile, writeFiles } from './utils/index.js' import { getTemplate, readFiles, readJsonFile, writeFiles } from './utils/index.js'
export async function generate(mode: Mode, data: ResolvedData): Promise<void> { export async function generate(mode: Mode, data: ResolvedData, cwd = process.cwd()): Promise<void> {
const cwd = process.cwd()
let userPkg: Record<string, any> = {} let userPkg: Record<string, any> = {}
if (mode === Mode.init) { if (mode === Mode.init) {
const pkgPath = path.join(cwd, 'package.json') const pkgPath = path.join(cwd, 'package.json')

View File

@ -5,13 +5,14 @@ import { path } from '@vuepress/utils'
import { resolveModule } from 'local-pkg' import { resolveModule } from 'local-pkg'
import MarkdownIt from 'markdown-it' import MarkdownIt from 'markdown-it'
import { fs, vol } from 'memfs' import { fs, vol } from 'memfs'
import { beforeEach, describe, expect, it, vi } from 'vitest' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { langReplPlugin } from '../src/node/container/langRepl.js' import { langReplPlugin } from '../src/node/container/langRepl.js'
vi.mock('node:fs') vi.mock('node:fs', () => fs)
vi.mock('node:fs/promises') vi.mock('node:fs/promises', () => fs.promises)
beforeEach(() => vol.reset()) beforeEach(() => vol.reset())
afterEach(() => vol.reset())
const FENCE = '```' const FENCE = '```'

View File

@ -56,6 +56,7 @@ export function createEmbedRuleBlock<Meta extends Record<string, any> = Record<s
return false return false
// return true as we have matched the syntax // return true as we have matched the syntax
/* istanbul ignore if -- @preserve */
if (silent) if (silent)
return true return true

View File

@ -2,6 +2,12 @@ import { defineConfig } from 'vitest/config'
export default defineConfig({ export default defineConfig({
test: { test: {
include: ['**/__test__/**/*.spec.[tj]s'],
exclude: [
'**/node_modules/**',
'**/dist/**',
'**/lib/**',
],
coverage: { coverage: {
enabled: true, enabled: true,
provider: 'istanbul', provider: 'istanbul',