mirror of
https://github.com/actions/configure-pages.git
synced 2025-12-08 16:16:09 +00:00
Update all source files to match expected Prettier formatting
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
# Prettier (formatter) configuration
|
# Prettier (formatter) configuration
|
||||||
---
|
---
|
||||||
printWidth: 80
|
printWidth: 120
|
||||||
tabWidth: 2
|
tabWidth: 2
|
||||||
useTabs: false
|
useTabs: false
|
||||||
semi: false
|
semi: false
|
||||||
singleQuote: true
|
singleQuote: true
|
||||||
trailingComma: none
|
trailingComma: none
|
||||||
bracketSpacing: false
|
bracketSpacing: true
|
||||||
arrowParens: avoid
|
arrowParens: avoid
|
||||||
|
|||||||
40
dist/index.js
vendored
40
dist/index.js
vendored
@@ -14559,7 +14559,7 @@ class ConfigParser {
|
|||||||
// Ctor
|
// Ctor
|
||||||
// - configurationFile: path to the configuration file
|
// - configurationFile: path to the configuration file
|
||||||
// - blankConfigurationFile: a blank configuration file to use if non was previously found
|
// - blankConfigurationFile: a blank configuration file to use if non was previously found
|
||||||
constructor({configurationFile, blankConfigurationFile, properties}) {
|
constructor({ configurationFile, blankConfigurationFile, properties }) {
|
||||||
// Save field
|
// Save field
|
||||||
this.configurationFile = configurationFile
|
this.configurationFile = configurationFile
|
||||||
this.properties = properties
|
this.properties = properties
|
||||||
@@ -14585,9 +14585,7 @@ class ConfigParser {
|
|||||||
findConfigurationObject(ast) {
|
findConfigurationObject(ast) {
|
||||||
// Try to find a default export
|
// Try to find a default export
|
||||||
var defaultExport = ast.body.find(
|
var defaultExport = ast.body.find(
|
||||||
node =>
|
node => node.type === 'ExportDefaultDeclaration' && node.declaration.type === 'ObjectExpression'
|
||||||
node.type === 'ExportDefaultDeclaration' &&
|
|
||||||
node.declaration.type === 'ObjectExpression'
|
|
||||||
)
|
)
|
||||||
if (defaultExport) {
|
if (defaultExport) {
|
||||||
core.info('Found configuration object in default export declaration')
|
core.info('Found configuration object in default export declaration')
|
||||||
@@ -14608,19 +14606,13 @@ class ConfigParser {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Direct module export
|
// Direct module export
|
||||||
if (
|
if (moduleExport && moduleExport.expression.right.type === 'ObjectExpression') {
|
||||||
moduleExport &&
|
|
||||||
moduleExport.expression.right.type === 'ObjectExpression'
|
|
||||||
) {
|
|
||||||
core.info('Found configuration object in direct module export')
|
core.info('Found configuration object in direct module export')
|
||||||
return moduleExport.expression.right
|
return moduleExport.expression.right
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indirect module export
|
// Indirect module export
|
||||||
else if (
|
else if (moduleExport && moduleExport.expression.right.type === 'Identifier') {
|
||||||
moduleExport &&
|
|
||||||
moduleExport.expression.right.type === 'Identifier'
|
|
||||||
) {
|
|
||||||
const identifierName = moduleExport && moduleExport.expression.right.name
|
const identifierName = moduleExport && moduleExport.expression.right.name
|
||||||
const identifierDefinition = ast.body.find(
|
const identifierDefinition = ast.body.find(
|
||||||
node =>
|
node =>
|
||||||
@@ -14648,9 +14640,7 @@ class ConfigParser {
|
|||||||
// Try to find a property matching a given name
|
// Try to find a property matching a given name
|
||||||
const property =
|
const property =
|
||||||
object.type === 'ObjectExpression' &&
|
object.type === 'ObjectExpression' &&
|
||||||
object.properties.find(
|
object.properties.find(node => node.key.type === 'Identifier' && node.key.name === name)
|
||||||
node => node.key.type === 'Identifier' && node.key.name === name
|
|
||||||
)
|
|
||||||
|
|
||||||
// Return the property's value (if found) or null
|
// Return the property's value (if found) or null
|
||||||
if (property) {
|
if (property) {
|
||||||
@@ -14670,9 +14660,7 @@ class ConfigParser {
|
|||||||
return `${properties[startIndex]}: ${JSON.stringify(propertyValue)}`
|
return `${properties[startIndex]}: ${JSON.stringify(propertyValue)}`
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
`${properties[startIndex]}: {` +
|
`${properties[startIndex]}: {` + this.getPropertyDeclaration(properties, startIndex + 1, propertyValue) + '}'
|
||||||
this.getPropertyDeclaration(properties, startIndex + 1, propertyValue) +
|
|
||||||
'}'
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14750,11 +14738,7 @@ class ConfigParser {
|
|||||||
// Create nested properties in the configuration file
|
// Create nested properties in the configuration file
|
||||||
else {
|
else {
|
||||||
// Build the declaration to inject
|
// Build the declaration to inject
|
||||||
const declaration = this.getPropertyDeclaration(
|
const declaration = this.getPropertyDeclaration(properties, depth, propertyValue)
|
||||||
properties,
|
|
||||||
depth,
|
|
||||||
propertyValue
|
|
||||||
)
|
|
||||||
|
|
||||||
// The last node identified is an object expression, so do the assignment
|
// The last node identified is an object expression, so do the assignment
|
||||||
if (lastNode.type === 'ObjectExpression') {
|
if (lastNode.type === 'ObjectExpression') {
|
||||||
@@ -14801,7 +14785,7 @@ class ConfigParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {ConfigParser}
|
module.exports = { ConfigParser }
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@@ -14833,7 +14817,7 @@ function getContext() {
|
|||||||
return requiredVars
|
return requiredVars
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {getContext}
|
module.exports = { getContext }
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@@ -14859,7 +14843,7 @@ module.exports = outputPagesBaseUrl
|
|||||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||||
|
|
||||||
const core = __nccwpck_require__(2186)
|
const core = __nccwpck_require__(2186)
|
||||||
const {ConfigParser} = __nccwpck_require__(8395)
|
const { ConfigParser } = __nccwpck_require__(8395)
|
||||||
|
|
||||||
// Return the settings to be passed to a {ConfigParser} for a given
|
// Return the settings to be passed to a {ConfigParser} for a given
|
||||||
// static site generator and a Pages path value to inject
|
// static site generator and a Pages path value to inject
|
||||||
@@ -14911,7 +14895,7 @@ function getConfigParserSettings(staticSiteGenerator, path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inject Pages configuration in a given static site generator's configuration file
|
// Inject Pages configuration in a given static site generator's configuration file
|
||||||
function setPagesPath({staticSiteGenerator, path}) {
|
function setPagesPath({ staticSiteGenerator, path }) {
|
||||||
try {
|
try {
|
||||||
// Parse the configuration file and try to inject the Pages configuration in it
|
// Parse the configuration file and try to inject the Pages configuration in it
|
||||||
const settings = getConfigParserSettings(staticSiteGenerator, path)
|
const settings = getConfigParserSettings(staticSiteGenerator, path)
|
||||||
@@ -14925,7 +14909,7 @@ function setPagesPath({staticSiteGenerator, path}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {getConfigParserSettings, setPagesPath}
|
module.exports = { getConfigParserSettings, setPagesPath }
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|||||||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -53,9 +53,7 @@ describe('apiClient', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('handles a 409 response when the page already exists', async () => {
|
it('handles a 409 response when the page already exists', async () => {
|
||||||
jest
|
jest.spyOn(axios, 'post').mockImplementationOnce(() => Promise.reject({ response: { status: 409 } }))
|
||||||
.spyOn(axios, 'post')
|
|
||||||
.mockImplementationOnce(() => Promise.reject({ response: { status: 409 } }))
|
|
||||||
|
|
||||||
// Simply assert that no error is raised
|
// Simply assert that no error is raised
|
||||||
const result = await apiClient.enablePagesSite({
|
const result = await apiClient.enablePagesSite({
|
||||||
@@ -67,9 +65,7 @@ describe('apiClient', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('re-raises errors on failure status codes', async () => {
|
it('re-raises errors on failure status codes', async () => {
|
||||||
jest
|
jest.spyOn(axios, 'post').mockImplementationOnce(() => Promise.reject({ response: { status: 404 } }))
|
||||||
.spyOn(axios, 'post')
|
|
||||||
.mockImplementationOnce(() => Promise.reject({ response: { status: 404 } }))
|
|
||||||
|
|
||||||
let erred = false
|
let erred = false
|
||||||
try {
|
try {
|
||||||
@@ -98,9 +94,7 @@ describe('apiClient', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('re-raises errors on failure status codes', async () => {
|
it('re-raises errors on failure status codes', async () => {
|
||||||
jest
|
jest.spyOn(axios, 'get').mockImplementationOnce(() => Promise.reject({ response: { status: 404 } }))
|
||||||
.spyOn(axios, 'get')
|
|
||||||
.mockImplementationOnce(() => Promise.reject({ response: { status: 404 } }))
|
|
||||||
|
|
||||||
let erred = false
|
let erred = false
|
||||||
try {
|
try {
|
||||||
@@ -203,7 +197,8 @@ describe('apiClient', () => {
|
|||||||
|
|
||||||
it('makes second request to get page if create fails because of existence', async () => {
|
it('makes second request to get page if create fails because of existence', async () => {
|
||||||
const PAGE_OBJECT = { html_url: 'https://actions.github.io/is-awesome/' }
|
const PAGE_OBJECT = { html_url: 'https://actions.github.io/is-awesome/' }
|
||||||
jest.spyOn(axios, 'get')
|
jest
|
||||||
|
.spyOn(axios, 'get')
|
||||||
.mockImplementationOnce(() => Promise.reject({ response: { status: 404 } }))
|
.mockImplementationOnce(() => Promise.reject({ response: { status: 404 } }))
|
||||||
.mockImplementationOnce(() => Promise.resolve({ status: 200, data: PAGE_OBJECT }))
|
.mockImplementationOnce(() => Promise.resolve({ status: 200, data: PAGE_OBJECT }))
|
||||||
jest.spyOn(axios, 'post').mockImplementationOnce(() => Promise.reject({ response: { status: 409 } }))
|
jest.spyOn(axios, 'post').mockImplementationOnce(() => Promise.reject({ response: { status: 409 } }))
|
||||||
@@ -217,5 +212,4 @@ describe('apiClient', () => {
|
|||||||
expect(axios.post).toHaveBeenCalledTimes(1)
|
expect(axios.post).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class ConfigParser {
|
|||||||
// Ctor
|
// Ctor
|
||||||
// - configurationFile: path to the configuration file
|
// - configurationFile: path to the configuration file
|
||||||
// - blankConfigurationFile: a blank configuration file to use if non was previously found
|
// - blankConfigurationFile: a blank configuration file to use if non was previously found
|
||||||
constructor({configurationFile, blankConfigurationFile, properties}) {
|
constructor({ configurationFile, blankConfigurationFile, properties }) {
|
||||||
// Save field
|
// Save field
|
||||||
this.configurationFile = configurationFile
|
this.configurationFile = configurationFile
|
||||||
this.properties = properties
|
this.properties = properties
|
||||||
@@ -57,9 +57,7 @@ class ConfigParser {
|
|||||||
findConfigurationObject(ast) {
|
findConfigurationObject(ast) {
|
||||||
// Try to find a default export
|
// Try to find a default export
|
||||||
var defaultExport = ast.body.find(
|
var defaultExport = ast.body.find(
|
||||||
node =>
|
node => node.type === 'ExportDefaultDeclaration' && node.declaration.type === 'ObjectExpression'
|
||||||
node.type === 'ExportDefaultDeclaration' &&
|
|
||||||
node.declaration.type === 'ObjectExpression'
|
|
||||||
)
|
)
|
||||||
if (defaultExport) {
|
if (defaultExport) {
|
||||||
core.info('Found configuration object in default export declaration')
|
core.info('Found configuration object in default export declaration')
|
||||||
@@ -80,19 +78,13 @@ class ConfigParser {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Direct module export
|
// Direct module export
|
||||||
if (
|
if (moduleExport && moduleExport.expression.right.type === 'ObjectExpression') {
|
||||||
moduleExport &&
|
|
||||||
moduleExport.expression.right.type === 'ObjectExpression'
|
|
||||||
) {
|
|
||||||
core.info('Found configuration object in direct module export')
|
core.info('Found configuration object in direct module export')
|
||||||
return moduleExport.expression.right
|
return moduleExport.expression.right
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indirect module export
|
// Indirect module export
|
||||||
else if (
|
else if (moduleExport && moduleExport.expression.right.type === 'Identifier') {
|
||||||
moduleExport &&
|
|
||||||
moduleExport.expression.right.type === 'Identifier'
|
|
||||||
) {
|
|
||||||
const identifierName = moduleExport && moduleExport.expression.right.name
|
const identifierName = moduleExport && moduleExport.expression.right.name
|
||||||
const identifierDefinition = ast.body.find(
|
const identifierDefinition = ast.body.find(
|
||||||
node =>
|
node =>
|
||||||
@@ -120,9 +112,7 @@ class ConfigParser {
|
|||||||
// Try to find a property matching a given name
|
// Try to find a property matching a given name
|
||||||
const property =
|
const property =
|
||||||
object.type === 'ObjectExpression' &&
|
object.type === 'ObjectExpression' &&
|
||||||
object.properties.find(
|
object.properties.find(node => node.key.type === 'Identifier' && node.key.name === name)
|
||||||
node => node.key.type === 'Identifier' && node.key.name === name
|
|
||||||
)
|
|
||||||
|
|
||||||
// Return the property's value (if found) or null
|
// Return the property's value (if found) or null
|
||||||
if (property) {
|
if (property) {
|
||||||
@@ -142,9 +132,7 @@ class ConfigParser {
|
|||||||
return `${properties[startIndex]}: ${JSON.stringify(propertyValue)}`
|
return `${properties[startIndex]}: ${JSON.stringify(propertyValue)}`
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
`${properties[startIndex]}: {` +
|
`${properties[startIndex]}: {` + this.getPropertyDeclaration(properties, startIndex + 1, propertyValue) + '}'
|
||||||
this.getPropertyDeclaration(properties, startIndex + 1, propertyValue) +
|
|
||||||
'}'
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,11 +210,7 @@ class ConfigParser {
|
|||||||
// Create nested properties in the configuration file
|
// Create nested properties in the configuration file
|
||||||
else {
|
else {
|
||||||
// Build the declaration to inject
|
// Build the declaration to inject
|
||||||
const declaration = this.getPropertyDeclaration(
|
const declaration = this.getPropertyDeclaration(properties, depth, propertyValue)
|
||||||
properties,
|
|
||||||
depth,
|
|
||||||
propertyValue
|
|
||||||
)
|
|
||||||
|
|
||||||
// The last node identified is an object expression, so do the assignment
|
// The last node identified is an object expression, so do the assignment
|
||||||
if (lastNode.type === 'ObjectExpression') {
|
if (lastNode.type === 'ObjectExpression') {
|
||||||
@@ -273,4 +257,4 @@ class ConfigParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {ConfigParser}
|
module.exports = { ConfigParser }
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
|
||||||
const {ConfigParser} = require('./config-parser')
|
const { ConfigParser } = require('./config-parser')
|
||||||
const {getTempFolder, compareFiles} = require('./test-helpers')
|
const { getTempFolder, compareFiles } = require('./test-helpers')
|
||||||
|
|
||||||
// Get the temp folder
|
// Get the temp folder
|
||||||
const tempFolder = getTempFolder()
|
const tempFolder = getTempFolder()
|
||||||
@@ -134,15 +134,15 @@ const cases = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
describe('config-parser', () => {
|
describe('config-parser', () => {
|
||||||
cases.forEach(({property, source, expected}, index) => {
|
cases.forEach(({ property, source, expected }, index) => {
|
||||||
it(`Inject path properly for case #${index}`, () => {
|
it(`Inject path properly for case #${index}`, () => {
|
||||||
// Write the source file
|
// Write the source file
|
||||||
const sourceFile = `${tempFolder}/source.js`
|
const sourceFile = `${tempFolder}/source.js`
|
||||||
fs.writeFileSync(sourceFile, source, {encoding: 'utf8'})
|
fs.writeFileSync(sourceFile, source, { encoding: 'utf8' })
|
||||||
|
|
||||||
// Write the expected file
|
// Write the expected file
|
||||||
const expectedFile = `${tempFolder}/expected.js`
|
const expectedFile = `${tempFolder}/expected.js`
|
||||||
fs.writeFileSync(expectedFile, expected, {encoding: 'utf8'})
|
fs.writeFileSync(expectedFile, expected, { encoding: 'utf8' })
|
||||||
|
|
||||||
// Update the settings and do the injection
|
// Update the settings and do the injection
|
||||||
new ConfigParser({
|
new ConfigParser({
|
||||||
|
|||||||
@@ -22,4 +22,4 @@ function getContext() {
|
|||||||
return requiredVars
|
return requiredVars
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {getContext}
|
module.exports = { getContext }
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ describe('outputPagesBaseUrl', () => {
|
|||||||
outputPagesBaseUrl(new URL(baseUrl))
|
outputPagesBaseUrl(new URL(baseUrl))
|
||||||
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
||||||
expect(core.setOutput).toHaveBeenCalledWith(
|
expect(core.setOutput).toHaveBeenCalledWith('origin', 'https://octocat.github.io')
|
||||||
'origin',
|
|
||||||
'https://octocat.github.io'
|
|
||||||
)
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
|
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
|
||||||
})
|
})
|
||||||
@@ -38,10 +35,7 @@ describe('outputPagesBaseUrl', () => {
|
|||||||
outputPagesBaseUrl(new URL(baseUrl))
|
outputPagesBaseUrl(new URL(baseUrl))
|
||||||
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
||||||
expect(core.setOutput).toHaveBeenCalledWith(
|
expect(core.setOutput).toHaveBeenCalledWith('origin', 'https://octocat.github.io')
|
||||||
'origin',
|
|
||||||
'https://octocat.github.io'
|
|
||||||
)
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/my-repo/')
|
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/my-repo/')
|
||||||
})
|
})
|
||||||
@@ -52,10 +46,7 @@ describe('outputPagesBaseUrl', () => {
|
|||||||
outputPagesBaseUrl(new URL(baseUrl))
|
outputPagesBaseUrl(new URL(baseUrl))
|
||||||
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
||||||
expect(core.setOutput).toHaveBeenCalledWith(
|
expect(core.setOutput).toHaveBeenCalledWith('origin', 'https://www.example.com')
|
||||||
'origin',
|
|
||||||
'https://www.example.com'
|
|
||||||
)
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('host', 'www.example.com')
|
expect(core.setOutput).toHaveBeenCalledWith('host', 'www.example.com')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
|
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
const {ConfigParser} = require('./config-parser')
|
const { ConfigParser } = require('./config-parser')
|
||||||
|
|
||||||
// Return the settings to be passed to a {ConfigParser} for a given
|
// Return the settings to be passed to a {ConfigParser} for a given
|
||||||
// static site generator and a Pages path value to inject
|
// static site generator and a Pages path value to inject
|
||||||
@@ -51,7 +51,7 @@ function getConfigParserSettings(staticSiteGenerator, path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inject Pages configuration in a given static site generator's configuration file
|
// Inject Pages configuration in a given static site generator's configuration file
|
||||||
function setPagesPath({staticSiteGenerator, path}) {
|
function setPagesPath({ staticSiteGenerator, path }) {
|
||||||
try {
|
try {
|
||||||
// Parse the configuration file and try to inject the Pages configuration in it
|
// Parse the configuration file and try to inject the Pages configuration in it
|
||||||
const settings = getConfigParserSettings(staticSiteGenerator, path)
|
const settings = getConfigParserSettings(staticSiteGenerator, path)
|
||||||
@@ -65,4 +65,4 @@ function setPagesPath({staticSiteGenerator, path}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {getConfigParserSettings, setPagesPath}
|
module.exports = { getConfigParserSettings, setPagesPath }
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const {getConfigParserSettings} = require('./set-pages-path')
|
const { getConfigParserSettings } = require('./set-pages-path')
|
||||||
const {ConfigParser} = require('./config-parser')
|
const { ConfigParser } = require('./config-parser')
|
||||||
const {getTempFolder, compareFiles} = require('./test-helpers')
|
const { getTempFolder, compareFiles } = require('./test-helpers')
|
||||||
|
|
||||||
// Get the temp folder
|
// Get the temp folder
|
||||||
const tempFolder = getTempFolder()
|
const tempFolder = getTempFolder()
|
||||||
@@ -40,10 +40,7 @@ describe('configParser', () => {
|
|||||||
new ConfigParser(settings).injectAll()
|
new ConfigParser(settings).injectAll()
|
||||||
|
|
||||||
// Read the expected file
|
// Read the expected file
|
||||||
const expectedFile = `${fixtureFolder}/${path.basename(
|
const expectedFile = `${fixtureFolder}/${path.basename(configurationFile, '.js')}.expected.js`
|
||||||
configurationFile,
|
|
||||||
'.js'
|
|
||||||
)}.expected.js`
|
|
||||||
|
|
||||||
// Compare the actual and expected files
|
// Compare the actual and expected files
|
||||||
compareFiles(settings.configurationFile, expectedFile)
|
compareFiles(settings.configurationFile, expectedFile)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const assert = require('assert')
|
|||||||
function getTempFolder() {
|
function getTempFolder() {
|
||||||
const tmpFolder = `${__dirname}/fixtures/tmp`
|
const tmpFolder = `${__dirname}/fixtures/tmp`
|
||||||
if (!fs.existsSync(tmpFolder)) {
|
if (!fs.existsSync(tmpFolder)) {
|
||||||
fs.mkdirSync(tmpFolder, {recursive: true})
|
fs.mkdirSync(tmpFolder, { recursive: true })
|
||||||
}
|
}
|
||||||
return tmpFolder
|
return tmpFolder
|
||||||
}
|
}
|
||||||
@@ -14,19 +14,21 @@ function getTempFolder() {
|
|||||||
// Read a JavaScript file and return it formatted
|
// Read a JavaScript file and return it formatted
|
||||||
function formatFile(file) {
|
function formatFile(file) {
|
||||||
const fileContent = fs.readFileSync(file, 'utf8')
|
const fileContent = fs.readFileSync(file, 'utf8')
|
||||||
return prettier.format(fileContent, {
|
return prettier
|
||||||
parser: 'espree',
|
.format(fileContent, {
|
||||||
|
parser: 'espree',
|
||||||
|
|
||||||
// Prettier options
|
// Prettier options
|
||||||
printWidth: 80,
|
printWidth: 120,
|
||||||
tabWidth: 2,
|
tabWidth: 2,
|
||||||
useTabs: false,
|
useTabs: false,
|
||||||
semi: false,
|
semi: false,
|
||||||
singleQuote: true,
|
singleQuote: true,
|
||||||
trailingComma: 'none',
|
trailingComma: 'none',
|
||||||
bracketSpacing: false,
|
bracketSpacing: true,
|
||||||
arrowParens: 'avoid'
|
arrowParens: 'avoid'
|
||||||
}).trim()
|
})
|
||||||
|
.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare two JavaScript files
|
// Compare two JavaScript files
|
||||||
@@ -34,4 +36,4 @@ function compareFiles(actualFile, expectedFile) {
|
|||||||
assert.equal(formatFile(actualFile), formatFile(expectedFile))
|
assert.equal(formatFile(actualFile), formatFile(expectedFile))
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {getTempFolder, formatFile, compareFiles}
|
module.exports = { getTempFolder, formatFile, compareFiles }
|
||||||
|
|||||||
Reference in New Issue
Block a user