Skip to content

Commit

Permalink
Add set-pages-path tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoann Chaudet committed Jul 19, 2022
1 parent 43a5456 commit ba4576e
Show file tree
Hide file tree
Showing 26 changed files with 317 additions and 168 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"axios": "^0.27.2",
"axios-retry": "^3.2.5",
"espree": "^9.3.2",
"prettier": "^2.7.1",
"string-format": "^1.0.0"
},
"devDependencies": {
"@vercel/ncc": "^0.34.0",
"jest": "^28.1.1"
"jest": "^28.1.1",
"prettier": "^2.7.1"
}
}
3 changes: 2 additions & 1 deletion src/config-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class ConfigParser {
}
}

parse() {
// Parse a configuration file and try to inject Pages settings in it.
inject() {
// Logging
core.info(`Parsing configuration:\n${this.configuration}`)

Expand Down
101 changes: 0 additions & 101 deletions src/config-parser.test.js

This file was deleted.

101 changes: 101 additions & 0 deletions src/config-parser.testx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// 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 cases = [
// [
// 'next.config.js',
// {
// configurationFile: `${tmpFolder}/next.config.js`,
// propertyName: 'basePath',
// propertyValue: repoPath,
// blankConfigurationFile: `${process.cwd()}/src/blank-configurations/next.js`
// }
// ],
// [
// 'next.config.old.js',
// {
// configurationFile: `${tmpFolder}/next.config.old.js`,
// propertyName: 'basePath',
// propertyValue: repoPath,
// blankConfigurationFile: `${process.cwd()}/src/blank-configurations/next.js`
// }
// ],
// [
// 'next.config.old.missing.js',
// {
// configurationFile: `${tmpFolder}/next.config.old.missing.js`,
// propertyName: 'basePath',
// propertyValue: repoPath,
// blankConfigurationFile: `${process.cwd()}/src/blank-configurations/next.js`
// }
// ],
// [
// 'gatsby-config.js',
// {
// configurationFile: `${tmpFolder}/gatsby-config.js`,
// propertyName: 'pathPrefix',
// propertyValue: repoPath,
// blankConfigurationFile: `${process.cwd()}/src/blank-configurations/gatsby.js`
// }
// ],
// [
// 'gatsby-config.old.js',
// {
// configurationFile: `${tmpFolder}/gatsby-config.old.js`,
// propertyName: 'pathPrefix',
// propertyValue: repoPath,
// blankConfigurationFile: `${process.cwd()}/src/blank-configurations/gatsby.js`
// }
// ],
// [
// 'nuxt.config.js',
// {
// configurationFile: `${tmpFolder}/nuxt.config.js`,
// propertyName: 'router.base',
// propertyValue: repoPath,
// blankConfigurationFile: `${process.cwd()}/src/blank-configurations/nuxt.js`
// }
// ],
// [
// 'nuxt.config.missing.js',
// {
// configurationFile: `${tmpFolder}/nuxt.config.missing.js`,
// propertyName: 'router.base',
// propertyValue: repoPath,
// blankConfigurationFile: `${process.cwd()}/src/blank-configurations/nuxt.js`
// }
// ],
// [
// 'nuxt.config.old.js',
// {
// configurationFile: `${tmpFolder}/nuxt.config.old.js`,
// propertyName: 'router.base',
// propertyValue: repoPath,
// blankConfigurationFile: `${process.cwd()}/src/blank-configurations/nuxt.js`
// }
// ]
// ]

// 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()

// var expectedContent = fs.readFileSync(expectedFileName).toString()
// var actualContent = fs.readFileSync(tmpFileName).toString()
// assert.equal(actualContent, expectedContent)
// fs.rmSync(tmpFileName)
// })
// })
5 changes: 4 additions & 1 deletion src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ function getRequiredVars() {
}
}

module.exports = function getContext() {
// Return the context object
function getContext() {
const requiredVars = getRequiredVars()
for (const variable in requiredVars) {
if (requiredVars[variable] === undefined) {
Expand All @@ -19,3 +20,5 @@ module.exports = function getContext() {
core.debug('all variables are set')
return requiredVars
}

module.exports = {getContext}
8 changes: 0 additions & 8 deletions src/fixtures/expected/gatsby-config.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/fixtures/expected/gatsby-config.old.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/fixtures/expected/next.config.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/fixtures/expected/next.config.old.js

This file was deleted.

1 change: 0 additions & 1 deletion src/fixtures/expected/next.config.old.missing.js

This file was deleted.

11 changes: 0 additions & 11 deletions src/fixtures/expected/nuxt.config.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/fixtures/expected/nuxt.config.missing.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/fixtures/expected/nuxt.config.old.js

This file was deleted.

2 changes: 2 additions & 0 deletions src/fixtures/gatsby/blank.expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Default Pages configuration for Gatsby
module.exports = { pathPrefix: "/docs/" }
1 change: 1 addition & 0 deletions src/fixtures/gatsby/blank.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This file is not read by the test suite
8 changes: 8 additions & 0 deletions src/fixtures/gatsby/default.expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
pathPrefix: "/docs/",
siteMetadata: {
title: `My Gatsby Site`,
siteUrl: `https://www.yourdomain.tld`,
},
plugins: [],
}
7 changes: 7 additions & 0 deletions src/fixtures/gatsby/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
siteMetadata: {
title: `My Gatsby Site`,
siteUrl: `https://www.yourdomain.tld`,
},
plugins: [],
}
3 changes: 3 additions & 0 deletions src/fixtures/next/blank.expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Default Pages configuration for Next
const nextConfig = { basePath: "/docs/" }
module.exports = nextConfig
1 change: 1 addition & 0 deletions src/fixtures/next/blank.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This file is not read by the test suite
8 changes: 8 additions & 0 deletions src/fixtures/next/default.expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
basePath: "/docs/",
reactStrictMode: true,
swcMinify: true,
}

module.exports = nextConfig
7 changes: 7 additions & 0 deletions src/fixtures/next/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
}

module.exports = nextConfig
Loading

0 comments on commit ba4576e

Please sign in to comment.