-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.test.js
32 lines (26 loc) · 1.04 KB
/
plugin.test.js
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
const fs = require('fs')
const path = require('path')
const prettier = require('prettier')
const { expect, test } = require('@jest/globals')
const fixturesDir = path.resolve(__dirname, './fixtures')
const files = fs.readdirSync(fixturesDir)
for (const sourceFileName of files) {
if (/\.prettified\./.test(sourceFileName)) {
continue
}
test(`Formats ${sourceFileName}`, async () => {
const formattedFileName = sourceFileName.replace(/(\.[a-z]+)$/, '.prettified$1')
const sourceFilePath = path.resolve(fixturesDir, sourceFileName)
const formattedFilePath = path.resolve(fixturesDir, formattedFileName)
const sourceText = fs.readFileSync(sourceFilePath, 'utf8')
const expectedFormattedText = fs.readFileSync(formattedFilePath, 'utf8')
const actualResult = prettier.format(sourceText, {
filepath: sourceFilePath,
semi: false,
singleQuote: true,
vueExcludeBlocks: ['style', 'template'],
plugins: [path.resolve(__dirname, '.')],
})
expect(actualResult).toBe(expectedFormattedText)
})
}