ui: Reinstate listing of available test steps via CLI (#8614)

* Unignore any bin files underneath the UI folder

* Add previously ignored node exec script

* Rearrange steps file so we can continue to list steps out
pull/8640/head
John Cowen 2020-09-09 09:12:42 +01:00 committed by GitHub
parent 5cc1fefa95
commit d818e892fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 44 deletions

1
ui-v2/.gitignore vendored
View File

@ -1,3 +1,4 @@
!bin
/public/consul-api-double /public/consul-api-double
# See https://help.github.com/ignore-files/ for more about ignoring files. # See https://help.github.com/ignore-files/ for more about ignoring files.

3
ui-v2/lib/commands/bin/list.js Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env node
require('../lib/list.js')(`${process.cwd()}/tests/steps.js`);

View File

@ -40,11 +40,12 @@ const library = {
return this; return this;
}, },
}; };
const root = process.cwd();
const exec = function(filename) { const exec = function(filename) {
const js = read(filename); const js = read(filename);
const code = babel.transform(js.toString(), { const code = babel.transform(js.toString(), {
filename: filename, filename: filename,
presets: [require('babel-preset-env')], presets: ['@babel/preset-env'],
}).code; }).code;
const exports = {}; const exports = {};
vm.runInNewContext( vm.runInNewContext(
@ -52,7 +53,7 @@ const exec = function(filename) {
{ {
exports: exports, exports: exports,
require: function(str) { require: function(str) {
return exec(path.resolve(`${process.cwd()}/tests`, `${str}.js`)).default; return exec(path.resolve(`${root}/tests`, `${str}.js`)).default;
}, },
}, },
{ {
@ -63,5 +64,6 @@ const exec = function(filename) {
}; };
module.exports = function(filename) { module.exports = function(filename) {
exec(filename).default(function() {}, library, {}, {}, {}, function() {}); const assert = () => {};
exec(filename).default({ assert, library });
}; };

View File

@ -1,5 +1,19 @@
import steps from 'consul-ui/tests/steps'; import steps from 'consul-ui/tests/steps';
import pages from 'consul-ui/tests/pages';
import Inflector from 'ember-inflector';
import utils from '@ember/test-helpers';
import $ from '-jquery';
import api from 'consul-ui/tests/helpers/api';
export default function({ assert, library }) { export default function({ assert, library }) {
return steps(assert, library); return steps({
assert,
library,
pages,
utils,
api,
Inflector,
$,
});
} }

View File

@ -1,8 +1,6 @@
import pages from 'consul-ui/tests/pages'; // This files export is executed from 2 places:
import Inflector from 'ember-inflector'; // 1. consul-ui/tests/acceptance/steps/steps.js - run during testing
import utils from '@ember/test-helpers'; // 2. consul-ui/lib/commands/lib/list.js - run when listing steps via the CLI
import api from 'consul-ui/tests/helpers/api';
import models from './steps/doubles/model'; import models from './steps/doubles/model';
import http from './steps/doubles/http'; import http from './steps/doubles/http';
@ -18,10 +16,19 @@ import assertForm from './steps/assertions/form';
// const dont = `( don't| shouldn't| can't)?`; // const dont = `( don't| shouldn't| can't)?`;
const pluralize = function(str) { export default function({
assert,
library,
pages = {},
utils = {},
api = {},
Inflector = {},
$ = {},
}) {
const pluralize = function(str) {
return Inflector.inflector.pluralize(str); return Inflector.inflector.pluralize(str);
}; };
const getLastNthRequest = function(getRequests) { const getLastNthRequest = function(getRequests) {
return function(n, method) { return function(n, method) {
let requests = getRequests() let requests = getRequests()
.slice(0) .slice(0)
@ -36,8 +43,8 @@ const getLastNthRequest = function(getRequests) {
} }
return requests[n]; return requests[n];
}; };
}; };
const mb = function(path) { const mb = function(path) {
return function(obj) { return function(obj) {
return ( return (
path.map(function(prop) { path.map(function(prop) {
@ -50,8 +57,7 @@ const mb = function(path) {
}) && obj }) && obj
); );
}; };
}; };
export default function(assert, library) {
const pauseUntil = function(run, message = 'assertion timed out') { const pauseUntil = function(run, message = 'assertion timed out') {
return new Promise(function(r) { return new Promise(function(r) {
let count = 0; let count = 0;
@ -135,7 +141,7 @@ export default function(assert, library) {
debug(library, assert, utils.currentURL); debug(library, assert, utils.currentURL);
assertHttp(library, assert, lastNthRequest); assertHttp(library, assert, lastNthRequest);
assertModel(library, assert, find, getCurrentPage, pauseUntil, pluralize); assertModel(library, assert, find, getCurrentPage, pauseUntil, pluralize);
assertPage(library, assert, find, getCurrentPage); assertPage(library, assert, find, getCurrentPage, $);
assertDom(library, assert, pauseUntil, utils.find, utils.currentURL, clipboard); assertDom(library, assert, pauseUntil, utils.find, utils.currentURL, clipboard);
assertForm(library, assert, find, getCurrentPage); assertForm(library, assert, find, getCurrentPage);

View File

@ -1,5 +1,4 @@
/* eslint no-console: "off" */ /* eslint no-console: "off" */
import $ from '-jquery';
const elementNotFound = 'Element not found'; const elementNotFound = 'Element not found';
// this error comes from our pageObject `find `function // this error comes from our pageObject `find `function
@ -32,7 +31,7 @@ const isExpectedError = function(e) {
); );
}; };
const dont = `( don't| shouldn't| can't)?`; const dont = `( don't| shouldn't| can't)?`;
export default function(scenario, assert, find, currentPage) { export default function(scenario, assert, find, currentPage, $) {
scenario scenario
.then(['I see $num of the $component object'], function(num, component) { .then(['I see $num of the $component object'], function(num, component) {
assert.equal( assert.equal(