summaryrefslogtreecommitdiff
path: root/tests/integration/bench_tests.rs
blob: d588f5b43797b4b316bde855db65f544732f9bfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

use deno_core::serde_json::json;
use deno_core::url::Url;
use test_util as util;
use util::assert_contains;
use util::assert_not_contains;
use util::TestContext;
use util::TestContextBuilder;

#[test]
fn recursive_permissions_pledge() {
  let context = TestContext::default();
  let output = context
    .new_command()
    .args("bench bench/recursive_permissions_pledge.js")
    .run();
  output.assert_exit_code(1);
  assert_contains!(
    output.combined_output(),
    "pledge test permissions called before restoring previous pledge"
  );
}

#[test]
fn file_protocol() {
  let file_url =
    Url::from_file_path(util::testdata_path().join("bench/file_protocol.ts"))
      .unwrap()
      .to_string();
  let context = TestContext::default();
  context
    .new_command()
    .args(format!("bench bench/file_protocol.ts {file_url}"))
    .run()
    .assert_matches_file("bench/file_protocol.out");
}

#[test]
fn conditionally_loads_type_graph() {
  let context = TestContext::default();
  let output = context
    .new_command()
    .args("bench --reload -L debug run/type_directives_js_main.js")
    .run();
  output.assert_matches_text("[WILDCARD] - FileFetcher::fetch_no_follow_with_options - specifier: file:///[WILDCARD]/subdir/type_reference.d.ts[WILDCARD]");
  let output = context
    .new_command()
    .args("bench --reload -L debug --no-check run/type_directives_js_main.js")
    .run();
  assert_not_contains!(output.combined_output(), "type_reference.d.ts");
}

#[test]
fn opt_out_top_level_exclude_via_bench_unexclude() {
  let context = TestContextBuilder::new().use_temp_cwd().build();
  let temp_dir = context.temp_dir().path();
  temp_dir.join("deno.json").write_json(&json!({
    "bench": {
      "exclude": [ "!excluded.bench.ts" ]
    },
    "exclude": [ "excluded.bench.ts", "actually_excluded.bench.ts" ]
  }));

  temp_dir
    .join("main.bench.ts")
    .write("Deno.bench('test1', () => {});");
  temp_dir
    .join("excluded.bench.ts")
    .write("Deno.bench('test2', () => {});");
  temp_dir
    .join("actually_excluded.bench.ts")
    .write("Deno.bench('test3', () => {});");

  let output = context.new_command().arg("bench").run();
  output.assert_exit_code(0);
  let output = output.combined_output();
  assert_contains!(output, "main.bench.ts");
  assert_contains!(output, "excluded.bench.ts");
  assert_not_contains!(output, "actually_excluded.bench.ts");
}