Skip to content

Commit

Permalink
test: fix detect-server test
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah committed Jan 28, 2021
1 parent 67c2bac commit 2c1e38d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 41 deletions.
14 changes: 0 additions & 14 deletions src/utils/detect-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,6 @@ const getStaticServerSettings = async function (settings, flags, projectDir, log

const DEFAULT_STATIC_PORT = 3999

const loadDetector = function (detectorName) {
try {
// eslint-disable-next-line node/global-require, import/no-dynamic-require
return require(path.join(__dirname, '..', 'detectors', detectorName))
} catch (error) {
throw new Error(
`Failed to load detector: ${chalk.yellow(
detectorName,
)}, this is likely a bug in the detector, please file an issue in netlify-cli\n ${error}`,
)
}
}

/** utilities for the inquirer section above */
const filterSettings = function (scriptInquirerOptions, input) {
const filteredSettings = fuzzy.filter(
Expand Down Expand Up @@ -228,5 +215,4 @@ const formatSettingsArrForInquirer = function (frameworks) {

module.exports = {
serverSettings,
loadDetector,
}
31 changes: 4 additions & 27 deletions src/utils/detect-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const getPort = require('get-port')

const { createSiteBuilder } = require('../../tests/utils/site-builder')

const { loadDetector, serverSettings, chooseDefaultArgs } = require('./detect-server')
const { serverSettings } = require('./detect-server')

const TARGET_PORT = 1234
const CUSTOM_PORT = 3000
Expand All @@ -28,20 +28,6 @@ test.after(async (t) => {
await t.context.builder.cleanupAsync()
})

test('loadDetector: valid', (t) => {
const detector = loadDetector('create-react-app.js')
t.is(typeof detector, 'function')
})

test('loadDetector: invalid', (t) => {
t.throws(
() => {
loadDetector('cry.js')
},
{ message: /Failed to load detector/ },
)
})

test('serverSettings: minimal config', async (t) => {
const settings = await serverSettings({ framework: '#auto' }, {}, t.context.sitePath, () => {})
t.is(settings.framework, undefined)
Expand All @@ -64,24 +50,21 @@ test('serverSettings: "command" override npm', async (t) => {
const devConfig = { framework: '#custom', command: 'npm run dev', targetPort: TARGET_PORT }
const settings = await serverSettings(devConfig, {}, t.context.sitePath, () => {})
t.is(settings.framework, devConfig.framework)
t.is(settings.command, devConfig.command.split(' ')[0])
t.deepEqual(settings.args, devConfig.command.split(' ').slice(1))
t.is(settings.command, devConfig.command)
})

test('serverSettings: "command" override yarn', async (t) => {
const devConfig = { framework: '#custom', command: 'yarn dev', targetPort: TARGET_PORT }
const settings = await serverSettings(devConfig, {}, t.context.sitePath, () => {})
t.is(settings.framework, devConfig.framework)
t.is(settings.command, devConfig.command.split(' ')[0])
t.deepEqual(settings.args, devConfig.command.split(' ').slice(1))
t.is(settings.command, devConfig.command)
})

test('serverSettings: custom framework parameters', async (t) => {
const devConfig = { framework: '#custom', command: 'yarn dev', targetPort: CUSTOM_PORT, publish: t.context.sitePath }
const settings = await serverSettings(devConfig, {}, t.context.sitePath, () => {})
t.is(settings.framework, '#custom')
t.is(settings.command, devConfig.command.split(' ')[0])
t.deepEqual(settings.args, devConfig.command.split(' ').slice(1))
t.is(settings.command, devConfig.command)
t.is(settings.targetPort, devConfig.frameworkPort)
t.is(settings.dist, devConfig.publish)
})
Expand Down Expand Up @@ -187,9 +170,3 @@ test('serverSettings: no config', async (t) => {
t.truthy(settings.frameworkPort)
t.is(settings.noCmd, true)
})

test('chooseDefaultArgs', (t) => {
const possibleArgsArrs = [['run', 'dev'], ['run develop']]
const args = chooseDefaultArgs(possibleArgsArrs)
t.deepEqual(args, possibleArgsArrs[0])
})

0 comments on commit 2c1e38d

Please sign in to comment.