Skip to content

Commit

Permalink
add update -all-test-.js command to main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jparkerweb committed Jan 7, 2020
1 parent 72e5a6e commit dfe0137
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 5 deletions.
12 changes: 12 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ function abracadabra(msg) {
})
break

// UPDATE -all- TEST GROUP WITH EXISTING TEST FILES
case 'update-all-test-group':
require('./app_modules/_updateAllTestGroup')()
.then(function() {
// blank()
pressEnterToContinue('-all-tests-.js'.yellow.bold + ' scenario was updated/created with all ' + 'test files'.yellow.bold + '\n\n.press enter to continue...', abracadabra) // restart app
})
.catch(function(err) {
console.log(err.bgRed.white)
})
break

// OPEN REPORT
case 'open-report':
checkForExistingReferences(false)
Expand Down
35 changes: 35 additions & 0 deletions app_modules/_getAllTestFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// ----------------------
// - get all test files -
// ----------------------

let walk = require('walk') // file system walker (get file names)

let getAllTestFiles = function() {
return new Promise(function(resolve, reject) {
let allTestFileNames = []
let walker = walk.walk('./bivariate_data/test_scripts', { followLinks: true })

walker.on('file', function(root, stat, next) {
let currentFile = stat.name
if(currentFile.charAt(0) === "_" && currentFile.charAt(1) !== "_") {
currentFile = currentFile.slice(0, -3)
currentFile = root + '\/' + currentFile
currentFile = currentFile.replace(/\\/g, "/")
currentFile = currentFile.replace(/\.\/bivariate_data\/test_scripts\//g, "")
allTestFileNames.push(currentFile)
}
next()
})

walker.on('end', function() {
resolve(allTestFileNames)
})

})
}


// *************
// ** Exports **
// *************
module.exports = getAllTestFiles
4 changes: 4 additions & 0 deletions app_modules/_questionsTestType.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ let questionsTestType = [
name: '- CREATE new blank Test file',
value: 'create-new-test'
},
{
name: '- UPDATE/CREATE `-all-tests-` test group with all existing test files',
value: 'update-all-test-group'
},
{
name: '',
value: ''
Expand Down
73 changes: 73 additions & 0 deletions app_modules/_updateAllTestGroup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// -----------------------------
// -- update -all- test group --
// -----------------------------
// jshint esversion: 6

let updateAllTestGroup = function updateAllTestGroup() {
let colors = require("colors") // pretty console colors
let forEach = require('mout/array/forEach') // foreach array util
let getAllTestFiles = require('./_getAllTestFiles')
let path = require('path')

return new Promise(function(resolve, reject) {
getAllTestFiles()
.then(function(testGroups) {
let allTestFilePath = path.join(process.cwd(), "./bivariate_data/test_scripts/-all-tests-.js")
let scenariosStringStart = "\"scenarios\": \["
let scenariosStringEnd = "\n\t\t\]"
let scenarioList = ""

/// loop trough tests and create regex replace string for -all- scenario
forEach(testGroups, function(val) {
val = val.replace(/\\/g,"\/")
scenarioList += "\n\t\t\trequire\(\'\.\/" + val + "\'\)\(baseURLs\),"
})

let scenariosString = scenariosStringStart + scenarioList + scenariosStringEnd

const copy = require('recursive-copy')
const replaceInFile = require('replace-in-file')

let templateTest = path.join(__dirname, '../init-bivariate-data/templates/-all-tests-.js')
let allTestFile = path.join(process.cwd(), './bivariate_data/test_scripts/-all-tests-.js')

copy(templateTest, allTestFile, { overwrite: true }, function(error, results) {
if (error) {
console.error('failed to create Test file: ' + error)
}
else {
let templateOptions = {
files: allTestFilePath,
from: [
/\"scenarios\"\: \[[\s\S]*\]/gm
],
to: [
scenariosString
]
}

try {
// update -all-tests-.js script scenario with all test files
const changes = replaceInFile.sync(templateOptions)
// console.log('Modified files:', changes.join(', '))

if (changes) {
// console.log(("test files:").yellow.bold)
// console.log(testGroups)
resolve('UPDATED -all-tests-.js scenario with all test files')
}
}
catch (error) {
console.error('Error occurred:', error)
}
}
})
})
})
}


// *************
// ** Exports **
// *************
module.exports = updateAllTestGroup
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ----------------
// -- Test Group --
// ----------------
// ----------------------
// -- -all- Test Group --
// ----------------------

let mixIn = require("./../libs/mout-mixin/mixIn")
let mixIn = require("../libs/mout-mixin/mixIn")
let testGroup = __filename.slice(__dirname.length + 1, -3)
let configCommon = require('./__config-common')(testGroup)
let baseURLs = require("./__config-baseURLs")
Expand Down
22 changes: 22 additions & 0 deletions init-bivariate-data/test_scripts/-all-tests-.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ----------------------
// -- -all- Test Group --
// ----------------------

let mixIn = require("../libs/mout-mixin/mixIn")
let testGroup = __filename.slice(__dirname.length + 1, -3)
let configCommon = require('./__config-common')(testGroup)
let baseURLs = require("./__config-baseURLs")


module.exports = mixIn(
{
// ---------------
// -- Scenarios --
// ---------------
"scenarios": [
require('./_example-test--home')(baseURLs),
require('./_example-test--paints')(baseURLs)
],
},
configCommon
)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bivariate",
"version": "0.13.0",
"version": "0.14.1",
"description": "An opinionated interface for writing, running, and saving BackstopJS tests",
"keywords": [
"BackstopJS",
Expand Down

0 comments on commit dfe0137

Please sign in to comment.