Skip to content

Commit

Permalink
fix(test): CLI runner sends version, shows errors
Browse files Browse the repository at this point in the history
- Package.json needs to be parsed to JSON after reading it.
- Rejected promise needs to be an error,
so that it can be passed to the mocha done function.
- refactor `runner.xq` to fail on missing parameters and for readability
  • Loading branch information
line-o committed Nov 23, 2019
1 parent 6d11d0c commit c43ce26
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
48 changes: 27 additions & 21 deletions test/mocha/runner.xq
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@ xquery version "3.1";


import module namespace test="http://exist-db.org/xquery/xqsuite"
at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";


declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "json";
declare option output:media-type "application/json";

declare
function local:get-module-uri ($lib as xs:string, $version as xs:string) as xs:string* {
xs:anyURI(
``[xmldb:///db/system/repo/`{$lib}`-`{$version}`/test/`{$lib}`-spec.xqm]``)
};

let $version := request:get-parameter('version', '1.0.0')
let $lib := request:get-parameter('lib', 'xbow')
let $uri := ``[xmldb:///db/system/repo/`{$lib}`-`{$version}`/test/`{$lib}`-spec.xqm]``

return
try {
let $result :=
xs:anyURI($uri)
=> inspect:module-functions()
=> test:suite()

let $json := map {
declare
function local:result-to-map ($result as element()) as map(*) {
map {
"result": map {
"errors": $result//testsuite/@errors => xs:integer(),
"tests": $result//testsuite/@tests => xs:integer(),
Expand All @@ -30,23 +26,33 @@ try {
"failures": $result//testsuite/@failures => xs:integer(),
"pending": $result//testsuite/@pending => xs:integer()
}
}
}
};

declare variable $local:lib := request:get-parameter('lib', ());
declare variable $local:version := request:get-parameter('version', ());

try {
let $result :=
local:get-module-uri($local:lib, $local:version)
=> inspect:module-functions()
=> test:suite()
=> local:result-to-map()

return (
util:log('info', $json),
$json
$result,
util:log('info', $result)
)
}
catch * {
util:log('error', $err:description),
map {
"error": map {
"lib": $lib,
"version": $version,
"uri": $uri,
"lib": $local:lib,
"version": $local:version,
"code": $err:code,
"value": $err:value,
"description": $err:description
}
}
},
util:log('error', $err:description)
}
7 changes: 5 additions & 2 deletions test/mocha/xqSuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const s = require('superagent')

const testRunnerLocalPath = 'test/mocha/runner.xq'

const pkg = fs.readFileSync('package.json')
const pkg = JSON.parse(fs.readFileSync('package.json'))
const testCollection = '/test-' + pkg.name + '-' + pkg.version
const testRunner = testCollection + '/runner.xq'

Expand Down Expand Up @@ -50,7 +50,10 @@ describe('xqSuite', function () {
.send()
})
.then(response => {
if (response.body.error) return Promise.reject(response.body.error)
if (response.body.error) {
return Promise.reject(
Error(response.body.error.description))
}
result = response.body.result
done()
})
Expand Down

0 comments on commit c43ce26

Please sign in to comment.