From 2f707bc7ac9a6018848d9bccd0c6451eab8dce16 Mon Sep 17 00:00:00 2001 From: "Anantachai Saothong (Manta)" Date: Wed, 6 May 2020 14:58:03 +0700 Subject: [PATCH] Added "-u" option to overwrite test outputs --- test/runner.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/runner.js b/test/runner.js index db5faf6..fba1337 100644 --- a/test/runner.js +++ b/test/runner.js @@ -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') @@ -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) }