Skip to content

Commit

Permalink
merge testrunner example and javascript tests into json.test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Yngwarr committed Feb 23, 2024
1 parent df40ee5 commit 587f6e4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sof-js/tests/1_basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe("basics", () => {
select: [{column: [{name: 'id', path: 'id'}]}],
where: [{path: 'active'}]
},
expect: [{id: 'pt1'}]
expectError: true
})

add_test({
Expand Down
32 changes: 32 additions & 0 deletions sof-js/tests/json.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import fs from 'fs'
import { expect, test, describe } from "bun:test";
import { evaluate } from '../src/index.js'

const testDirectory = '../tests/';
const files = fs.readdirSync(testDirectory);

files.forEach(f => {
const testGroup = JSON.parse(fs.readFileSync(testDirectory + f));
const resources = testGroup.resources;

testGroup.tests.forEach(testCase => {
const view = testCase.view;

describe(f, () => {
if (testCase.expect !== undefined) {
test(testCase.title, () => {
const res = evaluate(view, resources);
expect(res).toEqual(testCase.expect);
});
} else if (testCase.expectError !== undefined) {
test(testCase.title, () => {
expect(() => evaluate(view, resources)).toThrow();

Check failure on line 23 in sof-js/tests/json.test.js

View workflow job for this annotation

GitHub Actions / Test and Deploy Playground

error: expect(received).toThrow()

Received function did not throw at /home/runner/work/sql-on-fhir-v2/sql-on-fhir-v2/sof-js/tests/json.test.js:23:11

Check failure on line 23 in sof-js/tests/json.test.js

View workflow job for this annotation

GitHub Actions / Test and Deploy Playground

error: expect(received).toThrow()

Received function did not throw at /home/runner/work/sql-on-fhir-v2/sql-on-fhir-v2/sof-js/tests/json.test.js:23:11

Check failure on line 23 in sof-js/tests/json.test.js

View workflow job for this annotation

GitHub Actions / Test and Deploy Playground

error: expect(received).toThrow()

Received function did not throw at /home/runner/work/sql-on-fhir-v2/sql-on-fhir-v2/sof-js/tests/json.test.js:23:11

Check failure on line 23 in sof-js/tests/json.test.js

View workflow job for this annotation

GitHub Actions / Test and Deploy Playground

error: expect(received).toThrow()

Received function did not throw at /home/runner/work/sql-on-fhir-v2/sql-on-fhir-v2/sof-js/tests/json.test.js:23:11

Check failure on line 23 in sof-js/tests/json.test.js

View workflow job for this annotation

GitHub Actions / Test and Deploy Playground

error: expect(received).toThrow()

Received function did not throw at /home/runner/work/sql-on-fhir-v2/sql-on-fhir-v2/sof-js/tests/json.test.js:23:11

Check failure on line 23 in sof-js/tests/json.test.js

View workflow job for this annotation

GitHub Actions / Test and Deploy Playground

error: expect(received).toThrow()

Received function did not throw at /home/runner/work/sql-on-fhir-v2/sql-on-fhir-v2/sof-js/tests/json.test.js:23:11
});
} else if (testCase.expectCount !== undefined) {
throw new Error("expectCount is not implemented yet");
} else {
throw new Error(`'${testCase.title}' test has no known expectation`);
}
});
});
});
6 changes: 1 addition & 5 deletions tests/basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,7 @@
}
]
},
"expect": [
{
"id": "pt1"
}
]
"expectError": true
},
{
"title": "where as expr - 1",
Expand Down

0 comments on commit 587f6e4

Please sign in to comment.