Skip to content

Commit

Permalink
add js tests to coverage report (#378)
Browse files Browse the repository at this point in the history
* add js tests to coverage report

* fix by review
  • Loading branch information
kxc-wraikny authored Sep 11, 2023
1 parent b694b9a commit cff8443
Show file tree
Hide file tree
Showing 21 changed files with 85 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ _coverage:
rm -rf _coverage
-dune runtest -f --instrument-with bisect_ppx --no-buffer
@(mkdir -p _coverage/ocaml/coverage-files && \
find _build/default | grep -E 'bisect.+[.]coverage$$' | xargs -I{} cp {} _coverage/ocaml/coverage-files)
find _build/default | grep -E 'bisect.+[.]coverage$$' | tee _coverage/ocaml/coverage-files.lst | xargs -I{} cp {} _coverage/ocaml/coverage-files)
@echo "collected coverage files:"
@cat _coverage/ocaml/coverage-files.lst
@(bisect-ppx-report html -o _coverage/ocaml/doc _coverage/ocaml/coverage-files/*)
@echo ">>> OCaml coverage:"
@(bisect-ppx-report summary _coverage/ocaml/coverage-files/*)
Expand Down
16 changes: 16 additions & 0 deletions src/lib_test_common/jsoo_utils/bindoj_test_common_jsoo_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,19 @@ module Alcotest_jsoo_platform : Alcotest_engine.Platform.MAKER = functor (M : Al
end

module Alcotest_jsoo = Alcotest_engine.V1.Cli.Make(Alcotest_jsoo_platform)(FutexnIo)

let coverage_helper_js = object%js
method reset_counters_js =
info "Bisect.Runtime.reset_counters";
Bisect.Runtime.reset_counters();
Jv.undefined
method write_coverage_data_js =
info "Bisect.Runtime.write_coverage_data";
Bisect.Runtime.write_coverage_data();
Jv.undefined
method get_coverage_data_js =
info "Bisect.Runtime.get_coverage_data";
Bisect.Runtime.get_coverage_data ()
>? Jv.of_string
|? Jv.null
end [@@coverage off]
2 changes: 1 addition & 1 deletion src/lib_test_common/jsoo_utils/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(name bindoj_test_common_jsoo_utils)
(libraries
bindoj_apidir_runtime
alcotest fmt fmt.tty js_of_ocaml prr
alcotest fmt fmt.tty js_of_ocaml prr bisect_ppx.runtime
kxclib yojson jsonm)
(preprocess (pps js_of_ocaml-ppx))
(flags (:standard)))
1 change: 1 addition & 0 deletions with_js/apidir-typescript-tests/gen/gen_mock_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ let export_to_js (module Dir : Sample_apidir) =
end
in
Js_of_ocaml.Js.export "bindoj_jsoo_bridge" (object%js
val coverage_helper_js = coverage_helper_js
val server_mock_js = make_server_mock_js (module Bridge_dir)
end)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const mockServer: MockServer = b.server_mock;
const mockClient: clientIntf = createMockClient(invpInfo)(mockServer);

describe("apidir-typescript-tests-sample01", () => {
afterAll(() => {
b.coverage_helper.write_coverage_data();
b.coverage_helper.reset_counters();
});

test("get-any-student", async () => {
const { body: student, status_code } = await mockClient["get-any-student"]();
expect(status_code).toBe(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const mockServer: MockServer = b.server_mock;
const mockClient: clientIntf = createMockClient(invpInfo)(mockServer);

describe("apidir-typescript-tests-sample01-no-mangling", () => {
afterAll(() => {
b.coverage_helper.write_coverage_data();
b.coverage_helper.reset_counters();
});

test("get-any-student", async () => {
const { body: student, status_code } = await mockClient["get-any-student"]();
expect(status_code).toBe(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const createIntList = (nums: number[]): IntListObjtuple => {
};

describe("apidir-typescript-tests-sample02", () => {
afterAll(() => {
b.coverage_helper.write_coverage_data();
b.coverage_helper.reset_counters();
});

test("get-any-int-list", async () => {
const { body, status_code } = await mockClient["get-any-int-list"]();
expect(status_code).toBe(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const mockServer: MockServer = b.server_mock;
const mockClient: clientIntf = createMockClient(invpInfo)(mockServer);

describe("apidir-typescript-tests-sample03", () => {
afterAll(() => {
b.coverage_helper.write_coverage_data();
b.coverage_helper.reset_counters();
});

describe("id-of-person", () => {
test("Anonymous", async () => {
const person: Person = { kind: "anonymous" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const mockServer: MockServer = b.server_mock;
const mockClient: clientIntf = createMockClient(invpInfo)(mockServer);

describe("apidir-typescript-tests-sample04", () => {
afterAll(() => {
b.coverage_helper.write_coverage_data();
b.coverage_helper.reset_counters();
});

const sample_values: NamedJson[] = [
{ name: "position", json: { x: 2, y: -5} },
{ name: "greeting", json: "hello?" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const mockServer: MockServer = b.server_mock;
const mockClient: clientIntf = createMockClient(invpInfo)(mockServer);

describe("apidir-typescript-tests-sample05", () => {
afterAll(() => {
b.coverage_helper.write_coverage_data();
b.coverage_helper.reset_counters();
});

describe("int-of-string", () => {
[
{ value: "", result: null },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const mockServer: MockServer = b.server_mock;
const mockClient: clientIntf = createMockClient(invpInfo)(mockServer);

describe("apidir-typescript-tests-sample06", () => {
afterAll(() => {
b.coverage_helper.write_coverage_data();
b.coverage_helper.reset_counters();
});

const sample_values: XyOpt[] = [
{ },
{ yOpt: 42 },
Expand Down
1 change: 1 addition & 0 deletions with_js/jsoo-gen/gen/jsoo_gen_json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ open Prr

let () =
Js_of_ocaml.Js.export "jsoo_gen_json" (object%js
val coverage_helper_js = coverage_helper_js
val generator_js = object%js
val module_names_js = all |> Jv.(of_list (fst &> of_string)) |> cast
method generate_js name =
Expand Down
1 change: 1 addition & 0 deletions with_js/jsoo-gen/gen/jsoo_gen_ml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ let modules, mapping =

let () =
Js_of_ocaml.Js.export "jsoo_gen_ml" (object%js
val coverage_helper_js = coverage_helper_js
val generator_js = object%js
val module_names_js = modules |> Jv.(of_list of_string) |> cast
method generate_js name gen_type_decl =
Expand Down
1 change: 1 addition & 0 deletions with_js/jsoo-gen/gen/jsoo_gen_schema.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ open Prr

let () =
Js_of_ocaml.Js.export "jsoo_gen_schema" (object%js
val coverage_helper_js = coverage_helper_js
val generator_js = object%js
val module_names_js = all |> Jv.(of_list (fst &> of_string)) |> cast
method generate_js name =
Expand Down
1 change: 1 addition & 0 deletions with_js/jsoo-gen/gen/jsoo_gen_ts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ open Prr

let () =
Js_of_ocaml.Js.export "jsoo_gen_ts" (object%js
val coverage_helper_js = coverage_helper_js
val generator_js = object%js
val module_names_js = all |> Jv.(of_list (fst &> of_string)) |> cast
method generate_js name =
Expand Down
5 changes: 5 additions & 0 deletions with_js/jsoo-gen/tests/jsoo_gen_json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const b = require("../jsoo_gen_json.js").jsoo_gen_json;
const generator = b.generator;

describe("jsoo_gen_json", () => {
afterAll(() => {
b.coverage_helper.write_coverage_data();
b.coverage_helper.reset_counters();
});

const names: string[] = generator.module_names;
for (const name of names) {
test(name, async () => {
Expand Down
5 changes: 5 additions & 0 deletions with_js/jsoo-gen/tests/jsoo_gen_ml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const getFileName = (name: string, gen_type_decl: boolean, kind: "structure" | "
};

describe("jsoo_gen_ml", () => {
afterAll(() => {
b.coverage_helper.write_coverage_data();
b.coverage_helper.reset_counters();
});

const names: string[] = generator.module_names;
names
.flatMap((name) => [
Expand Down
5 changes: 5 additions & 0 deletions with_js/jsoo-gen/tests/jsoo_gen_schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const b = require("../jsoo_gen_schema.js").jsoo_gen_schema;
const generator = b.generator;

describe("jsoo_gen_schema", () => {
afterAll(() => {
b.coverage_helper.write_coverage_data();
b.coverage_helper.reset_counters();
});

const names: string[] = generator.module_names;
for (const name of names) {
test(name, async () => {
Expand Down
5 changes: 5 additions & 0 deletions with_js/jsoo-gen/tests/jsoo_gen_ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const b = require("../jsoo_gen_ts.js").jsoo_gen_ts;
const generator = b.generator;

describe("jsoo_gen_ts", () => {
afterAll(() => {
b.coverage_helper.write_coverage_data();
b.coverage_helper.reset_counters();
});

const names: string[] = generator.module_names;
for (const name of names) {
test(name, async () => {
Expand Down
3 changes: 2 additions & 1 deletion with_js/jsoo-integration-tests/dune
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
alcotest
yojson
kxclib
ojs)
ojs
bisect_ppx.runtime)
(modes js)
(optional)
(preprocess (pps js_of_ocaml-ppx ppx_inline_test))
Expand Down
4 changes: 3 additions & 1 deletion with_js/jsoo-integration-tests/run.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ let create_test_cases name (module Ex : T) filter =
|&> snd

let () =
Bisect.Runtime.reset_counters();
all
|> List.map (fun (name, m) ->
create_test_cases name m
(function | _ -> true))
|> Alcotest.run "with_js.jsoo_integration"
|> Alcotest.run "with_js.jsoo_integration";
Bisect.Runtime.write_coverage_data();

0 comments on commit cff8443

Please sign in to comment.