mirror of
https://github.com/actions/configure-pages.git
synced 2026-03-31 02:24:52 +00:00
Add tests for config-parser
This commit is contained in:
37
src/test-helpers.js
Normal file
37
src/test-helpers.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const fs = require('fs')
|
||||
const prettier = require('prettier')
|
||||
const assert = require('assert')
|
||||
|
||||
// Create and return the path to a temp folder
|
||||
function getTempFolder() {
|
||||
const tmpFolder = `${__dirname}/fixtures/tmp`
|
||||
if (!fs.existsSync(tmpFolder)) {
|
||||
fs.mkdirSync(tmpFolder, {recursive: true})
|
||||
}
|
||||
return tmpFolder
|
||||
}
|
||||
|
||||
// Read a JavaScript file and return it formatted
|
||||
function formatFile(file) {
|
||||
const fileContent = fs.readFileSync(file, 'utf8')
|
||||
return prettier.format(fileContent, {
|
||||
parser: 'espree',
|
||||
|
||||
// Prettier options
|
||||
printWidth: 80,
|
||||
tabWidth: 2,
|
||||
useTabs: false,
|
||||
semi: false,
|
||||
singleQuote: true,
|
||||
trailingComma: 'none',
|
||||
bracketSpacing: false,
|
||||
arrowParens: 'avoid'
|
||||
}).trim()
|
||||
}
|
||||
|
||||
// Compare two JavaScript files
|
||||
function compareFiles(actualFile, expectedFile) {
|
||||
assert.equal(formatFile(actualFile), formatFile(expectedFile))
|
||||
}
|
||||
|
||||
module.exports = {getTempFolder, formatFile, compareFiles}
|
||||
Reference in New Issue
Block a user