Add prettier configuration

This commit is contained in:
Yoann Chaudet
2022-07-18 15:06:14 -07:00
parent bfe36bc062
commit 61e591d3b5
10 changed files with 283 additions and 168 deletions

View File

@@ -1,83 +1,104 @@
const { ConfigParser } = require('./config-parser')
const fs = require("fs")
const {ConfigParser} = require('./config-parser')
const fs = require('fs')
const assert = require('assert')
const srcFolder = `${process.cwd()}/src/fixtures`
const tmpFolder = `${process.cwd()}/src/fixtures/tmp`
const expectedFolder = `${process.cwd()}/src/fixtures/expected`
const repoPath = "/amazing-new-repo/"
const repoPath = '/amazing-new-repo/'
const cases = [
["next.config.js", {
filePath: `${tmpFolder}/next.config.js`,
type: "next",
pathName: "basePath",
newPath: repoPath
}],
["next.config.old.js", {
filePath: `${tmpFolder}/next.config.old.js`,
type: "next",
pathName: "basePath",
newPath: repoPath
}],
["next.config.old.missing.js", {
filePath: `${tmpFolder}/next.config.old.missing.js`,
type: "next",
pathName: "basePath",
newPath: repoPath
}],
["gatsby-config.js", {
filePath: `${tmpFolder}/gatsby-config.js`,
type: "gatsby",
pathName: "pathPrefix",
newPath: repoPath
}],
["gatsby-config.old.js", {
filePath: `${tmpFolder}/gatsby-config.old.js`,
type: "gatsby",
pathName: "pathPrefix",
newPath: repoPath
}],
["nuxt.config.js", {
filePath:`${tmpFolder}/nuxt.config.js`,
type: "nuxt",
pathName: "router",
subPathName: "base",
newPath: repoPath
}],
["nuxt.config.missing.js", {
filePath:`${tmpFolder}/nuxt.config.missing.js`,
type: "nuxt",
pathName: "router",
subPathName: "base",
newPath: repoPath
}],
["nuxt.config.old.js", {
filePath:`${tmpFolder}/nuxt.config.old.js`,
type: "nuxt",
pathName: "router",
subPathName: "base",
newPath: repoPath
}],
];
[
'next.config.js',
{
filePath: `${tmpFolder}/next.config.js`,
type: 'next',
pathName: 'basePath',
newPath: repoPath
}
],
[
'next.config.old.js',
{
filePath: `${tmpFolder}/next.config.old.js`,
type: 'next',
pathName: 'basePath',
newPath: repoPath
}
],
[
'next.config.old.missing.js',
{
filePath: `${tmpFolder}/next.config.old.missing.js`,
type: 'next',
pathName: 'basePath',
newPath: repoPath
}
],
[
'gatsby-config.js',
{
filePath: `${tmpFolder}/gatsby-config.js`,
type: 'gatsby',
pathName: 'pathPrefix',
newPath: repoPath
}
],
[
'gatsby-config.old.js',
{
filePath: `${tmpFolder}/gatsby-config.old.js`,
type: 'gatsby',
pathName: 'pathPrefix',
newPath: repoPath
}
],
[
'nuxt.config.js',
{
filePath: `${tmpFolder}/nuxt.config.js`,
type: 'nuxt',
pathName: 'router',
subPathName: 'base',
newPath: repoPath
}
],
[
'nuxt.config.missing.js',
{
filePath: `${tmpFolder}/nuxt.config.missing.js`,
type: 'nuxt',
pathName: 'router',
subPathName: 'base',
newPath: repoPath
}
],
[
'nuxt.config.old.js',
{
filePath: `${tmpFolder}/nuxt.config.old.js`,
type: 'nuxt',
pathName: 'router',
subPathName: 'base',
newPath: repoPath
}
]
]
describe('configParser', () => {
test.each(cases)(
"%p parsed correctly",
(fileName, configuration) => {
srcFileName = `${srcFolder}/${fileName}`
tmpFileName = `${tmpFolder}/${fileName}`
expectedFileName = `${expectedFolder}/${fileName}`
fs.mkdirSync(tmpFolder, {recursive: true})
fs.copyFileSync(srcFileName, tmpFileName)
const parser = new ConfigParser(configuration)
parser.parse()
test.each(cases)('%p parsed correctly', (fileName, configuration) => {
srcFileName = `${srcFolder}/${fileName}`
tmpFileName = `${tmpFolder}/${fileName}`
expectedFileName = `${expectedFolder}/${fileName}`
fs.mkdirSync(tmpFolder, {recursive: true})
fs.copyFileSync(srcFileName, tmpFileName)
const parser = new ConfigParser(configuration)
parser.parse()
var expectedContent = fs.readFileSync(expectedFileName).toString()
var actualContent = fs.readFileSync(tmpFileName).toString()
assert.equal(actualContent, expectedContent)
fs.rmSync(tmpFileName)
}
)
var expectedContent = fs.readFileSync(expectedFileName).toString()
var actualContent = fs.readFileSync(tmpFileName).toString()
assert.equal(actualContent, expectedContent)
fs.rmSync(tmpFileName)
})
})