diff options
Diffstat (limited to 'cli/tests')
14 files changed, 176 insertions, 118 deletions
diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs index 6a66db35f..49095b6df 100644 --- a/cli/tests/integration/npm_tests.rs +++ b/cli/tests/integration/npm_tests.rs @@ -7,6 +7,7 @@ use util::assert_contains; use util::env_vars_for_npm_tests; use util::env_vars_for_npm_tests_no_sync_download; use util::http_server; +use util::TestContextBuilder; // NOTE: See how to make test npm packages at ./testdata/npm/README.md @@ -101,7 +102,7 @@ itest!(conditional_exports { itest!(conditional_exports_node_modules_dir { args: "run --allow-read --node-modules-dir $TESTDATA/npm/conditional_exports/main.js", - output: "npm/conditional_exports/main.out", + output: "npm/conditional_exports/main_node_modules.out", envs: env_vars_for_npm_tests(), http_server: true, temp_cwd: true, @@ -729,7 +730,7 @@ itest!(node_modules_dir_require_added_node_modules_folder { itest!(node_modules_dir_with_deps { args: "run --allow-read --allow-env --node-modules-dir $TESTDATA/npm/cjs_with_deps/main.js", - output: "npm/cjs_with_deps/main.out", + output: "npm/cjs_with_deps/main_node_modules.out", envs: env_vars_for_npm_tests(), http_server: true, temp_cwd: true, @@ -1392,39 +1393,26 @@ fn auto_discover_lock_file() { #[test] fn peer_deps_with_copied_folders_and_lockfile() { - let _server = http_server(); - - let deno_dir = util::new_deno_dir(); - let temp_dir = util::TempDir::new(); + let context = TestContextBuilder::for_npm() + .use_sync_npm_download() + .use_separate_deno_dir() // the "npm" folder means something in the deno dir, so use a separate folder + .use_copy_temp_dir("npm/peer_deps_with_copied_folders") + .cwd("npm/peer_deps_with_copied_folders") + .build(); + + let deno_dir = context.deno_dir(); + let temp_dir = context.temp_dir(); + let temp_dir_sub_path = + temp_dir.path().join("npm/peer_deps_with_copied_folders"); // write empty config file - temp_dir.write("deno.json", "{}"); - let test_folder_path = test_util::testdata_path() - .join("npm") - .join("peer_deps_with_copied_folders"); - let main_contents = - std::fs::read_to_string(test_folder_path.join("main.ts")).unwrap(); - temp_dir.write("./main.ts", main_contents); - - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .arg("-A") - .arg("main.ts") - .envs(env_vars_for_npm_tests()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(); - let output = deno.wait_with_output().unwrap(); - assert!(output.status.success()); + temp_dir.write("npm/peer_deps_with_copied_folders/deno.json", "{}"); - let expected_output = - std::fs::read_to_string(test_folder_path.join("main.out")).unwrap(); + let output = context.new_command().args("run -A main.ts").run(); + output.assert_exit_code(0); + output.assert_matches_file("npm/peer_deps_with_copied_folders/main.out"); - assert_eq!(String::from_utf8(output.stderr).unwrap(), expected_output); - - assert!(temp_dir.path().join("deno.lock").exists()); + assert!(temp_dir_sub_path.join("deno.lock").exists()); let grandchild_path = deno_dir .path() .join("npm") @@ -1437,52 +1425,26 @@ fn peer_deps_with_copied_folders_and_lockfile() { assert!(grandchild_path.join("1.0.0_1").exists()); // copy folder, which is hardlinked // run again - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .arg("-A") - .arg("main.ts") - .envs(env_vars_for_npm_tests()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(); - let output = deno.wait_with_output().unwrap(); - assert_eq!(String::from_utf8(output.stderr).unwrap(), "1\n2\n"); - assert!(output.status.success()); + let output = context.new_command().args("run -A main.ts").run(); + output.assert_exit_code(0); + output.assert_matches_text("1\n2\n"); - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .arg("--reload") - .arg("-A") - .arg("main.ts") - .envs(env_vars_for_npm_tests()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(); - let output = deno.wait_with_output().unwrap(); - assert_eq!(String::from_utf8(output.stderr).unwrap(), expected_output); - assert!(output.status.success()); + // run with reload + let output = context.new_command().args("run -A --reload main.ts").run(); + output.assert_exit_code(0); + output.assert_matches_file("npm/peer_deps_with_copied_folders/main.out"); // now run with local node modules - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .arg("--node-modules-dir") - .arg("-A") - .arg("main.ts") - .envs(env_vars_for_npm_tests()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(); - let output = deno.wait_with_output().unwrap(); - assert_eq!(String::from_utf8(output.stderr).unwrap(), "1\n2\n"); - assert!(output.status.success()); + let output = context + .new_command() + .args("run -A --node-modules-dir main.ts") + .run(); + output.assert_exit_code(0); + output.assert_matches_file( + "npm/peer_deps_with_copied_folders/main_node_modules.out", + ); - let deno_folder = temp_dir.path().join("node_modules").join(".deno"); + let deno_folder = temp_dir_sub_path.join("node_modules").join(".deno"); assert!(deno_folder .join("@denotest+peer-dep-test-grandchild@1.0.0") .exists()); @@ -1491,55 +1453,32 @@ fn peer_deps_with_copied_folders_and_lockfile() { .exists()); // copy folder // now again run with local node modules - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .arg("--node-modules-dir") - .arg("-A") - .arg("main.ts") - .envs(env_vars_for_npm_tests()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(); - let output = deno.wait_with_output().unwrap(); - assert!(output.status.success()); - assert_eq!(String::from_utf8(output.stderr).unwrap(), "1\n2\n"); + let output = context + .new_command() + .args("run -A --node-modules-dir main.ts") + .run(); + output.assert_exit_code(0); + output.assert_matches_text("1\n2\n"); // now ensure it works with reloading - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .arg("--node-modules-dir") - .arg("--reload") - .arg("-A") - .arg("main.ts") - .envs(env_vars_for_npm_tests()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(); - let output = deno.wait_with_output().unwrap(); - assert!(output.status.success()); - assert_eq!(String::from_utf8(output.stderr).unwrap(), expected_output); + let output = context + .new_command() + .args("run -A --reload --node-modules-dir main.ts") + .run(); + output.assert_exit_code(0); + output.assert_matches_file( + "npm/peer_deps_with_copied_folders/main_node_modules_reload.out", + ); // now ensure it works with reloading and no lockfile - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .arg("--node-modules-dir") - .arg("--no-lock") - .arg("--reload") - .arg("-A") - .arg("main.ts") - .envs(env_vars_for_npm_tests()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(); - let output = deno.wait_with_output().unwrap(); - assert_eq!(String::from_utf8(output.stderr).unwrap(), expected_output,); - assert!(output.status.success()); + let output = context + .new_command() + .args("run -A --reload --node-modules-dir --no-lock main.ts") + .run(); + output.assert_exit_code(0); + output.assert_matches_file( + "npm/peer_deps_with_copied_folders/main_node_modules_reload.out", + ); } itest!(info_peer_deps { diff --git a/cli/tests/testdata/npm/cjs_with_deps/main_node_modules.out b/cli/tests/testdata/npm/cjs_with_deps/main_node_modules.out new file mode 100644 index 000000000..1ae22f510 --- /dev/null +++ b/cli/tests/testdata/npm/cjs_with_deps/main_node_modules.out @@ -0,0 +1,43 @@ +Download http://localhost:4545/npm/registry/chalk +Download http://localhost:4545/npm/registry/chai +Download http://localhost:4545/npm/registry/ansi-styles +Download http://localhost:4545/npm/registry/supports-color +Download http://localhost:4545/npm/registry/assertion-error +Download http://localhost:4545/npm/registry/check-error +Download http://localhost:4545/npm/registry/deep-eql +Download http://localhost:4545/npm/registry/get-func-name +Download http://localhost:4545/npm/registry/loupe +Download http://localhost:4545/npm/registry/pathval +Download http://localhost:4545/npm/registry/type-detect +Download http://localhost:4545/npm/registry/color-convert +Download http://localhost:4545/npm/registry/has-flag +Download http://localhost:4545/npm/registry/color-name +Download http://localhost:4545/npm/registry/ansi-styles/ansi-styles-4.3.0.tgz +Initialize ansi-styles@4.3.0 +Download http://localhost:4545/npm/registry/assertion-error/assertion-error-1.1.0.tgz +Initialize assertion-error@1.1.0 +Download http://localhost:4545/npm/registry/chai/chai-4.3.6.tgz +Initialize chai@4.3.6 +Download http://localhost:4545/npm/registry/chalk/chalk-4.1.2.tgz +Initialize chalk@4.1.2 +Download http://localhost:4545/npm/registry/check-error/check-error-1.0.2.tgz +Initialize check-error@1.0.2 +Download http://localhost:4545/npm/registry/color-convert/color-convert-2.0.1.tgz +Initialize color-convert@2.0.1 +Download http://localhost:4545/npm/registry/color-name/color-name-1.1.4.tgz +Initialize color-name@1.1.4 +Download http://localhost:4545/npm/registry/deep-eql/deep-eql-3.0.1.tgz +Initialize deep-eql@3.0.1 +Download http://localhost:4545/npm/registry/get-func-name/get-func-name-2.0.0.tgz +Initialize get-func-name@2.0.0 +Download http://localhost:4545/npm/registry/has-flag/has-flag-4.0.0.tgz +Initialize has-flag@4.0.0 +Download http://localhost:4545/npm/registry/loupe/loupe-2.3.4.tgz +Initialize loupe@2.3.4 +Download http://localhost:4545/npm/registry/pathval/pathval-1.1.1.tgz +Initialize pathval@1.1.1 +Download http://localhost:4545/npm/registry/supports-color/supports-color-7.2.0.tgz +Initialize supports-color@7.2.0 +Download http://localhost:4545/npm/registry/type-detect/type-detect-4.0.8.tgz +Initialize type-detect@4.0.8 +chalk cjs loads diff --git a/cli/tests/testdata/npm/cjs_yargs/main.out b/cli/tests/testdata/npm/cjs_yargs/main.out index ded92a4da..6aa34bce8 100644 --- a/cli/tests/testdata/npm/cjs_yargs/main.out +++ b/cli/tests/testdata/npm/cjs_yargs/main.out @@ -25,30 +25,56 @@ Download http://localhost:4545/npm/registry/p-limit Download http://localhost:4545/npm/registry/color-name Download http://localhost:4545/npm/registry/p-try Download http://localhost:4545/npm/registry/ansi-regex/ansi-regex-5.0.1.tgz +Initialize ansi-regex@5.0.1 Download http://localhost:4545/npm/registry/ansi-styles/ansi-styles-4.3.0.tgz +Initialize ansi-styles@4.3.0 Download http://localhost:4545/npm/registry/camelcase/camelcase-5.3.1.tgz +Initialize camelcase@5.3.1 Download http://localhost:4545/npm/registry/cliui/cliui-6.0.0.tgz +Initialize cliui@6.0.0 Download http://localhost:4545/npm/registry/color-convert/color-convert-2.0.1.tgz +Initialize color-convert@2.0.1 Download http://localhost:4545/npm/registry/color-name/color-name-1.1.4.tgz +Initialize color-name@1.1.4 Download http://localhost:4545/npm/registry/decamelize/decamelize-1.2.0.tgz +Initialize decamelize@1.2.0 Download http://localhost:4545/npm/registry/emoji-regex/emoji-regex-8.0.0.tgz +Initialize emoji-regex@8.0.0 Download http://localhost:4545/npm/registry/find-up/find-up-4.1.0.tgz +Initialize find-up@4.1.0 Download http://localhost:4545/npm/registry/get-caller-file/get-caller-file-2.0.5.tgz +Initialize get-caller-file@2.0.5 Download http://localhost:4545/npm/registry/is-fullwidth-code-point/is-fullwidth-code-point-3.0.0.tgz +Initialize is-fullwidth-code-point@3.0.0 Download http://localhost:4545/npm/registry/locate-path/locate-path-5.0.0.tgz +Initialize locate-path@5.0.0 Download http://localhost:4545/npm/registry/p-limit/p-limit-2.3.0.tgz +Initialize p-limit@2.3.0 Download http://localhost:4545/npm/registry/p-locate/p-locate-4.1.0.tgz +Initialize p-locate@4.1.0 Download http://localhost:4545/npm/registry/p-try/p-try-2.2.0.tgz +Initialize p-try@2.2.0 Download http://localhost:4545/npm/registry/path-exists/path-exists-4.0.0.tgz +Initialize path-exists@4.0.0 Download http://localhost:4545/npm/registry/require-directory/require-directory-2.1.1.tgz +Initialize require-directory@2.1.1 Download http://localhost:4545/npm/registry/require-main-filename/require-main-filename-2.0.0.tgz +Initialize require-main-filename@2.0.0 Download http://localhost:4545/npm/registry/set-blocking/set-blocking-2.0.0.tgz +Initialize set-blocking@2.0.0 Download http://localhost:4545/npm/registry/string-width/string-width-4.2.3.tgz +Initialize string-width@4.2.3 Download http://localhost:4545/npm/registry/strip-ansi/strip-ansi-6.0.1.tgz +Initialize strip-ansi@6.0.1 Download http://localhost:4545/npm/registry/which-module/which-module-2.0.0.tgz +Initialize which-module@2.0.0 Download http://localhost:4545/npm/registry/wrap-ansi/wrap-ansi-6.2.0.tgz +Initialize wrap-ansi@6.2.0 Download http://localhost:4545/npm/registry/y18n/y18n-4.0.3.tgz +Initialize y18n@4.0.3 Download http://localhost:4545/npm/registry/yargs/yargs-15.4.1.tgz +Initialize yargs@15.4.1 Download http://localhost:4545/npm/registry/yargs-parser/yargs-parser-18.1.3.tgz +Initialize yargs-parser@18.1.3 start server on :8000 [WILDCARD] diff --git a/cli/tests/testdata/npm/conditional_exports/main_node_modules.out b/cli/tests/testdata/npm/conditional_exports/main_node_modules.out new file mode 100644 index 000000000..525f31d5c --- /dev/null +++ b/cli/tests/testdata/npm/conditional_exports/main_node_modules.out @@ -0,0 +1,18 @@ +Download http://localhost:4545/npm/registry/@denotest/conditional-exports +Download http://localhost:4545/npm/registry/supports-esm +Download http://localhost:4545/npm/registry/has-package-exports +Download http://localhost:4545/npm/registry/@ljharb/has-package-exports-patterns +Download http://localhost:4545/npm/registry/@denotest/conditional-exports/1.0.0.tgz +Initialize @denotest/conditional-exports@1.0.0 +Download http://localhost:4545/npm/registry/@ljharb/has-package-exports-patterns/has-package-exports-patterns-0.0.2.tgz +Initialize @ljharb/has-package-exports-patterns@0.0.2 +Download http://localhost:4545/npm/registry/has-package-exports/has-package-exports-1.3.0.tgz +Initialize has-package-exports@1.3.0 +Download http://localhost:4545/npm/registry/supports-esm/supports-esm-1.0.0.tgz +Initialize supports-esm@1.0.0 +{ hello: "from esm" } +{ hello: "from foo" } +{ hello: "from esm client" } +{ hello: "from esm client foo" } +{ hello: "from esm client bar" } +true diff --git a/cli/tests/testdata/npm/mixed_case_package_name/local.out b/cli/tests/testdata/npm/mixed_case_package_name/local.out index b61be3d35..d21377fd6 100644 --- a/cli/tests/testdata/npm/mixed_case_package_name/local.out +++ b/cli/tests/testdata/npm/mixed_case_package_name/local.out @@ -1,7 +1,9 @@ Download http://localhost:4545/npm/registry/@denotest/MixedCase Download http://localhost:4545/npm/registry/@denotest/CAPITALS Download http://localhost:4545/npm/registry/@denotest/CAPITALS/1.0.0.tgz +Initialize @denotest/CAPITALS@1.0.0 Download http://localhost:4545/npm/registry/@denotest/MixedCase/1.0.0.tgz +Initialize @denotest/MixedCase@1.0.0 5 true true diff --git a/cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules.out b/cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules.out new file mode 100644 index 000000000..6cbadb8e7 --- /dev/null +++ b/cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules.out @@ -0,0 +1,7 @@ +Initialize @denotest/peer-dep-test-child@1.0.0 +Initialize @denotest/peer-dep-test-child@2.0.0 +Initialize @denotest/peer-dep-test-grandchild@1.0.0 +Initialize @denotest/peer-dep-test-peer@1.0.0 +Initialize @denotest/peer-dep-test-peer@2.0.0 +1 +2 diff --git a/cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules_reload.out b/cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules_reload.out new file mode 100644 index 000000000..91a59e183 --- /dev/null +++ b/cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules_reload.out @@ -0,0 +1,15 @@ +Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-child +Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-grandchild +Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-peer +Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-child/1.0.0.tgz +Initialize @denotest/peer-dep-test-child@1.0.0 +Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-child/2.0.0.tgz +Initialize @denotest/peer-dep-test-child@2.0.0 +Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-grandchild/1.0.0.tgz +Initialize @denotest/peer-dep-test-grandchild@1.0.0 +Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-peer/1.0.0.tgz +Initialize @denotest/peer-dep-test-peer@1.0.0 +Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-peer/2.0.0.tgz +Initialize @denotest/peer-dep-test-peer@2.0.0 +1 +2 diff --git a/cli/tests/testdata/package_json/basic/lib.bench.out b/cli/tests/testdata/package_json/basic/lib.bench.out index 589f17655..b16d9e7ac 100644 --- a/cli/tests/testdata/package_json/basic/lib.bench.out +++ b/cli/tests/testdata/package_json/basic/lib.bench.out @@ -1,5 +1,6 @@ Download http://localhost:4545/npm/registry/@denotest/esm-basic Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz +Initialize @denotest/esm-basic@1.0.0 Check file:///[WILDCARD]/lib.bench.ts cpu: [WILDCARD] runtime: [WILDCARD] diff --git a/cli/tests/testdata/package_json/basic/lib.test.out b/cli/tests/testdata/package_json/basic/lib.test.out index f0fe89612..fa1cbb0f7 100644 --- a/cli/tests/testdata/package_json/basic/lib.test.out +++ b/cli/tests/testdata/package_json/basic/lib.test.out @@ -1,5 +1,6 @@ Download http://localhost:4545/npm/registry/@denotest/esm-basic Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz +Initialize @denotest/esm-basic@1.0.0 Check file://[WILDCARD]/lib.test.ts running 1 test from [WILDCARD]lib.test.ts should add ... ok ([WILDCARD]) diff --git a/cli/tests/testdata/package_json/basic/main.cache.out b/cli/tests/testdata/package_json/basic/main.cache.out index 4be62e9eb..1c729e2a3 100644 --- a/cli/tests/testdata/package_json/basic/main.cache.out +++ b/cli/tests/testdata/package_json/basic/main.cache.out @@ -1,2 +1,3 @@ Download http://localhost:4545/npm/registry/@denotest/esm-basic Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz +Initialize @denotest/esm-basic@1.0.0 diff --git a/cli/tests/testdata/package_json/basic/main.check.out b/cli/tests/testdata/package_json/basic/main.check.out index 09c377314..a506cb0ed 100644 --- a/cli/tests/testdata/package_json/basic/main.check.out +++ b/cli/tests/testdata/package_json/basic/main.check.out @@ -1,3 +1,4 @@ Download http://localhost:4545/npm/registry/@denotest/esm-basic Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz +Initialize @denotest/esm-basic@1.0.0 Check file://[WILDCARD]/main.ts diff --git a/cli/tests/testdata/package_json/invalid_value/ok.ts.out b/cli/tests/testdata/package_json/invalid_value/ok.ts.out index 3c7e2792f..17d9bba00 100644 --- a/cli/tests/testdata/package_json/invalid_value/ok.ts.out +++ b/cli/tests/testdata/package_json/invalid_value/ok.ts.out @@ -1,3 +1,4 @@ Download http://localhost:4545/npm/registry/@denotest/esm-basic Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz +Initialize @denotest/esm-basic@1.0.0 2 diff --git a/cli/tests/testdata/task/both/package_json_selected.out b/cli/tests/testdata/task/both/package_json_selected.out index 435145deb..06b735c9d 100644 --- a/cli/tests/testdata/task/both/package_json_selected.out +++ b/cli/tests/testdata/task/both/package_json_selected.out @@ -1,5 +1,6 @@ Download http://localhost:4545/npm/registry/@denotest/bin Download http://localhost:4545/npm/registry/@denotest/bin/1.0.0.tgz +Initialize @denotest/bin@1.0.0 Warning Currently only basic package.json `scripts` are supported. Programs like `rimraf` or `cross-env` will not work correctly. This will be fixed in the upcoming release. Task bin cli-esm testing this out "asdf" testing diff --git a/cli/tests/testdata/task/package_json/bin.out b/cli/tests/testdata/task/package_json/bin.out index d8594a243..fac692115 100644 --- a/cli/tests/testdata/task/package_json/bin.out +++ b/cli/tests/testdata/task/package_json/bin.out @@ -1,6 +1,8 @@ Download http://localhost:4545/npm/registry/@denotest/bin Download http://localhost:4545/npm/registry/@denotest/bin/0.5.0.tgz +Initialize @denotest/bin@0.5.0 Download http://localhost:4545/npm/registry/@denotest/bin/1.0.0.tgz +Initialize @denotest/bin@1.0.0 Warning Currently only basic package.json `scripts` are supported. Programs like `rimraf` or `cross-env` will not work correctly. This will be fixed in the upcoming release. Task bin @denotest/bin hi && cli-esm testing this out && npx cli-cjs test "extra" hi |