diff options
Diffstat (limited to 'cli/tests')
24 files changed, 205 insertions, 0 deletions
diff --git a/cli/tests/integration/bench_tests.rs b/cli/tests/integration/bench_tests.rs index 15a86ee9d..5a010ec62 100644 --- a/cli/tests/integration/bench_tests.rs +++ b/cli/tests/integration/bench_tests.rs @@ -2,6 +2,7 @@ use deno_core::url::Url; use test_util as util; +use util::env_vars_for_npm_tests; itest!(overloads { args: "bench bench/overloads.ts", @@ -216,3 +217,13 @@ fn file_protocol() { }) .run(); } + +itest!(package_json_basic { + args: "bench", + output: "package_json/basic/main.bench.out", + envs: env_vars_for_npm_tests(), + http_server: true, + cwd: Some("package_json/basic"), + copy_temp_dir: Some("package_json/basic"), + exit_code: 0, +}); diff --git a/cli/tests/integration/cache_tests.rs b/cli/tests/integration/cache_tests.rs index ae4dc001a..c80f7f5c8 100644 --- a/cli/tests/integration/cache_tests.rs +++ b/cli/tests/integration/cache_tests.rs @@ -1,5 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use test_util::env_vars_for_npm_tests; + itest!(_036_import_map_fetch { args: "cache --quiet --reload --import-map=import_maps/import_map.json import_maps/test.ts", @@ -95,3 +97,13 @@ itest!(json_import { // should not error args: "cache --quiet cache/json_import/main.ts", }); + +itest!(package_json_basic { + args: "cache main.ts", + output: "package_json/basic/main.cache.out", + envs: env_vars_for_npm_tests(), + http_server: true, + cwd: Some("package_json/basic"), + copy_temp_dir: Some("package_json/basic"), + exit_code: 0, +}); diff --git a/cli/tests/integration/check_tests.rs b/cli/tests/integration/check_tests.rs index 66433f81d..021a536c4 100644 --- a/cli/tests/integration/check_tests.rs +++ b/cli/tests/integration/check_tests.rs @@ -3,6 +3,8 @@ use std::process::Command; use std::process::Stdio; use test_util as util; +use util::env_vars_for_npm_tests; +use util::env_vars_for_npm_tests_no_sync_download; use util::TempDir; itest!(_095_check_with_bare_import { @@ -229,3 +231,23 @@ fn ts_no_recheck_on_redirect() { assert!(std::str::from_utf8(&output.stderr).unwrap().is_empty()); } + +itest!(package_json_basic { + args: "check main.ts", + output: "package_json/basic/main.check.out", + envs: env_vars_for_npm_tests(), + http_server: true, + cwd: Some("package_json/basic"), + copy_temp_dir: Some("package_json/basic"), + exit_code: 0, +}); + +itest!(package_json_fail_check { + args: "check --quiet fail_check.ts", + output: "package_json/basic/fail_check.check.out", + envs: env_vars_for_npm_tests_no_sync_download(), + http_server: true, + cwd: Some("package_json/basic"), + copy_temp_dir: Some("package_json/basic"), + exit_code: 1, +}); diff --git a/cli/tests/integration/info_tests.rs b/cli/tests/integration/info_tests.rs index 6c75deea6..704aaa7af 100644 --- a/cli/tests/integration/info_tests.rs +++ b/cli/tests/integration/info_tests.rs @@ -2,6 +2,7 @@ use test_util as util; use test_util::TempDir; +use util::env_vars_for_npm_tests_no_sync_download; #[test] fn info_with_compiled_source() { @@ -127,3 +128,13 @@ itest!(with_config_override { args: "info info/with_config/test.ts --config info/with_config/deno-override.json --import-map info/with_config/import_map.json", output: "info/with_config/with_config.out", }); + +itest!(package_json_basic { + args: "info --quiet main.ts", + output: "package_json/basic/main.info.out", + envs: env_vars_for_npm_tests_no_sync_download(), + http_server: true, + cwd: Some("package_json/basic"), + copy_temp_dir: Some("package_json/basic"), + exit_code: 0, +}); diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs index 54053710e..910936ac3 100644 --- a/cli/tests/integration/npm_tests.rs +++ b/cli/tests/integration/npm_tests.rs @@ -1565,3 +1565,23 @@ itest!(create_require { envs: env_vars_for_npm_tests(), http_server: true, }); + +itest!(node_modules_import_run { + args: "run --quiet main.ts", + output: "npm/node_modules_import/main.out", + envs: env_vars_for_npm_tests(), + http_server: true, + cwd: Some("npm/node_modules_import/"), + copy_temp_dir: Some("npm/node_modules_import/"), + exit_code: 0, +}); + +itest!(node_modules_import_check { + args: "check --quiet main.ts", + output: "npm/node_modules_import/main_check.out", + envs: env_vars_for_npm_tests(), + http_server: true, + cwd: Some("npm/node_modules_import/"), + copy_temp_dir: Some("npm/node_modules_import/"), + exit_code: 1, +}); diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs index efe50ac16..8b318e8e1 100644 --- a/cli/tests/integration/test_tests.rs +++ b/cli/tests/integration/test_tests.rs @@ -2,6 +2,7 @@ use deno_core::url::Url; use test_util as util; +use util::env_vars_for_npm_tests; #[test] fn no_color() { @@ -452,3 +453,13 @@ itest!(parallel_output { output: "test/parallel_output.out", exit_code: 1, }); + +itest!(package_json_basic { + args: "test", + output: "package_json/basic/main.test.out", + envs: env_vars_for_npm_tests(), + http_server: true, + cwd: Some("package_json/basic"), + copy_temp_dir: Some("package_json/basic"), + exit_code: 0, +}); diff --git a/cli/tests/testdata/npm/node_modules_import/main.out b/cli/tests/testdata/npm/node_modules_import/main.out new file mode 100644 index 000000000..51993f072 --- /dev/null +++ b/cli/tests/testdata/npm/node_modules_import/main.out @@ -0,0 +1,2 @@ +2 +2 diff --git a/cli/tests/testdata/npm/node_modules_import/main.ts b/cli/tests/testdata/npm/node_modules_import/main.ts new file mode 100644 index 000000000..ed433ed04 --- /dev/null +++ b/cli/tests/testdata/npm/node_modules_import/main.ts @@ -0,0 +1,13 @@ +import * as myImport1 from "@denotest/esm-basic"; +import * as myImport2 from "./node_modules/@denotest/esm-basic/main.mjs"; + +myImport1.setValue(5); +myImport2.setValue(2); + +// these should both give type errors +const value1: string = myImport1.getValue(); +const value2: string = myImport2.getValue(); + +// these should both be equal because it should be mutating the same module +console.log(value1); +console.log(value2); diff --git a/cli/tests/testdata/npm/node_modules_import/main_check.out b/cli/tests/testdata/npm/node_modules_import/main_check.out new file mode 100644 index 000000000..4442a97ba --- /dev/null +++ b/cli/tests/testdata/npm/node_modules_import/main_check.out @@ -0,0 +1,11 @@ +error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. +const value1: string = myImport1.getValue(); + ~~~~~~ + at file:///[WILDCARD]/npm/node_modules_import/main.ts:8:7 + +TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. +const value2: string = myImport2.getValue(); + ~~~~~~ + at file:///[WILDCARD]/npm/node_modules_import/main.ts:9:7 + +Found 2 errors. diff --git a/cli/tests/testdata/npm/node_modules_import/package.json b/cli/tests/testdata/npm/node_modules_import/package.json new file mode 100644 index 000000000..ed77298e0 --- /dev/null +++ b/cli/tests/testdata/npm/node_modules_import/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "@denotest/esm-basic": "^1" + } +} diff --git a/cli/tests/testdata/npm/registry/@denotest/esm-basic/1.0.0/main.d.mts b/cli/tests/testdata/npm/registry/@denotest/esm-basic/1.0.0/main.d.mts new file mode 100644 index 000000000..fa7814911 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/esm-basic/1.0.0/main.d.mts @@ -0,0 +1,2 @@ +export declare function setValue(val: number): void; +export declare function getValue(): number; diff --git a/cli/tests/testdata/npm/registry/@denotest/esm-basic/1.0.0/main.mjs b/cli/tests/testdata/npm/registry/@denotest/esm-basic/1.0.0/main.mjs new file mode 100644 index 000000000..23df4221c --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/esm-basic/1.0.0/main.mjs @@ -0,0 +1,9 @@ +let value = 0; + +export function setValue(newValue) { + value = newValue; +} + +export function getValue() { + return value; +} diff --git a/cli/tests/testdata/npm/registry/@denotest/esm-basic/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/esm-basic/1.0.0/package.json new file mode 100644 index 000000000..757ac2db9 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/esm-basic/1.0.0/package.json @@ -0,0 +1,7 @@ +{ + "name": "@denotest/esm-basic", + "version": "1.0.0", + "type": "module", + "main": "main.mjs", + "types": "main.d.mts" +} diff --git a/cli/tests/testdata/package_json/basic/fail_check.check.out b/cli/tests/testdata/package_json/basic/fail_check.check.out new file mode 100644 index 000000000..03997a051 --- /dev/null +++ b/cli/tests/testdata/package_json/basic/fail_check.check.out @@ -0,0 +1,4 @@ +error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. +const _test: string = getValue(); + ~~~~~ + at file:///[WILDCARD]/fail_check.ts:3:7 diff --git a/cli/tests/testdata/package_json/basic/fail_check.ts b/cli/tests/testdata/package_json/basic/fail_check.ts new file mode 100644 index 000000000..ce849d92f --- /dev/null +++ b/cli/tests/testdata/package_json/basic/fail_check.ts @@ -0,0 +1,3 @@ +import { getValue } from "./main.ts"; + +const _test: string = getValue(); diff --git a/cli/tests/testdata/package_json/basic/main.bench.out b/cli/tests/testdata/package_json/basic/main.bench.out new file mode 100644 index 000000000..db0db2114 --- /dev/null +++ b/cli/tests/testdata/package_json/basic/main.bench.out @@ -0,0 +1,11 @@ +Download http://localhost:4545/npm/registry/@denotest/esm-basic +Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz +Check file:///[WILDCARD]/main.bench.ts +0 +cpu: [WILDCARD] +runtime: [WILDCARD] + +file:///[WILDCARD]/main.bench.ts +[WILDCARD] +-------------------------------------------------- ----------------------------- +should add [WILDCARD] diff --git a/cli/tests/testdata/package_json/basic/main.bench.ts b/cli/tests/testdata/package_json/basic/main.bench.ts new file mode 100644 index 000000000..51bfc7bba --- /dev/null +++ b/cli/tests/testdata/package_json/basic/main.bench.ts @@ -0,0 +1,7 @@ +import { add } from "./main.ts"; + +Deno.bench("should add", () => { + if (add(1, 2) !== 3) { + throw new Error("Fail"); + } +}); diff --git a/cli/tests/testdata/package_json/basic/main.cache.out b/cli/tests/testdata/package_json/basic/main.cache.out new file mode 100644 index 000000000..4be62e9eb --- /dev/null +++ b/cli/tests/testdata/package_json/basic/main.cache.out @@ -0,0 +1,2 @@ +Download http://localhost:4545/npm/registry/@denotest/esm-basic +Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz diff --git a/cli/tests/testdata/package_json/basic/main.check.out b/cli/tests/testdata/package_json/basic/main.check.out new file mode 100644 index 000000000..09c377314 --- /dev/null +++ b/cli/tests/testdata/package_json/basic/main.check.out @@ -0,0 +1,3 @@ +Download http://localhost:4545/npm/registry/@denotest/esm-basic +Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz +Check file://[WILDCARD]/main.ts diff --git a/cli/tests/testdata/package_json/basic/main.info.out b/cli/tests/testdata/package_json/basic/main.info.out new file mode 100644 index 000000000..48c10a0ba --- /dev/null +++ b/cli/tests/testdata/package_json/basic/main.info.out @@ -0,0 +1,7 @@ +local: [WILDCARD]main.ts +type: TypeScript +dependencies: 1 unique +size: [WILDCARD] + +file://[WILDCARD]/package_json/basic/main.ts ([WILDCARD]) +└── npm:@denotest/esm-basic@1.0.0 ([WILDCARD]) diff --git a/cli/tests/testdata/package_json/basic/main.test.out b/cli/tests/testdata/package_json/basic/main.test.out new file mode 100644 index 000000000..b04420b3b --- /dev/null +++ b/cli/tests/testdata/package_json/basic/main.test.out @@ -0,0 +1,9 @@ +Download http://localhost:4545/npm/registry/@denotest/esm-basic +Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz +Check file://[WILDCARD]/main.test.ts +0 +running 1 test from [WILDCARD]main.test.ts +should add ... ok ([WILDCARD]) + +ok | 1 passed | 0 failed ([WILDCARD]) + diff --git a/cli/tests/testdata/package_json/basic/main.test.ts b/cli/tests/testdata/package_json/basic/main.test.ts new file mode 100644 index 000000000..298ce1f5b --- /dev/null +++ b/cli/tests/testdata/package_json/basic/main.test.ts @@ -0,0 +1,7 @@ +import { add } from "./main.ts"; + +Deno.test("should add", () => { + if (add(1, 2) !== 3) { + throw new Error("Fail"); + } +}); diff --git a/cli/tests/testdata/package_json/basic/main.ts b/cli/tests/testdata/package_json/basic/main.ts new file mode 100644 index 000000000..5911fe32d --- /dev/null +++ b/cli/tests/testdata/package_json/basic/main.ts @@ -0,0 +1,11 @@ +import * as test from "@denotest/esm-basic"; + +console.log(test.getValue()); + +export function add(a: number, b: number) { + return a + b; +} + +export function getValue() { + return test.getValue(); +} diff --git a/cli/tests/testdata/package_json/basic/package.json b/cli/tests/testdata/package_json/basic/package.json new file mode 100644 index 000000000..54ca824d6 --- /dev/null +++ b/cli/tests/testdata/package_json/basic/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "@denotest/esm-basic": "*" + } +} |