-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: Add ember steps:list command for listing available steps (#5255)
* ui: Add ember steps:list command for listing available steps 1. Adds `command` addon to house the new command 2. Start to organize out the steps themselves, bring a bit more order to things ready to dedupe and cleanup
- Loading branch information
Showing
18 changed files
with
776 additions
and
520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint no-console: "off" */ | ||
/* eslint-env node */ | ||
'use strict'; | ||
module.exports = { | ||
name: 'commands', | ||
includedCommands: function() { | ||
return { | ||
'steps:list': { | ||
name: 'steps:list', | ||
run: function(config, args) { | ||
require('./lib/list.js')(`${process.cwd()}/tests/steps.js`); | ||
}, | ||
}, | ||
}; | ||
}, | ||
isDevelopingAddon() { | ||
return true; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* eslint no-console: "off" */ | ||
/* eslint-env node */ | ||
'use strict'; | ||
const babel = require('@babel/core'); | ||
const read = require('fs').readFileSync; | ||
const path = require('path'); | ||
const vm = require('vm'); | ||
const color = require('chalk'); | ||
|
||
const out = function(prefix, step, desc) { | ||
if (!Array.isArray(step)) { | ||
step = [step]; | ||
} | ||
step.forEach(function(item) { | ||
const str = | ||
prefix + | ||
item.replace('\n', ' | ').replace(/\$\w+/g, function(match) { | ||
return color.cyan(match); | ||
}); | ||
console.log(color.green(str)); | ||
}); | ||
}; | ||
const library = { | ||
given: function(step, cb, desc) { | ||
out('Given ', step, desc); | ||
return this; | ||
}, | ||
desc: function(desc) { | ||
console.log(color.yellow(`- ${desc.trim()}`)); | ||
}, | ||
section: function() { | ||
console.log(color.yellow(`##`)); | ||
}, | ||
then: function(step, cb, desc) { | ||
out('Then ', step, desc); | ||
return this; | ||
}, | ||
when: function(step, cb, desc) { | ||
out('When ', step, desc); | ||
return this; | ||
}, | ||
}; | ||
const exec = function(filename) { | ||
const js = read(filename); | ||
const code = babel.transform(js.toString(), { | ||
filename: filename, | ||
presets: [require('babel-preset-env')], | ||
}).code; | ||
const exports = {}; | ||
vm.runInNewContext( | ||
code, | ||
{ | ||
exports: exports, | ||
require: function(str) { | ||
return exec(path.resolve(`${process.cwd()}/tests`, `${str}.js`)).default; | ||
}, | ||
}, | ||
{ | ||
filename: filename, | ||
} | ||
); | ||
return exports; | ||
}; | ||
|
||
module.exports = function(filename) { | ||
exec(filename).default(function() {}, library, {}, {}, {}, function() {}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "commands", | ||
"keywords": [ | ||
"ember-addon" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,83 @@ | ||
/* eslint no-console: "off" */ | ||
import Inflector from 'ember-inflector'; | ||
import utils from '@ember/test-helpers'; | ||
import getDictionary from '@hashicorp/ember-cli-api-double/dictionary'; | ||
|
||
import yadda from 'consul-ui/tests/helpers/yadda'; | ||
import pages from 'consul-ui/tests/pages'; | ||
import api from 'consul-ui/tests/helpers/api'; | ||
|
||
import steps from 'consul-ui/tests/steps'; | ||
export default steps; | ||
|
||
const pluralize = function(str) { | ||
return Inflector.inflector.pluralize(str); | ||
}; | ||
export default function(assert) { | ||
const library = yadda.localisation.English.library( | ||
getDictionary(function(model, cb) { | ||
switch (model) { | ||
case 'datacenter': | ||
case 'datacenters': | ||
case 'dcs': | ||
model = 'dc'; | ||
break; | ||
case 'services': | ||
model = 'service'; | ||
break; | ||
case 'nodes': | ||
model = 'node'; | ||
break; | ||
case 'kvs': | ||
model = 'kv'; | ||
break; | ||
case 'acls': | ||
model = 'acl'; | ||
break; | ||
case 'sessions': | ||
model = 'session'; | ||
break; | ||
case 'intentions': | ||
model = 'intention'; | ||
break; | ||
} | ||
cb(null, model); | ||
}, yadda) | ||
); | ||
const create = function(number, name, value) { | ||
// don't return a promise here as | ||
// I don't need it to wait | ||
api.server.createList(name, number, value); | ||
}; | ||
const respondWith = function(url, data) { | ||
api.server.respondWith(url.split('?')[0], data); | ||
}; | ||
const setCookie = function(key, value) { | ||
api.server.setCookie(key, value); | ||
}; | ||
const getLastNthRequest = function(arr) { | ||
return function(n, method) { | ||
let requests = arr.slice(0).reverse(); | ||
if (method) { | ||
requests = requests.filter(function(item) { | ||
return item.method === method; | ||
}); | ||
} | ||
if (n == null) { | ||
return requests; | ||
} | ||
return requests[n]; | ||
}; | ||
}; | ||
return steps(assert, library, pages, { | ||
pluralize: pluralize, | ||
triggerKeyEvent: utils.triggerKeyEvent, | ||
currentURL: utils.currentURL, | ||
click: utils.click, | ||
fillIn: utils.fillIn, | ||
find: utils.find, | ||
lastNthRequest: getLastNthRequest(api.server.history), | ||
respondWith: respondWith, | ||
create: create, | ||
set: setCookie, | ||
}); | ||
} |
Oops, something went wrong.