Skip to content

Commit df84d8f

Browse files
committed
Fix tests
1 parent 4c07e6d commit df84d8f

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

tests/test.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const prettier = require('prettier')
22
const path = require('path')
3+
const fs = require('fs')
34
const { execSync } = require('child_process')
45
const { t, yes, no } = require('./utils')
56

@@ -23,17 +24,40 @@ function format(str, options = {}) {
2324
.trim()
2425
}
2526

27+
function allowFixtureFormatting(callback) {
28+
let renames = [
29+
{
30+
from: __dirname + '/../.prettierignore',
31+
to: __dirname + '/../.prettierignore.testing',
32+
},
33+
{
34+
from: __dirname + '/../prettier.config.js',
35+
to: __dirname + '/../prettier.config.js.testing',
36+
},
37+
]
38+
39+
for (const { from, to } of renames) {
40+
fs.renameSync(from, to)
41+
}
42+
43+
try {
44+
return callback()
45+
} finally {
46+
for (const { from, to } of renames) {
47+
fs.renameSync(to, from)
48+
}
49+
}
50+
}
51+
2652
function formatFixture(name) {
2753
let binPath = path.resolve(__dirname, '../node_modules/.bin/prettier')
2854
let filePath = path.resolve(__dirname, `fixtures/${name}/index.html`)
29-
return execSync(
30-
`${binPath} ${filePath} --plugin-search-dir ${__dirname} --plugin ${path.resolve(
31-
__dirname,
32-
'..',
33-
)}`,
34-
)
35-
.toString()
36-
.trim()
55+
let cmd = `${binPath} ${filePath} --plugin-search-dir ${__dirname} --plugin ${path.resolve(
56+
__dirname,
57+
'..',
58+
)}`
59+
60+
return allowFixtureFormatting(() => execSync(cmd).toString().trim())
3761
}
3862

3963
let html = [

0 commit comments

Comments
 (0)