Skip to content

Commit

Permalink
Merge pull request #41 from actions/alt-blank-extensions
Browse files Browse the repository at this point in the history
Test: Better support alternative file extensions for blank config files
  • Loading branch information
JamesMGreene committed Nov 23, 2022
2 parents b94e9ad + 948e60f commit 0c2178e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/set-pages-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ const tempFolder = getTempFolder()

const SUPPORTED_GENERATORS = ['next', 'nuxt', 'gatsby', 'sveltekit']
const SUPPORTED_FILE_EXTENSIONS = ['.js', '.cjs', '.mjs']
const IS_BLANK_CONFIG_FILE_REGEX = new RegExp(
'^blank\\.(' + SUPPORTED_FILE_EXTENSIONS.map(ext => ext.slice(1)).join('|') + ')$'
)

function isBlankConfigFileName(fileName) {
return IS_BLANK_CONFIG_FILE_REGEX.test(fileName)
}

// Test suite
describe('configParser', () => {
Expand Down Expand Up @@ -44,7 +51,7 @@ describe('configParser', () => {
// Copy the source fixture to a temp file
const fixtureSourceFile = `${fixtureFolder}/${configurationFile}`
const fixtureTargetFile = `${tempFolder}/${configurationFile}`
if (configurationFile !== 'blank.js') {
if (!isBlankConfigFileName(configurationFile)) {
fs.copyFileSync(fixtureSourceFile, fixtureTargetFile)
} else if (fs.existsSync(fixtureTargetFile)) {
fs.rmSync(fixtureTargetFile)
Expand Down Expand Up @@ -77,7 +84,7 @@ describe('configParser', () => {
// Copy the source fixture to a temp file
const fixtureSourceFile = `${fixtureFolder}/${configurationFile}`
const fixtureTargetFile = `${tempFolder}/${configurationFile}`
if (configurationFile !== 'blank.js') {
if (!isBlankConfigFileName(configurationFile)) {
fs.copyFileSync(fixtureSourceFile, fixtureTargetFile)
} else if (fs.existsSync(fixtureTargetFile)) {
fs.rmSync(fixtureTargetFile)
Expand Down

0 comments on commit 0c2178e

Please sign in to comment.