@kudobuzz/kbscripts
Version:
Configuration and scripts for kudobuzz projects
98 lines (86 loc) • 2.69 kB
JavaScript
'use strict'
const chai = require('chai')
const which = require('which')
const path = require('path')
const {
getPathToGlobalCommand,
hereRelative,
resolveExecutable
} = require('./utils')
describe('Utils', () => {
it('getPathToGlobalCommand() when executable found', async () => {
const exec = 'node'
const str = getPathToGlobalCommand(exec)
chai.expect(which.sync(exec)).equal(str)
})
it('getPathToGlobalCommand() when executable is not found', async () => {
const exec = 'kitugani'
const str = getPathToGlobalCommand(exec)
chai.expect(str).to.be.equal(null)
})
it('hereRelative()', async () => {
const base = '/some/folder'
const relativePath = hereRelative(base)
const expectedPath = path.join(__dirname, base).replace(process.cwd(), '.')
chai.expect(relativePath).to.be.equals(expectedPath)
})
it('resolveExecutable() test with eslint', async () => {
const exec = 'eslint'
const expectedOutput = 'test' // './node_modules/eslint/bin/eslint.js'
const params = {
pathToGlobalCommand: getPathToGlobalCommand(exec),
moduleName: exec,
cwd: process.cwd()
}
chai.expect(resolveExecutable(exec, params), expectedOutput)
})
it('resolveExecutable() test with prettier-standard', async () => {
const exec = 'prettier-standard'
const expectedOutput = './node_modules/prettier-standard/src/cli.js'
const params = {
pathToGlobalCommand: getPathToGlobalCommand(exec),
moduleName: exec,
cwd: process.cwd()
}
chai.expect(resolveExecutable(exec, params)).to.be.equal(expectedOutput)
})
it('resolveExecutable() when moduleName is not a string', async () => {
const exec = {}
const params = {
pathToGlobalCommand: getPathToGlobalCommand('exec'),
moduleName: exec,
cwd: process.cwd()
}
try {
resolveExecutable('some', params)
} catch (e) {
chai.expect(e).to.be.instanceOf(Error)
}
})
it('resolveExecutable() error when executable is not a string', async () => {
const exec = {}
const params = {
pathToGlobalCommand: getPathToGlobalCommand('eslints'),
moduleName: 'eslint',
cwd: process.cwd()
}
try {
resolveExecutable(exec, params)
} catch (e) {
chai.expect(e).to.be.instanceOf(Error)
}
})
it('resolveExecutable() error when cwd is not a string', async () => {
const exec = 'eslint'
const params = {
pathToGlobalCommand: getPathToGlobalCommand(exec),
moduleName: exec,
cwd: {}
}
try {
resolveExecutable(exec, params)
} catch (e) {
chai.expect(e).to.be.instanceOf(Error)
}
})
})