Skip to content

Commit

Permalink
[#210] make test files write on error
Browse files Browse the repository at this point in the history
  • Loading branch information
Yngwarr committed Feb 23, 2024
1 parent 2ccb5e2 commit a107fa3
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 16 deletions.
2 changes: 1 addition & 1 deletion sof-js/tests/1_basic.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test , describe, beforeAll, afterAll} from "bun:test";
import { evaluate, get_columns, row_product } from '../src/index.js'
import { start_case, end_case, add_test, debug, run_test, should_fail, add_throwing_test } from './test_helpers.js'
import { start_case, end_case, add_test, debug, should_fail, add_throwing_test } from './test_helpers.js'

test("row_product", () => {
expect(row_product([[{a: 1}, {a: 2}], [{b: 1}, {b: 2}]]))
Expand Down
2 changes: 1 addition & 1 deletion sof-js/tests/2_fhirpath.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test, describe } from "bun:test";
import { evaluate, row_product } from '../src/index.js'
import { start_case, end_case, add_test, run_test, should_fail } from './test_helpers.js'
import { start_case, end_case, add_test, should_fail } from './test_helpers.js'

let l = console.log

Expand Down
2 changes: 1 addition & 1 deletion sof-js/tests/3_foreach.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test, describe } from "bun:test";
import { start_case, end_case, run_test,add_test, debug } from './test_helpers.js'
import { start_case, end_case, add_test, debug } from './test_helpers.js'

let l = console.log

Expand Down
15 changes: 3 additions & 12 deletions sof-js/tests/test_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs from 'fs'


let test_case = null;

export function start_case(name, desc, resources) {
test_case = {
title: name,
Expand All @@ -13,19 +14,10 @@ export function start_case(name, desc, resources) {
}
}

export function run_test(viewdef, result) {
// TODO: dump tests
let res = evaluate( viewdef, test_case.resources)
test_case.tests.push({view: viewdef, expect: result})
expect(res).toEqual(result);

}


export function add_test(opts) {
test(opts.title, () => {
const res = evaluate(opts.view, test_case.resources);
test_case.tests.push(opts);
const res = evaluate(opts.view, test_case.resources);
expect(res).toEqual(opts.expect);
})
}
Expand All @@ -38,10 +30,9 @@ export function add_throwing_test(opts) {
}

export function invalid_view(opts) {
test(opts.title, ()=>{
test(opts.title, () => {
test_case.tests.push(opts)
let errs = errors(opts.view, test_case.resources)
// console.log(errs)
expect((errs || []).length > 0).toEqual(true)
})
}
Expand Down
143 changes: 142 additions & 1 deletion tests/fn_boundary.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,146 @@
"status": "final"
}
],
"tests": []
"tests": [
{
"title": "decimal lowBoundary",
"view": {
"resource": "Observation",
"status": "active",
"select": [
{
"column": [
{
"name": "id",
"path": "id"
},
{
"name": "decimal",
"path": "value.ofType(Quantity).value.lowBoundary()"
}
]
}
]
},
"expect": [
{
"id": "o1",
"decimal": 0.95
},
{
"id": "o2",
"decimal": null
},
{
"id": "o3",
"decimal": null
}
]
},
{
"title": "decimal highBoundary",
"view": {
"resource": "Observation",
"status": "active",
"select": [
{
"column": [
{
"name": "id",
"path": "id"
},
{
"name": "decimal",
"path": "value.ofType(Quantity).value.highBoundary()"
}
]
}
]
},
"expect": [
{
"id": "o1",
"decimal": 1.05
},
{
"id": "o2",
"decimal": null
},
{
"id": "o3",
"decimal": null
}
]
},
{
"title": "datetime lowBoundary",
"view": {
"resource": "Observation",
"status": "active",
"select": [
{
"column": [
{
"name": "id",
"path": "id"
},
{
"name": "datetime",
"path": "value.ofType(DateTime).lowBoundary()"
}
]
}
]
},
"expect": [
{
"id": "o1",
"decimal": null
},
{
"id": "o2",
"decimal": "2010-10-10T00:00:00.000+14:00"
},
{
"id": "o3",
"decimal": null
}
]
},
{
"title": "datetime highBoundary",
"view": {
"resource": "Observation",
"status": "active",
"select": [
{
"column": [
{
"name": "id",
"path": "id"
},
{
"name": "datetime",
"path": "value.ofType(DateTime).highBoundary()"
}
]
}
]
},
"expect": [
{
"id": "o1",
"decimal": null
},
{
"id": "o2",
"decimal": "2010-10-10T23:59:59.999-12:00"
},
{
"id": "o3",
"decimal": null
}
]
}
]
}

0 comments on commit a107fa3

Please sign in to comment.