1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix: support mts, cjs & cts files for deno test & deno fmt (#13274)

This commit is contained in:
Leo Kettmeir 2022-01-05 00:46:34 +01:00 committed by GitHub
parent 22d140ffb1
commit 80bf2828c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -130,7 +130,10 @@ pub fn resolve_from_cwd(path: &Path) -> Result<PathBuf, AnyError> {
/// Checks if the path has extension Deno supports.
pub fn is_supported_ext(path: &Path) -> bool {
if let Some(ext) = get_extension(path) {
matches!(ext.as_str(), "ts" | "tsx" | "js" | "jsx" | "mjs")
matches!(
ext.as_str(),
"ts" | "tsx" | "js" | "jsx" | "mjs" | "mts" | "cjs" | "cts"
)
} else {
false
}
@ -147,6 +150,9 @@ pub fn is_supported_ext_fmt(path: &Path) -> bool {
| "js"
| "jsx"
| "mjs"
| "mts"
| "cjs"
| "cts"
| "json"
| "jsonc"
| "md"
@ -163,26 +169,12 @@ pub fn is_supported_ext_fmt(path: &Path) -> bool {
/// Checks if the path has a basename and extension Deno supports for tests.
pub fn is_supported_test_path(path: &Path) -> bool {
use std::path::Component;
if let Some(Component::Normal(basename_os_str)) =
path.components().next_back()
{
let basename = basename_os_str.to_string_lossy();
basename.ends_with("_test.ts")
|| basename.ends_with("_test.tsx")
|| basename.ends_with("_test.js")
|| basename.ends_with("_test.mjs")
|| basename.ends_with("_test.jsx")
|| basename.ends_with(".test.ts")
|| basename.ends_with(".test.tsx")
|| basename.ends_with(".test.js")
|| basename.ends_with(".test.mjs")
|| basename.ends_with(".test.jsx")
|| basename == "test.ts"
|| basename == "test.tsx"
|| basename == "test.js"
|| basename == "test.mjs"
|| basename == "test.jsx"
if let Some(name) = path.file_stem() {
let basename = name.to_string_lossy();
(basename.ends_with("_test")
|| basename.ends_with(".test")
|| basename == "test")
&& is_supported_ext(path)
} else {
false
}
@ -198,6 +190,9 @@ pub fn is_supported_test_ext(path: &Path) -> bool {
| "js"
| "jsx"
| "mjs"
| "mts"
| "cjs"
| "cts"
| "md"
| "mkd"
| "mkdn"
@ -443,6 +438,9 @@ mod tests {
assert!(is_supported_ext(Path::new("foo.JS")));
assert!(is_supported_ext(Path::new("foo.JSX")));
assert!(is_supported_ext(Path::new("foo.mjs")));
assert!(is_supported_ext(Path::new("foo.mts")));
assert!(is_supported_ext(Path::new("foo.cjs")));
assert!(is_supported_ext(Path::new("foo.cts")));
assert!(!is_supported_ext(Path::new("foo.mjsx")));
}
@ -466,6 +464,9 @@ mod tests {
assert!(is_supported_ext_fmt(Path::new("foo.JS")));
assert!(is_supported_ext_fmt(Path::new("foo.JSX")));
assert!(is_supported_ext_fmt(Path::new("foo.mjs")));
assert!(is_supported_ext_fmt(Path::new("foo.mts")));
assert!(is_supported_ext_fmt(Path::new("foo.cjs")));
assert!(is_supported_ext_fmt(Path::new("foo.cts")));
assert!(!is_supported_ext_fmt(Path::new("foo.mjsx")));
assert!(is_supported_ext_fmt(Path::new("foo.jsonc")));
assert!(is_supported_ext_fmt(Path::new("foo.JSONC")));
@ -493,6 +494,9 @@ mod tests {
assert!(is_supported_test_ext(Path::new("foo.JS")));
assert!(is_supported_test_ext(Path::new("foo.JSX")));
assert!(is_supported_test_ext(Path::new("foo.mjs")));
assert!(is_supported_test_ext(Path::new("foo.mts")));
assert!(is_supported_test_ext(Path::new("foo.cjs")));
assert!(is_supported_test_ext(Path::new("foo.cts")));
assert!(!is_supported_test_ext(Path::new("foo.mjsx")));
assert!(!is_supported_test_ext(Path::new("foo.jsonc")));
assert!(!is_supported_test_ext(Path::new("foo.JSONC")));