mirror of
https://github.com/actions/configure-pages.git
synced 2026-03-30 18:14:51 +00:00
add test cases
This commit is contained in:
@@ -1,14 +1,83 @@
|
||||
const ConfigParser = require('./config-parser')
|
||||
const { ConfigParser } = require('./config-parser')
|
||||
const fs = require("fs")
|
||||
const assert = require('assert')
|
||||
|
||||
const srcFolder = `src/fixtures`
|
||||
const tmpFolder = `src/fixtures/tmp`
|
||||
const expectedFolder = `src/fixtures/expected`
|
||||
|
||||
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
|
||||
}],
|
||||
];
|
||||
|
||||
describe('configParser', () => {
|
||||
it('set nextjs url correctly', async () => {
|
||||
// parser = new ConfigParser({
|
||||
// filePath:"./nuxt.config.js",
|
||||
// type: "nuxt",
|
||||
// pathName: "router",
|
||||
// subPathName: "base",
|
||||
// newPath: baseUrl
|
||||
// })
|
||||
// parser.generateConfigFile()
|
||||
})
|
||||
})
|
||||
test.each(cases)(
|
||||
"%p parsed correctly",
|
||||
(fileName, configuration) => {
|
||||
srcFileName = `${srcFolder}/${fileName}`
|
||||
tmpFileName = `${tmpFolder}/${fileName}`
|
||||
expectedFileName = `${expectedFolder}/${fileName}`
|
||||
|
||||
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)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user