2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-12-13 05:00:45 -05:00
|
|
|
|
2024-01-08 18:51:49 -05:00
|
|
|
use deno_core::serde_json::json;
|
|
|
|
use test_util::assert_contains;
|
|
|
|
use test_util::assert_not_contains;
|
2024-02-06 21:06:34 -05:00
|
|
|
use test_util::env_vars_for_jsr_tests;
|
2024-01-24 16:59:18 -05:00
|
|
|
use test_util::env_vars_for_npm_tests;
|
2024-02-12 19:13:14 -05:00
|
|
|
use test_util::itest;
|
2024-01-08 18:51:49 -05:00
|
|
|
use test_util::TestContextBuilder;
|
|
|
|
|
2023-12-13 05:00:45 -05:00
|
|
|
itest!(no_token {
|
2024-01-10 17:40:30 -05:00
|
|
|
args: "publish",
|
|
|
|
cwd: Some("publish/missing_deno_json"),
|
2023-12-13 05:00:45 -05:00
|
|
|
output: "publish/no_token.out",
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(missing_deno_json {
|
2024-01-10 17:40:30 -05:00
|
|
|
args: "publish --token 'sadfasdf'",
|
2023-12-13 05:00:45 -05:00
|
|
|
output: "publish/missing_deno_json.out",
|
2024-01-10 17:40:30 -05:00
|
|
|
cwd: Some("publish/missing_deno_json"),
|
2023-12-13 05:00:45 -05:00
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
2024-02-19 10:28:41 -05:00
|
|
|
itest!(has_slow_types {
|
2024-01-10 17:40:30 -05:00
|
|
|
args: "publish --token 'sadfasdf'",
|
2024-02-19 10:28:41 -05:00
|
|
|
output: "publish/has_slow_types.out",
|
|
|
|
cwd: Some("publish/has_slow_types"),
|
2024-01-10 17:40:30 -05:00
|
|
|
exit_code: 1,
|
2024-01-24 16:24:52 -05:00
|
|
|
});
|
|
|
|
|
2024-02-19 10:28:41 -05:00
|
|
|
itest!(allow_slow_types {
|
|
|
|
args: "publish --allow-slow-types --token 'sadfasdf'",
|
|
|
|
output: "publish/allow_slow_types.out",
|
|
|
|
cwd: Some("publish/has_slow_types"),
|
2024-02-06 21:06:34 -05:00
|
|
|
envs: env_vars_for_jsr_tests(),
|
|
|
|
http_server: true,
|
|
|
|
exit_code: 0,
|
2024-01-31 10:10:31 -05:00
|
|
|
});
|
|
|
|
|
2024-01-24 16:24:52 -05:00
|
|
|
itest!(invalid_path {
|
|
|
|
args: "publish --token 'sadfasdf'",
|
|
|
|
output: "publish/invalid_path.out",
|
|
|
|
cwd: Some("publish/invalid_path"),
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(symlink {
|
|
|
|
args: "publish --token 'sadfasdf' --dry-run",
|
|
|
|
output: "publish/symlink.out",
|
|
|
|
cwd: Some("publish/symlink"),
|
|
|
|
exit_code: 0,
|
2024-01-10 17:40:30 -05:00
|
|
|
});
|
|
|
|
|
2024-01-24 16:59:18 -05:00
|
|
|
itest!(invalid_import {
|
|
|
|
args: "publish --token 'sadfasdf' --dry-run",
|
|
|
|
output: "publish/invalid_import.out",
|
|
|
|
cwd: Some("publish/invalid_import"),
|
|
|
|
envs: env_vars_for_npm_tests(),
|
|
|
|
exit_code: 1,
|
|
|
|
http_server: true,
|
|
|
|
});
|
|
|
|
|
2024-02-06 15:57:10 -05:00
|
|
|
#[test]
|
|
|
|
fn publish_non_exported_files_using_import_map() {
|
|
|
|
let context = publish_context_builder().build();
|
|
|
|
let temp_dir = context.temp_dir().path();
|
|
|
|
temp_dir.join("deno.json").write_json(&json!({
|
|
|
|
"name": "@foo/bar",
|
|
|
|
"version": "1.0.0",
|
|
|
|
"exports": "./mod.ts",
|
|
|
|
"imports": {
|
|
|
|
"@denotest/add": "jsr:@denotest/add@1"
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
// file not in the graph
|
|
|
|
let other_ts = temp_dir.join("_other.ts");
|
|
|
|
other_ts
|
|
|
|
.write("import { add } from '@denotest/add'; console.log(add(1, 3));");
|
|
|
|
let mod_ts = temp_dir.join("mod.ts");
|
|
|
|
mod_ts.write("import { add } from '@denotest/add'; console.log(add(1, 2));");
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args("publish --log-level=debug --token 'sadfasdf'")
|
|
|
|
.run();
|
2024-02-19 10:28:41 -05:00
|
|
|
output.assert_exit_code(0);
|
2024-02-06 15:57:10 -05:00
|
|
|
let lines = output.combined_output().split('\n').collect::<Vec<_>>();
|
2024-02-19 10:28:41 -05:00
|
|
|
eprintln!("{}", output.combined_output());
|
2024-02-06 15:57:10 -05:00
|
|
|
assert!(lines
|
|
|
|
.iter()
|
|
|
|
.any(|l| l.contains("Unfurling") && l.ends_with("mod.ts")));
|
|
|
|
assert!(lines
|
|
|
|
.iter()
|
|
|
|
.any(|l| l.contains("Unfurling") && l.ends_with("other.ts")));
|
|
|
|
}
|
|
|
|
|
2024-02-06 19:21:26 -05:00
|
|
|
#[test]
|
|
|
|
fn publish_warning_not_in_graph() {
|
|
|
|
let context = publish_context_builder().build();
|
|
|
|
let temp_dir = context.temp_dir().path();
|
|
|
|
temp_dir.join("deno.json").write_json(&json!({
|
|
|
|
"name": "@foo/bar",
|
|
|
|
"version": "1.0.0",
|
|
|
|
"exports": "./mod.ts",
|
|
|
|
}));
|
|
|
|
// file not in the graph that uses a non-analyzable dynamic import (cause a diagnostic)
|
|
|
|
let other_ts = temp_dir.join("_other.ts");
|
|
|
|
other_ts
|
|
|
|
.write("const nonAnalyzable = './_other.ts'; await import(nonAnalyzable);");
|
|
|
|
let mod_ts = temp_dir.join("mod.ts");
|
|
|
|
mod_ts.write(
|
|
|
|
"export function test(a: number, b: number): number { return a + b; }",
|
|
|
|
);
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args("publish --token 'sadfasdf'")
|
|
|
|
.run()
|
|
|
|
.assert_matches_text(
|
|
|
|
"[WILDCARD]unable to analyze dynamic import[WILDCARD]",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-01-10 17:40:30 -05:00
|
|
|
itest!(javascript_missing_decl_file {
|
|
|
|
args: "publish --token 'sadfasdf'",
|
|
|
|
output: "publish/javascript_missing_decl_file.out",
|
|
|
|
cwd: Some("publish/javascript_missing_decl_file"),
|
2024-02-06 21:06:34 -05:00
|
|
|
envs: env_vars_for_jsr_tests(),
|
2024-01-10 17:40:30 -05:00
|
|
|
exit_code: 0,
|
2024-01-12 17:59:27 -05:00
|
|
|
http_server: true,
|
2024-01-10 17:40:30 -05:00
|
|
|
});
|
|
|
|
|
2024-01-24 08:49:33 -05:00
|
|
|
itest!(unanalyzable_dynamic_import {
|
|
|
|
args: "publish --token 'sadfasdf'",
|
|
|
|
output: "publish/unanalyzable_dynamic_import.out",
|
|
|
|
cwd: Some("publish/unanalyzable_dynamic_import"),
|
2024-02-06 21:06:34 -05:00
|
|
|
envs: env_vars_for_jsr_tests(),
|
2024-01-24 08:49:33 -05:00
|
|
|
exit_code: 0,
|
|
|
|
http_server: true,
|
|
|
|
});
|
|
|
|
|
2024-01-10 17:40:30 -05:00
|
|
|
itest!(javascript_decl_file {
|
|
|
|
args: "publish --token 'sadfasdf'",
|
|
|
|
output: "publish/javascript_decl_file.out",
|
|
|
|
cwd: Some("publish/javascript_decl_file"),
|
2024-02-06 21:06:34 -05:00
|
|
|
envs: env_vars_for_jsr_tests(),
|
2024-01-12 17:59:27 -05:00
|
|
|
http_server: true,
|
2024-01-10 17:40:30 -05:00
|
|
|
exit_code: 0,
|
|
|
|
});
|
|
|
|
|
2023-12-13 05:00:45 -05:00
|
|
|
itest!(successful {
|
2024-01-10 17:40:30 -05:00
|
|
|
args: "publish --token 'sadfasdf'",
|
2023-12-13 05:00:45 -05:00
|
|
|
output: "publish/successful.out",
|
2024-01-10 17:40:30 -05:00
|
|
|
cwd: Some("publish/successful"),
|
2024-02-06 21:06:34 -05:00
|
|
|
envs: env_vars_for_jsr_tests(),
|
2024-01-10 17:40:30 -05:00
|
|
|
http_server: true,
|
2024-01-15 10:07:57 -05:00
|
|
|
});
|
|
|
|
|
2024-02-21 08:35:25 -05:00
|
|
|
itest!(no_check {
|
|
|
|
args: "publish --token 'sadfasdf' --no-check",
|
|
|
|
// still type checks the slow types output though
|
|
|
|
output: "publish/successful_no_check.out",
|
|
|
|
cwd: Some("publish/successful"),
|
|
|
|
envs: env_vars_for_jsr_tests(),
|
|
|
|
http_server: true,
|
|
|
|
});
|
|
|
|
|
2024-01-31 23:18:44 -05:00
|
|
|
itest!(node_specifier {
|
|
|
|
args: "publish --token 'sadfasdf'",
|
|
|
|
output: "publish/node_specifier.out",
|
|
|
|
cwd: Some("publish/node_specifier"),
|
2024-02-06 21:06:34 -05:00
|
|
|
envs: env_vars_for_jsr_tests()
|
2024-01-31 23:18:44 -05:00
|
|
|
.into_iter()
|
|
|
|
.chain(env_vars_for_npm_tests().into_iter())
|
|
|
|
.collect(),
|
|
|
|
http_server: true,
|
|
|
|
});
|
|
|
|
|
2024-01-15 10:07:57 -05:00
|
|
|
itest!(config_file_jsonc {
|
|
|
|
args: "publish --token 'sadfasdf'",
|
|
|
|
output: "publish/deno_jsonc.out",
|
|
|
|
cwd: Some("publish/deno_jsonc"),
|
2024-02-06 21:06:34 -05:00
|
|
|
envs: env_vars_for_jsr_tests(),
|
2024-01-15 10:07:57 -05:00
|
|
|
http_server: true,
|
2024-01-10 17:40:30 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
itest!(workspace_all {
|
2024-01-14 16:58:06 -05:00
|
|
|
args: "publish --token 'sadfasdf'",
|
2024-01-10 17:40:30 -05:00
|
|
|
output: "publish/workspace.out",
|
|
|
|
cwd: Some("publish/workspace"),
|
2024-02-06 21:06:34 -05:00
|
|
|
envs: env_vars_for_jsr_tests(),
|
2024-01-10 17:40:30 -05:00
|
|
|
http_server: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(workspace_individual {
|
2024-01-14 16:58:06 -05:00
|
|
|
args: "publish --token 'sadfasdf'",
|
2024-01-10 17:40:30 -05:00
|
|
|
output: "publish/workspace_individual.out",
|
|
|
|
cwd: Some("publish/workspace/bar"),
|
2024-02-06 21:06:34 -05:00
|
|
|
envs: env_vars_for_jsr_tests(),
|
2023-12-13 05:00:45 -05:00
|
|
|
http_server: true,
|
|
|
|
});
|
2024-01-08 18:51:49 -05:00
|
|
|
|
2024-01-11 16:17:03 -05:00
|
|
|
itest!(dry_run {
|
|
|
|
args: "publish --token 'sadfasdf' --dry-run",
|
|
|
|
cwd: Some("publish/successful"),
|
|
|
|
output: "publish/dry_run.out",
|
2024-02-06 21:06:34 -05:00
|
|
|
envs: env_vars_for_jsr_tests(),
|
2024-01-11 16:17:03 -05:00
|
|
|
http_server: true,
|
2024-02-14 12:13:07 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
itest!(config_flag {
|
|
|
|
args: "publish --token 'sadfasdf' --config=successful/deno.json",
|
|
|
|
output: "publish/successful.out",
|
|
|
|
cwd: Some("publish"),
|
|
|
|
envs: env_vars_for_jsr_tests(),
|
|
|
|
http_server: true,
|
2024-01-11 16:17:03 -05:00
|
|
|
});
|
|
|
|
|
2024-02-22 21:26:34 -05:00
|
|
|
#[test]
|
|
|
|
fn ignores_gitignore() {
|
|
|
|
let context = publish_context_builder().build();
|
|
|
|
let temp_dir = context.temp_dir().path();
|
|
|
|
temp_dir.join("deno.json").write_json(&json!({
|
|
|
|
"name": "@foo/bar",
|
|
|
|
"version": "1.0.0",
|
|
|
|
"exports": "./main.ts"
|
|
|
|
}));
|
|
|
|
|
|
|
|
temp_dir.join("main.ts").write("import './sub_dir/b.ts';");
|
|
|
|
|
|
|
|
let gitignore = temp_dir.join(".gitignore");
|
|
|
|
gitignore.write("ignored.ts\nsub_dir/ignored.wasm");
|
|
|
|
|
|
|
|
let sub_dir = temp_dir.join("sub_dir");
|
|
|
|
sub_dir.create_dir_all();
|
|
|
|
sub_dir.join("ignored.wasm").write("");
|
|
|
|
sub_dir.join("b.ts").write("export default {}");
|
|
|
|
|
|
|
|
temp_dir.join("ignored.ts").write("");
|
|
|
|
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.arg("publish")
|
|
|
|
.arg("--dry-run")
|
|
|
|
.arg("--token")
|
|
|
|
.arg("sadfasdf")
|
|
|
|
.run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
let output = output.combined_output();
|
|
|
|
assert_contains!(output, "b.ts");
|
|
|
|
assert_contains!(output, "main.ts");
|
|
|
|
assert_not_contains!(output, "ignored.ts");
|
|
|
|
assert_not_contains!(output, "ignored.wasm");
|
|
|
|
}
|
|
|
|
|
2024-01-08 18:51:49 -05:00
|
|
|
#[test]
|
|
|
|
fn ignores_directories() {
|
|
|
|
let context = publish_context_builder().build();
|
|
|
|
let temp_dir = context.temp_dir().path();
|
|
|
|
temp_dir.join("deno.json").write_json(&json!({
|
|
|
|
"name": "@foo/bar",
|
|
|
|
"version": "1.0.0",
|
|
|
|
"exclude": [ "ignore" ],
|
2024-01-24 15:30:08 -05:00
|
|
|
"publish": {
|
|
|
|
"exclude": [ "ignore2" ]
|
|
|
|
},
|
2024-01-10 17:40:30 -05:00
|
|
|
"exports": "./main_included.ts"
|
2024-01-08 18:51:49 -05:00
|
|
|
}));
|
|
|
|
|
|
|
|
let ignored_dirs = vec![
|
|
|
|
temp_dir.join(".git"),
|
|
|
|
temp_dir.join("node_modules"),
|
|
|
|
temp_dir.join("ignore"),
|
2024-01-24 15:30:08 -05:00
|
|
|
temp_dir.join("ignore2"),
|
2024-01-08 18:51:49 -05:00
|
|
|
];
|
|
|
|
for ignored_dir in ignored_dirs {
|
|
|
|
ignored_dir.create_dir_all();
|
|
|
|
ignored_dir.join("ignored.ts").write("");
|
|
|
|
}
|
|
|
|
|
|
|
|
let sub_dir = temp_dir.join("sub_dir");
|
|
|
|
sub_dir.create_dir_all();
|
|
|
|
sub_dir.join("sub_included.ts").write("");
|
|
|
|
|
|
|
|
temp_dir.join("main_included.ts").write("");
|
|
|
|
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.arg("publish")
|
|
|
|
.arg("--log-level=debug")
|
|
|
|
.arg("--token")
|
|
|
|
.arg("sadfasdf")
|
|
|
|
.run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
let output = output.combined_output();
|
|
|
|
assert_contains!(output, "sub_included.ts");
|
|
|
|
assert_contains!(output, "main_included.ts");
|
|
|
|
assert_not_contains!(output, "ignored.ts");
|
|
|
|
}
|
|
|
|
|
2024-02-22 21:26:34 -05:00
|
|
|
#[test]
|
|
|
|
fn includes_directories_with_gitignore() {
|
|
|
|
let context = publish_context_builder().build();
|
|
|
|
let temp_dir = context.temp_dir().path();
|
|
|
|
temp_dir.join("deno.json").write_json(&json!({
|
|
|
|
"name": "@foo/bar",
|
|
|
|
"version": "1.0.0",
|
|
|
|
"exports": "./main.ts",
|
|
|
|
"publish": {
|
|
|
|
"include": [ "deno.json", "main.ts" ]
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
temp_dir.join(".gitignore").write("main.ts");
|
|
|
|
temp_dir.join("main.ts").write("");
|
|
|
|
temp_dir.join("ignored.ts").write("");
|
|
|
|
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.arg("publish")
|
|
|
|
.arg("--token")
|
|
|
|
.arg("sadfasdf")
|
|
|
|
.run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
let output = output.combined_output();
|
|
|
|
assert_contains!(output, "main.ts");
|
|
|
|
assert_not_contains!(output, "ignored.ts");
|
|
|
|
}
|
|
|
|
|
2024-01-24 15:30:08 -05:00
|
|
|
#[test]
|
|
|
|
fn includes_directories() {
|
|
|
|
let context = publish_context_builder().build();
|
|
|
|
let temp_dir = context.temp_dir().path();
|
|
|
|
temp_dir.join("deno.json").write_json(&json!({
|
|
|
|
"name": "@foo/bar",
|
|
|
|
"version": "1.0.0",
|
|
|
|
"exports": "./main.ts",
|
|
|
|
"publish": {
|
|
|
|
"include": [ "deno.json", "main.ts" ]
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
temp_dir.join("main.ts").write("");
|
|
|
|
temp_dir.join("ignored.ts").write("");
|
|
|
|
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.arg("publish")
|
|
|
|
.arg("--token")
|
|
|
|
.arg("sadfasdf")
|
|
|
|
.run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
let output = output.combined_output();
|
|
|
|
assert_contains!(output, "main.ts");
|
|
|
|
assert_not_contains!(output, "ignored.ts");
|
|
|
|
}
|
|
|
|
|
2024-01-08 18:51:49 -05:00
|
|
|
fn publish_context_builder() -> TestContextBuilder {
|
|
|
|
TestContextBuilder::new()
|
|
|
|
.use_http_server()
|
2024-02-06 21:06:34 -05:00
|
|
|
.envs(env_vars_for_jsr_tests())
|
2024-01-10 17:40:30 -05:00
|
|
|
.use_temp_cwd()
|
2024-01-08 18:51:49 -05:00
|
|
|
}
|