Skip to content

Commit c981340

Browse files
committed
Improve compatibility with REST YAML test format
1 parent fde2e92 commit c981340

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

test/integration/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const getAllFiles = dir => {
5151
const name = join(dir, file)
5252
if (statSync(name).isDirectory()) {
5353
return [...files, ...getAllFiles(name)]
54-
} else if (!name.endsWith('.yaml') && !name.endsWith('.yml')) {
54+
} else if (!name.includes(`${sep}tests${sep}`) && (!name.endsWith('.yaml') || !name.endsWith('.yml'))) {
5555
return files
5656
} else {
5757
return [...files, name]
@@ -91,7 +91,7 @@ async function start ({ client }) {
9191
}
9292
const folders = getAllFiles(yamlFolder)
9393
.reduce((arr, file) => {
94-
const path = file.slice(file.indexOf('/tests'), file.lastIndexOf('/'))
94+
const path = file.slice(file.lastIndexOf(`${sep}tests`), file.lastIndexOf(sep))
9595
let inserted = false
9696
for (let i = 0; i < arr.length; i++) {
9797
if (arr[i][0].includes(path)) {
@@ -107,7 +107,7 @@ async function start ({ client }) {
107107
const totalTime = now()
108108
for (const folder of folders) {
109109
// pretty name
110-
const apiName = folder[0].split(`${sep}tests${sep}`)[1]
110+
const apiName = folder[0].split(`${sep}tests${sep}`)[1].split(sep)[0]
111111

112112
log('Testing ' + apiName)
113113
const apiTime = now()

test/integration/test-runner.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,10 @@ function build (opts = {}) {
420420
const key = Object.keys(action.match)[0]
421421
match(
422422
// in some cases, the yaml refers to the body with an empty string
423-
key === '$body' || key === ''
423+
key.split('.')[0] === '$body' || key === ''
424424
? response
425425
: delve(response, fillStashedValues(key)),
426-
key === '$body'
426+
key.split('.')[0] === '$body'
427427
? action.match[key]
428428
: fillStashedValues(action.match)[key],
429429
action.match
@@ -544,6 +544,8 @@ function match (val1, val2, action) {
544544
// 'm' adds the support for multiline regex
545545
assert.match(val1, new RegExp(regStr, 'm'), `should match pattern provided: ${val2}, but got: ${val1}`)
546546
// everything else
547+
} else if (typeof val1 === 'string' && typeof val2 === 'string') {
548+
assert.include(val1, val2, `should match pattern provided: ${val2}, but got: ${val1}`)
547549
} else {
548550
assert.equal(val1, val2, `should be equal: ${val1} - ${val2}, action: ${JSON.stringify(action)}`)
549551
}
@@ -640,6 +642,10 @@ function length (val, len) {
640642
*/
641643
function parseDo (action) {
642644
action = JSON.parse(JSON.stringify(action))
645+
646+
if (typeof action === 'string') action = {[action]: {}}
647+
if (Array.isArray(action)) action = action[0]
648+
643649
return Object.keys(action).reduce((acc, val) => {
644650
switch (val) {
645651
case 'catch':

0 commit comments

Comments
 (0)