Repository: denoland/deno
File: tests/integration/run_tests.rs (Rust)

Code before:
        "prompt\r\n",
        "┏ ⚠️  Deno requests read access to \"foo\".\r\n",
        "┠─ Requested by `Deno.permissions.request()` API.\r\n",
        "┠─ Learn more at: https://docs.deno.com/go/--allow-read\r\n",
        "┠─ Run again with --allow-read to bypass this prompt.\r\n",
        "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all read permissions)",
      ));
      console.human_delay();
      console.write_line_raw("y");
      console.expect("✅ Granted read access to \"foo\".");
      console.expect("granted");
      console.expect("prompt");
    });
}

itest!(env_file {
  args: "run --env=env --allow-env run/env_file.ts",
  output: "run/env_file.out",
});

itest!(env_file_missing {
  args: "run --env=missing --allow-env run/env_file.ts",
  output: "run/env_file_missing.out",
});

itest!(env_file_multiple {
  args: "run --env=env --env=env_one --env=env_two --allow-env run/multiple_env_file.ts",
  output: "run/multiple_env_file.out",
});

itest!(lock_write_fetch {
  args:
    "run --quiet --allow-import --allow-read --allow-write --allow-env --allow-run run/lock_write_fetch/main.ts",
  output: "run/lock_write_fetch/main.out",
  http_server: true,
  exit_code: 0,
});

#[test]
fn lock_redirects() {
  let context = TestContextBuilder::new()
    .use_temp_cwd()
    .use_http_server()
    .add_npm_env_vars()
    .build();
  let temp_dir = context.temp_dir();
  temp_dir.write("deno.json", "{}"); // cause a lockfile to be created
  temp_dir.write(
    "main.ts",
    "import 'http://localhost:4546/run/001_hello.js';",
  );

Review comment (suggestion):
Could I actually ask you to rewrite these three `env_file_` tests to spec tests? You can see some examples in `tests/specs/run/`

Code after:
        "prompt\r\n",
        "┏ ⚠️  Deno requests read access to \"foo\".\r\n",
        "┠─ Requested by `Deno.permissions.request()` API.\r\n",
        "┠─ Learn more at: https://docs.deno.com/go/--allow-read\r\n",
        "┠─ Run again with --allow-read to bypass this prompt.\r\n",
        "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all read permissions)",
      ));
      console.human_delay();
      console.write_line_raw("y");
      console.expect("✅ Granted read access to \"foo\".");
      console.expect("granted");
      console.expect("prompt");
    });
}

itest!(lock_write_fetch {
  args:
    "run --quiet --allow-import --allow-read --allow-write --allow-env --allow-run run/lock_write_fetch/main.ts",
  output: "run/lock_write_fetch/main.out",
  http_server: true,
  exit_code: 0,
});

#[test]
fn lock_redirects() {
  let context = TestContextBuilder::new()
    .use_temp_cwd()
    .use_http_server()
    .add_npm_env_vars()
    .build();
  let temp_dir = context.temp_dir();
  temp_dir.write("deno.json", "{}"); // cause a lockfile to be created
  temp_dir.write(
    "main.ts",
    "import 'http://localhost:4546/run/001_hello.js';",
  );
  context
    .new_command()
    .args("run --allow-import main.ts")
    .run()
    .skip_output_check();
  let initial_lockfile_text = r#"{
  "version": "4",
  "redirects": {
    "http://localhost:4546/run/001_hello.js": "http://localhost:4545/run/001_hello.js"
  },
  "remote": {
    "http://localhost:4545/run/001_hello.js": "c479db5ea26965387423ca438bb977d0b4788d5901efcef52f69871e4c1048c5"
  }
}
"#;