Skip to content

Commit

Permalink
Added "-u" option to overwrite test outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anantachai Saothong (Manta) committed May 6, 2020
1 parent 86c90dc commit 2f707bc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ const Stylus = require('stylus')
const format = require('../edge/format')
const compareContent = require('../edge/compareContent')

const filesAndDirectories = _.chain(ps.argv.length > 2 ? ps.argv.slice(2) : ['*']).map(para => glob.sync('spec/' + para)).flatten().value()
const filesAndDirectories = _.chain(ps.argv.length > 2 ? ps.argv.slice(2) : ['*'])
.reject(para => para.startsWith('-'))
.map(para => glob.sync('spec/' + para))
.flatten()
.filter(directory => fs.lstatSync(directory).isDirectory() && fs.readdirSync(directory).length > 0)
.value()
const filesOnly = path => pt.extname(path) === '.js'
const directoriesOnly = path => pt.extname(path) === ''

const outputOverwritten = ps.argv.includes('-u')

filesAndDirectories.filter(directoriesOnly).forEach(directory => {
const optionFilePath = pt.join(directory, 'formattingOptions.json')
const inputFilePath = pt.join(directory, 'input.styl')
Expand All @@ -40,7 +47,7 @@ filesAndDirectories.filter(directoriesOnly).forEach(directory => {
formattingOptions = require('../' + optionFilePath)
}

if (fs.existsSync(outputFilePath) === false) {
if (fs.existsSync(outputFilePath) === false || outputOverwritten) {
const actualContent = format(inputContent, formattingOptions)
fs.writeFileSync(outputFilePath, actualContent)
}
Expand Down

0 comments on commit 2f707bc

Please # to comment.