-
Notifications
You must be signed in to change notification settings - Fork 2
/
jest.setup.mts
66 lines (59 loc) · 1.79 KB
/
jest.setup.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import type { IParser } from '@yozora/core-parser'
import type { IMarkupWeaver } from '@yozora/markup-weaver'
import { DefaultMarkupWeaver } from '@yozora/markup-weaver'
import YozoraParser from '@yozora/parser'
import GfmParser from '@yozora/parser-gfm'
import GfmExParser from '@yozora/parser-gfm-ex'
import fs from 'node:fs'
import path from 'node:path'
import url from 'node:url'
export const parsers = {
get gfm(): IParser {
return new GfmParser({
defaultParseOptions: { shouldReservePosition: true },
})
},
get gfmEx(): IParser {
return new GfmExParser({
defaultParseOptions: { shouldReservePosition: true },
})
},
get yozora(): IParser {
return new YozoraParser({
defaultParseOptions: { shouldReservePosition: true },
})
},
}
export const generateParseData = (filepath: string): void => {
const content = fs.readFileSync(filepath, 'utf8')
const result = parsers.yozora.parse(content)
const data = JSON.stringify(result, null, 2)
fs.writeFileSync(filepath + '.json', data, 'utf8')
}
export const weavers = {
get yozora(): IMarkupWeaver {
return new DefaultMarkupWeaver()
},
}
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
export const workspaceRootDir = __dirname
export const testRootDior = path.resolve()
/**
* Locate fixture filepath.
* @param p
* @returns
*/
export const locateFixture = (...p: string[]): string =>
path.join(testRootDior, '__test__/fixtures', ...p)
/**
* Load fixture filepath.
* @param p
* @returns
*/
export const loadFixtures = (...p: string[]): string =>
fs.readFileSync(locateFixture(...p), 'utf-8')
export const loadJSONFixture = (...p: string[]): any => {
const filepath = locateFixture(...p)
const content = fs.readFileSync(filepath, { encoding: 'utf8' })
return JSON.parse(content)
}