Skip to content

Commit

Permalink
feat(init): tool initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
msanguineti committed Apr 17, 2019
1 parent 458c538 commit 8247b7f
Show file tree
Hide file tree
Showing 13 changed files with 1,269 additions and 614 deletions.
99 changes: 99 additions & 0 deletions __tests__/core.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import * as core from '../src/core'
import sh from 'shelljs'

describe('testing core functionalities', () => {
describe('config', () => {
let tempConfigFile: string

test('default config values are defined', () => {
const defaults: core.ConfigValues = core.getDefaultConfigValues()

expect(defaults).toBeDefined()
})
test('default config values contain values', () => {
const defaults: core.ConfigValues = core.getDefaultConfigValues()

expect(defaults.main).toMatch('master')
expect(defaults.usedev).not.toBeTruthy()
expect(defaults.integration).toEqual(1)
})

test('load default values if no config files - part I', () => {
const defaults = core.loadConfigFile()

expect(defaults.main).toMatch('master')
expect(defaults.usedev).not.toBeTruthy()
expect(defaults.integration).toEqual(1)
})

test('load default values if no config files - part II', () => {
const defaults = core.loadConfigValues()

expect(defaults.main).toMatch('master')
expect(defaults.usedev).not.toBeTruthy()
expect(defaults.integration).toEqual(1)
})

test('write default config file', () => {
core.writeConfigFile({})

expect(sh.test('-f', 'gof.config.js')).toBeTruthy()
sh.rm('gof.config.js')
})

test('write to config file', () => {
tempConfigFile = sh.tempdir() + '/gof.test.config.json'

core.writeConfigFile({
file: tempConfigFile,
data: { test: 'test value' }
})

expect(sh.test('-f', tempConfigFile)).toBeTruthy()
})

test('load config values from file', () => {
const defaults = core.loadConfigFile(tempConfigFile)

expect(defaults).toBeDefined()
expect(defaults.test).toMatch('test value')
})

test('write to (and load from) .js file', () => {
const jsFile = sh.tempdir() + '/gof.config.js'

core.writeConfigFile({
file: jsFile,
data: { development: 'develop', test: true }
})

expect(sh.test('-f', jsFile)).toBeTruthy()

const jsObject = core.loadConfigFile(jsFile)

expect(jsObject.development).toMatch('develop')
expect(jsObject.test).toBeTruthy()
})

test('attemp to write to wrong file type', () => {
const wrong = core.writeConfigFile({ file: 'file.wrong' })

expect(wrong).not.toBeTruthy()
})
})

describe('git', () => {
test('the branch name is valid', () => {
expect(core.isValidBranchName('branch/name')).toBeTruthy()
})
test('the branch name is invalid', () => {
expect(core.isValidBranchName('branch///dkd/.kdk,.l')).not.toBeTruthy()
})
test('the tag name is valid', () => {
expect(core.isValidTagName('1.2.3')).toBeTruthy()
})
test('the tag name is invalid', () => {
expect(core.isValidTagName('1...3.4.5')).not.toBeTruthy()
})
})
})
165 changes: 0 additions & 165 deletions bin/gof-init.js

This file was deleted.

Loading

0 comments on commit 8247b7f

Please sign in to comment.